Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const CB_ADDSTRING = &H143
Private Const CB_SETITEMDATA = &H151
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type COMBOBOXINFO
cbSize As Long
rcItem As RECT
rcButton As RECT
stateButton As Long
hwndCombo As Long
hwndEdit As Long
hwndList As Long
End Type
Private Declare Function GetComboBoxInfo Lib "user32" _
(ByVal hwndCombo As Long, _
CBInfo As COMBOBOXINFO) 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 SetWindowText Lib "user32" _
Alias "SetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String) As Long
Private Sub Command1_Click()
Dim hEdit As Long
hEdit = GetComboEditHandle(Combo1)
'prove you got it by changing the combo text (style 0 only)
Call SetWindowText(hEdit, "Hey! that's it .." & CStr(hEdit))
'add the handle to the list...
Call SendMessage(Combo1.hwnd, CB_ADDSTRING, _
0&, ByVal "GetComboBoxInfo: Edit handle is " & CStr(hEdit))
End Sub
Private Sub Command2_Click()
Dim hList As Long
hList = GetComboListHandle(Combo1)
'add the handle to the list...
Call SendMessage(Combo1.hwnd, CB_ADDSTRING, _
0&, ByVal "GetComboBoxInfo: List handle is " & CStr(hList))
hwndList = hList
End Sub
Private Function GetComboEditHandle(ctl As ComboBox) As Long
Dim CBI As COMBOBOXINFO
CBI.cbSize = Len(CBI)
Call GetComboBoxInfo(ctl.hwnd, CBI)
GetComboEditHandle = CBI.hwndEdit
End Function
Private Function GetComboListHandle(ctl As ComboBox) As Long
Dim CBI As COMBOBOXINFO
CBI.cbSize = Len(CBI)
Call GetComboBoxInfo(ctl.hwnd, CBI)
GetComboListHandle = CBI.hwndList
End Function
|