Bob,
Yes - that is precisely the case. I have VB6, am using a VB popup menu for listboxes and textboxes and up until now have been relying on keypress events to call the menu for the comboboxes. So - based on the start that you gave me I have patched together this code:
In Form:
Private Sub Form_Load()
Dim i As Integer
Dim cbi As COMBOBOXINFO
cbi.cbSize = Len(cbi)
Call GetComboBoxInfo(Me.Combo1.hwnd, cbi)
'gHW = cbi.hwndList
gHW = Combo1.hwnd
For i = 0 To 100
Me.Combo1.AddItem i
Next i
Hook
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unhook
End Sub
in Modul:
Public Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Public 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
Public Declare Function GetComboBoxInfo Lib "user32.dll" (ByVal hwndCombo As Long, ByRef CBInfo As COMBOBOXINFO) As Long
Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = -4
Public Const WM_RBUTTONUP = &H205
Public IsHooked As Boolean
Global lpPrevWndProc As Long
Global gHW As Long
Public Sub Hook()
If IsHooked Then = False Then
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
IsHooked = True
End If
End Sub
Public Sub Unhook()
Dim temp As Long
temp = SetWindowLong(gHWText, GWL_WNDPROC, lpPrevWndProc)
IsHooked = False
End Sub
Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_RBUTTONUP
MsgBox "Popup"
End Select
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
And amazingly, it works (though I haven't actually tried it in my project yet...)
At this point my question is - it seems that I can "Hook" a single component (see Form_Load above - setting the handle of the combobox allows for right clicks when collapsed, and setting the handle of the list (hwndList ) allows when expanded - I have my lists set to Style 2 - Dropdown List so I'm not interested in the textbox portion of the combobox). How do I hook both the combobox and the combobox's list?
Additionally, the comboboxes are indexed in a control array - I'll have to test to see if I need to hook and unhook each instance, do you know if this is necessary.
At any rate, thanks for your help - I've been searching the web and haven't found all of this info together in any one place - which seems surprising given the limitations of the combobox as shipped with VB6. It seems that with .net that the combobox does have mouse events but I'm sticking it out with VB6 for now.
Regards,
Peter