Hi,
Frame -> Mdi - > Child Window -> Combobox
I have the HWND of the Combobox. But getwindow
text will only get the WINDOWS text. I need the
text of a control (label, combobox, ext..) of
another window. Now how can i do that?
Printable View
Hi,
Frame -> Mdi - > Child Window -> Combobox
I have the HWND of the Combobox. But getwindow
text will only get the WINDOWS text. I need the
text of a control (label, combobox, ext..) of
another window. Now how can i do that?
label, combobox are also windows.getwindowtext gets their text too.
Code:Dim c As String
c = Space(256)
GetWindowText Combo1.hwnd, c, 255
'c contains combo1 text
I'm assuming you want to get a list of strings inside a ComboBox that you only have the hWnd of. :rolleyes:
(If you want something else, please explain it again)
Here's how to use it:Code:Option Explicit
Private Const CB_GETCOUNT = &H146
Private Const CB_GETLBTEXT = &H148
Private Const CB_GETLBTEXTLEN = &H149
Private Const CB_ERR = (-1)
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
Function GetComboBoxItems(ByVal hWndComboBox As Long) As Variant
Dim nCount As Long, I As Long, nLen As Long
Dim sItems() As String
nCount = SendMessage(hWndComboBox, CB_GETCOUNT, 0, 0)
If (nCount = CB_ERR) Or (nCount = 0) Then Exit Function
For I = 0 To nCount - 1
ReDim Preserve sItems(0 To I) As String
nLen = SendMessage(hWndComboBox, CB_GETLBTEXTLEN, I, 0)
If nLen = CB_ERR Then Exit Function
sItems(I) = String(nLen, vbNullChar)
If SendMessage(hWndComboBox, CB_GETLBTEXT, I, ByVal sItems(I)) = CB_ERR Then Exit Function
Next
GetComboBoxItems = sItems
End Function
Code:Dim sItems As Variant
Dim I As Long
sItems = GetComboBoxItems(MyComboBox.hWnd) ' Does not have to be an hWnd in your app
If IsArray(sItems) Then
For I = LBound(sItems) To UBound(sItems)
Debug.Print sItems(I) & " = " & I + 1 ' Item1 = 1, Item2 = 2, etc.
Next
Else
Debug.Print "Error, or empty ComboBox."
End If
Or if you want to get the text from the TextBox part of the combobox, you would have to get the hwnd from the child window of the combobox, and use GetWindowText on that hwnd. The classname of this child is "Edit".