Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

Popup menu hidding problem !

when I right click on my tray icon, a popup menu appears.
The problem is that when I click outside the menu, the menu is not killed.

How can I make the menu to be killed when I click outiside the menu ?

Here's the code :

LRESULT CWindowHandlePickerDlg::OnNotifyTaskBarIcon(WPARAM wParam, LPARAM lParam)
 {
  UINT uID       = (UINT)wParam;
  UINT uMouseMsg = (UINT)lParam;

  if (uID != ID_TRAYICON) return 0L;

  switch(uMouseMsg)
   {
    case WM_LBUTTONDBLCLK :
                            OnTrayMenu_ShowInterface();
                            break;

    case WM_RBUTTONDOWN :
                          {
                           CMenu cTaskBarDummyMenu;

                           if (!cTaskBarDummyMenu.LoadMenu(IDM_TASKBARICON)) return 0L;

                           CMenu *pcTaskBarMenu = cTaskBarDummyMenu.GetSubMenu(0);

                           CPoint point;
                           
                           GetCursorPos(&point);

                           if (pcTaskBarMenu) pcTaskBarMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this);

                           cTaskBarDummyMenu.DestroyMenu();
                          }
                          break;
   }

  return 0L;
 }
ASKER CERTIFIED SOLUTION
Avatar of MichaelS
MichaelS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vinayak Kumbar
Vinayak Kumbar

Interesting......

VinExpert
Hi,

Yes, it works fine. Thanks MichaelS. It is a good trick.
mike, u have to change ur code as

......
.......

CPoint point;
GetCursorPos(&point);

this->SetForegroundWindow();

if (pcTaskBarMenu) pcTaskBarMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, this);

this->PostMessage(NULL,0,0);

cTaskBarDummyMenu.DestroyMenu();

Thats it. Once again thanks MichaelS.

VinExpert
You wellcome.
Avatar of mike_marquet

ASKER

Thanks to you MichaelS