Solved

I Can´t delete PopUp Menu

Posted on 2003-12-09
8
372 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

18 Experts available now in Live!

Get 1:1 Help Now