Solved

Popup menu hidding problem !

Posted on 2000-02-24
5
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 76
Not needed 13 134
Capture logon name 13 119
Work with App store 7 123
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

710 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