Results 1 to 3 of 3

Thread: Creating a Combo Box in a Window

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    1
    Ok... I'm new to this so bear with me. I want to create a drop down type list that only comes up when I use a command button. I have seen a program bring up a window (like a message box) with a combo box looking drop down that you can select from. I may be crazy to want to do this, but does anyone know how to make this happen? Also, how can I call the MS Calculator from a program, use it, and take the results back to the program as input? Just go easy one me. I'm a converted MS Basic programmer (self taught many years ago). Thanks!!! Mark

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    OK, somewhere to the Right of your screen there's a window called Project Explorer, with a Forms Folder and Form1 Coming out of it, right click here, and from the popup menu, select Add.. Form

    Make this Form how you Like, then you can bring it up with Form2.Show, and Hide it with Form2.Hide. You Can Access it's Controlls With Form2.Como1 etc. and If you Declare Variables as Public (instead of Bim x as long, use Public x as long) then you can access these ifrom form 1 with Form2.x etc.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    For your first question you can do something like this:
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const CB_SHOWDROPDOWN = &H14F
    
    Private Sub Command1_Click()
        Static blnDropDownState As Boolean
        
        blnDropDownState = Not blnDropDownState
        
        Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, blnDropDownState, 0)
    End Sub
    
    Private Sub Form_Load()
        Dim i As Integer
        
        For i = 1 To 10
            Combo1.AddItem "Item" & i
        Next
    End Sub
    As for Calculator, you can do something like this. Drop Command Button, Timer and a TextBox onto your form:
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE
    
    'This variable is to hold
    'the value from Calculator
    Public dblCalcValue As Double
    
    Private Sub Command1_Click()
        Shell "Calc", vbNormalFocus
    End Sub
    
    
    Private Sub Form_Load()
        Timer1.Interval = 100
    End Sub
    
    
    Private Sub Timer1_Timer()
        Dim lngHwndCalc As Long
        Dim lngHwndTextBox As Long
        Dim strBuffer As String
        Dim lngLen As Long
        Dim lngRetVal As Long
        
        lngHwndCalc = FindWindowEx(0, 0, "SciCalc", vbNullString)
        If lngHwndCalc Then
            lngHwndTextBox = FindWindowEx(lngHwndCalc, 0, "Static", vbNullString)
            lngLen = SendMessage(lngHwndTextBox, WM_GETTEXTLENGTH, 0, 0)
            strBuffer = Space(lngLen)
            lngRetVal = SendMessageStr(lngHwndTextBox, WM_GETTEXT, lngLen, ByVal strBuffer)
            If lngRetVal Then dblCalcValue = CDbl(strBuffer)
        Else
            Text1.Text = dblCalcValue
        End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width