Solved

I Can´t delete PopUp Menu

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
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. …
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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