Solved

Popup menu hidding problem !

Posted on 2000-02-24
5
203 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 101
Best tools for Backup and restore of Wordpress site 6 57
sameEnds challenge 3 161
Problem to open Excel file 15 135
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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