Solved

Popup menu hidding problem !

Posted on 2000-02-24
5
200 Views
Last Modified: 2013-11-20
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
Comment
Question by:mike_marquet
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
MichaelS earned 25 total points
ID: 2553745
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
 
LVL 8

Expert Comment

by:VinExpert
ID: 2553858
Interesting......

VinExpert
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 2553877
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
 
LVL 6

Expert Comment

by:MichaelS
ID: 2553885
You wellcome.
0
 

Author Comment

by:mike_marquet
ID: 2553898
Thanks to you MichaelS
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now