I would like to learn how to extract data from a combo box in another program. I can identify the hwnd but do not know how to get the information.
Please help. :)
Printable View
I would like to learn how to extract data from a combo box in another program. I can identify the hwnd but do not know how to get the information.
Please help. :)
Sure! This example will show you how to get all ComboBox items and put them in your Listbox:
Usage: FromComboToList ComboboxHandle, DestinationListBoxCode:Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 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 Const CB_GETCOUNT = &H146
Private Const CB_GETLBTEXT = &H148
Private Const CB_GETLBTEXTLEN = &H149
Public Sub FromComboToList(pComboHwnd As ComboBox, pList As ListBox)
Dim lCount As Long
Dim lLen As Long
Dim strBuffer As String
Dim i As Integer
lCount = SendMessage(pComboHwnd, CB_GETCOUNT, 0, 0)
For i = 0 To lCount - 1
lLen = SendMessage(pComboHwnd, CB_GETLBTEXTLEN, i, 0)
strBuffer = Space(lLen)
Call SendMessageString(pComboHwnd, CB_GETLBTEXT, i, strBuffer)
pList.AddItem strBuffer
Next
End Sub
Example: FromComboToList ComboHwnd, List1
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
Hey Serge,
I get a type mismatch error and it does not work. What am I doing wrong?
Can you post the code snippet?
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
Serge,
That is ok... :) I have found an excellent working example tonight. I am learning how to do it from there.
Thank you for your assistance.