Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

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;
 }
0
mike_marquet
Asked:
mike_marquet
  • 2
  • 2
1 Solution
 
MichaelSCommented:
There is a trick. Berof calling TrackPopupMenu you have to call SetForegroundWindow() function and after TrackPopupMenu you have to call PostMessage(, NULL,,) and  specify handle of you window in that function.
0
 
Vinayak KumbarSr Program ManagerCommented:
Interesting......

VinExpert
0
 
Vinayak KumbarSr Program ManagerCommented:
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
0
 
MichaelSCommented:
You wellcome.
0
 
mike_marquetAuthor Commented:
Thanks to you MichaelS
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now