TrackPopupMenu: menu not dismissed when clicking outside 
Author Message
 TrackPopupMenu: menu not dismissed when clicking outside
In an MFC app that places an icon in the tray, but where the app's own
window always remains invisible (just used to receive the notification
messages from the tray icon), I was trying to include a popup menu.

This works fine, except that the menu can only be dismissed by clicking one
of its choices - clicking outside the menu has all the effects it should
have (for whatever you click on), but the popup menu stays on screen.

Does anyone know what may cause this?  I don't use MFC often, so I fear that
this might be the result of my mixing MFC things too much with the standard
API things I'm more accustomed to?

The code (included in the app's WindowProc) looks like this:

LRESULT CWimiNetMonDlg::WindowProc(UINT message, WPARAM wParam, LPARAM
lParam)
{
 if(message==WM_USER){
  if(lParam==WM_RBUTTONUP || lParam==WM_LBUTTONUP){
   CMenu Menu;
   if(Menu.LoadMenu(IDR_MENU1)){
    CMenu *pPopup = Menu.GetSubMenu(0);
    ASSERT (pPopup!=NULL);
    POINT MousePoint;
    GetCursorPos(&MousePoint);
    pPopup->TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, MousePoint.x,
MousePoint.y, this);

I tried explicitly specifying NULL for the lpRect parameter, with the same
result.

BTW, I have to resort to GetCursorPos to find out where to display the menu,
because GetMessagePos returns 0: I suppose this is because the actual mouse
message was coming from the icon, and not from the app's own window?



Sat, 09 Nov 2002 03:00:00 GMT  
 TrackPopupMenu: menu not dismissed when clicking outside

Quote:
>In an MFC app that places an icon in the tray, but where the app's own
>window always remains invisible (just used to receive the notification
>messages from the tray icon), I was trying to include a popup menu.

>This works fine, except that the menu can only be dismissed by clicking one
>of its choices - clicking outside the menu has all the effects it should
>have (for whatever you click on), but the popup menu stays on screen.

See Knowledge Base article Q135788 "PRB: Menus for Notification Icons
Do Not Work Correctly".

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sat, 09 Nov 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Right click menu on tree control-Menu not going away

2. TrackPopupMenu does not show menu labels

3. Grayed menu items not working with TrackPopupMenu()?

4. Q: Trackpopup Menu - dismissing it

5. How to dismiss a context menu?

6. Right-click opoup menu? not working

7. On continuous right click not able to invoke a menu

8. How to capture a mouse click outside window

9. HELP: Getting mouse click outside window

10. Click outside POPUP window

11. HELP: Getting mouse click outside window

12. how can I add myself menu item to CEdit right click menu?(jchen)

 

 
Powered by phpBB® Forum Software