Solved

I Can´t delete PopUp Menu

Posted on 2003-12-09
8
378 Views
Last Modified: 2013-11-20
I have a PopUp Menu. When I press rbutton it appears as consequence of

CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_PRINCIPAL_DIALOG));
CMenu* pPopup;
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
While (pWndPopupOwner->GetStyle() & WS_CHILD)
      pWndPopupOwner = pWndPopupOwner->GetParent();

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,pWndPopupOwner);

then the method concludes.

The problem is that when I choose an item , all the correspondent code is invoked but when the action was done the PopUp Menu doesn´t desappear.
What do i have to do ?
Thanks
0
Comment
Question by:martin11_ar
[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
8 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9903974
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9904008
There are remarks in the TrackPopupMenu MSDN topic, possibly this is your case:

To display a context menu for a notification icon, the current window must be the foreground window before the application calls TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the window that created the menu (if it is visible). However, when the current window is the foreground window, the second time this menu is displayed, it displays and then immediately disappears. To correct this, you must force a task switch to the application that called TrackPopupMenu at some time in the near future. This is done by posting a benign message to the window or thread, as shown in the following code sample:

    SetForegroundWindow(hDlg);

   // Display the menu
   TrackPopupMenu(   hSubMenu,
                     TPM_RIGHTBUTTON,
                     pt.x,
                     pt.y,
                     0,
                     hDlg,
                     NULL);

   PostMessage(hDlg, WM_NULL, 0, 0);
0
 

Author Comment

by:martin11_ar
ID: 9904557
Sorry , it doesn´t work. Equally i don´t understand so much.
But i have another question about this that perhaps help you to get the answer.
When I created the PopUp Menu the classwizard ask me for a class for the PopUp menu but i still don´t create any class for it.
Do i need to do this ?
If the answer is yes , what class would i have to associate to it?
A new or an existing class?
0
 

Author Comment

by:martin11_ar
ID: 9904617
I found the reason, the code that i wrote in my first question is in the OnContextMenu(CWnd* pWnd, CPoint point) method.
I don´t know why but it´s invoked 3 times when i press the rbutton.
So the apllication shows 3 PopUp Menu.
Do you Know why it´s invoked 3 times ?
If you can Answer the second question too, please.
0
 
LVL 3

Accepted Solution

by:
jsaxon2 earned 40 total points
ID: 9906792
You should put your code in the OnRButtonUp() function for your control.
0

Featured Post

Three Considerations for Containers

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read our article on Experts Exchange.

Question has a verified solution.

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

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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

631 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