Re: Tray icon menu does not disapear - vbPopupMenuRightButton usage
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sun, 19 Nov 2006 19:19:33 -0500
<gsagie@xxxxxxxxx> wrote in message news:OZ2CVLBDHHA.572@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I want the tray icon popup menu to disappears when ever the user press left or right key off the menu.
Although I'm using the following code:
Me.PopupMenu mnuPopup1, vbPopupMenuLeftButton Or vbPopupMenuRightButton
The menu did not disappears,
First , please don't multipost.
Just to make sure I understand, you're displaying the menu from the tray icon just fine, but you want the user to be able to press the left or right arrow key to dismiss the menu?
Without some subclassing, I doubt you can do this because VB provides no way to trap those keypresses when a popup menu is displayed. Even with subclassing, I don't know for certain how you'd do this as I don't know if any of the keyboard event messages would even be sent to your window (or form). Hopefully, you're already subclassing a window for the tray icon instead of relying on the WM_MOUSEMOVE hack (specifying this message as the callback message). If so, it should be simple to add code to trap WM_KEYUP and check wParam for the key code for either the left or right arrow key. If you use the WM_MOUSEMOVE hack, well, I can only say learn the proper way (which is to specify an application-defined message as the callback message and subclass a form to handle that application-defined message).
If you look up the PopupMenu method in Help, you'll see that those constants are to specify which mouse button can "activate" commands on the menu. IOW, if you specify vbPopupMenuRightButton, the user can click either the left or right button on any of the menu commands; otherwise, the user can can click the left button only. Combining these constants does absolutely nothing because the value of vbPopupMenuLeftButton is 0.
What Beastfish mentioned to do will cause the menu to be dismissed when the popup menu "loses focus", such as the user clicking on the Desktop or pretty much anything OTHER than the popup menu itself. If you want a keyboard means of dismissing the menu, educate/instruct your users to press the Escape key. That's the standard keyboard means to dismiss a popup menu without taking any kind of action whatsoever. Alternatively, you could add a Cancel menu command which the user can choose to dismiss the menu. Then, the user could the the up or down arrow keys to move to the Cancel command and press Enter/Return. That'd give them 2 keyboard ways to dismiss it (they can still press Escape too).
--
Mike
Microsoft MVP Visual Basic
.
- References:
- Prev by Date: Re: .NET haters ought to get a kick out of this
- Next by Date: Re: VB6 Apps on Vista - Released Nov 16, 2006.
- Previous by thread: Re: Tray icon menu does not disapear - vbPopupMenuRightButton usage
- Next by thread: GetPrivateProfileString question
- Index(es):