Quote:
>I need my own popup menu to appear on a combobox.
> There are no mouseup etc there so how do I do that?
> Vb6SP6
It appears that you're going to have to use subclassing.
It might be helpful if you provide more information. For example, what style
does the combobox have, etc. I mention this because both the dropdown
styles (0 and 2) provide the standard edit control right-click menu already.
So are you saying you need to replace this with your own popup menu? Or, are
you using style 1-Simple Combo and need to provide your own right-click
menu? You'll most likely need to handle different messages in your
subclassing depending on this, and possibly other things. For example, for
styles 0 and 2, you probably need to handle the WM_CONTEXTMENU message. For
style 1, it'd be the WM_RBUTTONUP message.
I played around with this a bit, and from what I can tell, what you actually
need to subclass is the edit box of the combobox (for styles 0 and 2). From
an example I found in MSDN Library, it looks like you get that by using the
ChildWindowFromPoint API function using a point of 1,1. So, I tested that.
Didn't work. Then I thought that perhaps 1,1 was a coordinate for a border,
so I arbitrarily changed the point to 3,10 and voila! Below is the code I
used. Please note that I used a subclassing control, so none of the actual
subclassing code is included here. If you need that code, searching google
should find you tons of posts on how to subclass. Or, post back and I can
whip up something fairly quickly that doesn't use a subclassing control.
Also, you might need to experiment a bit with the point that you use and
this COULD vary on different systems depending on user-defined border sizes,
screen resolution, small fonts vs large fonts (or more accurately, DPI),
etc.
-----BEGIN CODE
Option Explicit
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_CONTEXTMENU As Long = &H7B
Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent
As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Load()
With SubClass1
.WinHandle = ChildWindowFromPoint(Combo1.hWnd, 3, 10)
.MessageQueue(WM_CONTEXTMENU) = True
End With
End Sub
Private Sub SubClass1_WindProc(uMsg As Long, wParam As Long, lParam As Long,
Ret As Long)
PopupMenu MyCBPopupMenu
End Sub
-----END CODE
And, as I said, if your combobox is style 1, you'd want to handle the
WM_RBUTTONUP message instead of WM_CONTEXTMENU (and you'd subclass the
combobox since there would be no edit control).
And just for clarity, since WM_CONTEXTMENU is the only message I added to
the subclassing control's list of messages, there was no need to check the
uMsg parameter in its WindProc event because the subclassing control is only
going to raise that event for that message and no others. That's
functionality of the subclassing control.
--
Mike
Microsoft MVP Visual Basic