Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

I Can´t delete PopUp Menu

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
martin11_ar
Asked:
martin11_ar
  • 2
  • 2
1 Solution
 
AlexFMCommented:
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
0
 
AlexFMCommented:
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
 
martin11_arAuthor Commented:
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
 
martin11_arAuthor Commented:
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
 
jsaxon2Commented:
You should put your code in the OnRButtonUp() function for your control.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now