From: Lorin on
I need my own popup menu to appear on a combobox.
There are no mouseup etc there so how do I do that?
Vb6SP6

From: christery on
On 28 Juni, 08:20, Lorin <Lo...(a)discussions.microsoft.com> wrote:
> I need my own popup menu to appear on a combobox.
> There are no mouseup etc there so how do I do that?
> Vb6SP6

Did try it in VBA (XL), but should be better in VB...

Private Sub ComboBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "Aha " & Button
End Sub

Worked...

Sorry that I cant try that on VB6 at home...

//CY
From: MikeD on

"Lorin" <Lorin(a)discussions.microsoft.com> wrote in message
news:C30E8785-EDEF-4313-9DC6-3CC859CBAEC2(a)microsoft.com...
>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



From: MikeD on

<christery(a)gmail.com> wrote in message
news:d1d59197-7c32-4775-9422-eea7747a7092(a)i76g2000hsf.googlegroups.com...
> On 28 Juni, 08:20, Lorin <Lo...(a)discussions.microsoft.com> wrote:
>> I need my own popup menu to appear on a combobox.
>> There are no mouseup etc there so how do I do that?
>> Vb6SP6
>
> Did try it in VBA (XL), but should be better in VB...
>
> Private Sub ComboBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
> Integer, ByVal X As Single, ByVal Y As Single)
> MsgBox "Aha " & Button
> End Sub
>
> Worked...
>

Worthless in VB. As has been stated MANY times, VB is not the same as VBA.
In VB, a combobox does NOT have a MouseUp event, which the OP even
mentioned.

--
Mike
Microsoft MVP Visual Basic


From: duke on
On Jun 28, 12:20 am, Lorin <Lo...(a)discussions.microsoft.com> wrote:
> I need my own popup menu to appear on a combobox.
> There are no mouseup etc there so how do I do that?
> Vb6SP6

I'm trying to understand what you want to do.
I am having trouble understanding why one choice is placed in a
combobox and another in a popupmenu.

Is the popupmenu supposed to appear after you click on one of the
items in the combobox ?

If yes, then place the PopupMenu statement in the combo1_Click event
as per below:

Private Sub Combo1_Click()
PopupMenu Test

End Sub