Solved

I Can´t delete PopUp Menu

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
Tab names are off by one 5 54
Define unique primary key 9 95
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 111
zeroFront challenge 7 121
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

735 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