如何得到另一个程序中comboBox控件内的当前内容啊....假设句柄已找到..
我用GetWindowText..没用....
用GetText消息又出错.....请大哥们给我一个可以通过的程序段啊...谢谢了..

解决方案 »

  1.   

    通过sendmessage发送消息到combobox控件来获取,首先发送CB_GETCURSEL消息获得当前选择的的行号。然后发送CB_GETLBTEXT这行的内容。
      

  2.   

    VB代码:Option ExplicitPrivate Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd _
       As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As LongConst CB_GETCURSEL = &H147
    Const CB_GETLBTEXT = &H148
    Const CB_GETLBTEXTLEN = &H149
    Private Sub Combo1_DropDown()
    Timer1.Enabled = True
    End Sub
    Private Sub Combo1_LostFocus()
    Timer1.Enabled = False
    End SubPrivate Sub Form_Load()
    With Combo1
       .AddItem "Item1"
      .AddItem "Item2"
      .AddItem "Item3"
    End With
    End SubPrivate Sub Timer1_Timer()
    ' Display the text of whatever item in combo box Combo1
    ' is currently selected.  If no list box item is selected, say so.
    Dim index As Long       ' index to the selected item
    Dim itemtext As String  ' the text of the selected item
    Dim textlen As Long     ' the length of the selected item's text' Determine the index of the selected item.
    index = SendMessage(Combo1.hwnd, CB_GETCURSEL, ByVal CLng(0), ByVal CLng(0))
    ' Decide what to do based on that.
    Select Case index
    Case -1    ' No list box item was selected.
       'ToDo
    Case Else  ' Some item is selected.
       ' Determine how long the item's text is.
       textlen = SendMessage(Combo1.hwnd, CB_GETLBTEXTLEN, ByVal CLng(index), ByVal CLng(0))
       ' Make enough room in the string to receive the text, including the terminating null.
       itemtext = Space(textlen) & vbNullChar
       ' Retrieve that item's text and display it.
       textlen = SendMessage(Combo1.hwnd, CB_GETLBTEXT, ByVal CLng(index), ByVal itemtext)
       itemtext = Left$(itemtext, textlen)
       Text1.Text = "Selected item: " & itemtext
    End SelectEnd Sub
      

  3.   

    是啊!
    实际上你把ComboBox上的内容发送到公用的模块中就可以
    让其他窗口访问乐!
      

  4.   

    问题我自己很早前就解决了...散分..HOHO