15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Getting OnUpdateCmdUI to work with TrackPopupMenu

Jeff S. Shanholtz -- jshanholtz@worldnet.att.net
Monday, December 16, 1996

Environment: VC++ 1.52c, Windows95

I'm trying to get a TrackPopupMenu call to work in a view of my app and the
only way I can seem to get menu items disabled or checked is to manually do
it right before calling TrackPopupMenu. I know I have gotten it to work
with the OnUpdateCmdUI handlers way back when I took an MFC class, but I
don't remember what I did. I think it had something to do with the window
pointer parameter (passing in something other than "this"). I tried passing
in "this" and also the main frame's pointer, but messages didn't seem to
route to my view class.

Here's how I'm calling it (from my view class):

pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_LEFTBUTTON, point.x, point.y, this);

Jeff Shanholtz
Enertech Consultants



Mike Morel -- mmorel@mushroomsoft.com
Wednesday, December 18, 1996

[Mini-digest: 2 responses]

>From the December MFC For Yourself:

These handlers will be properly called, as long as the owner of the menu is 
derived from CFrameWnd.  See the article How to Use TrackPopupMenu() and 
Update UI Handlers, Microsoft Knowledgebase, Q139469 for more information. 
 The most important excerpt:
"Floating pop-up menus are generally displayed in response to right-mouse 
click messages. The CMenu::TrackPopupMenu() function is used to display 
these menus. For the MFC Update UI mechanism to work correctly with these 
menus, the owner of these menus should be a class derived from CFrameWnd."

So, you want to change your call to:
pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd());

Mike Morel
mmorel@mushroomsoft.com
Mushroom Software
Home of MFC For Yourself
http://www.mushroomsoft.com


----------
From: 	Jeff S. Shanholtz[SMTP:jshanholtz@worldnet.att.net]
Sent: 	Monday, December 16, 1996 1:11 PM
To: 	mfc-l@netcom.com
Subject: 	Getting OnUpdateCmdUI to work with TrackPopupMenu

Environment: VC++ 1.52c, Windows95

I'm trying to get a TrackPopupMenu call to work in a view of my app and the
only way I can seem to get menu items disabled or checked is to manually do
it right before calling TrackPopupMenu. I know I have gotten it to work
with the OnUpdateCmdUI handlers way back when I took an MFC class, but I
don't remember what I did. I think it had something to do with the window
pointer parameter (passing in something other than "this"). I tried passing
in "this" and also the main frame's pointer, but messages didn't seem to
route to my view class.

Here's how I'm calling it (from my view class):

pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_LEFTBUTTON, point.x, point.y, this);

Jeff Shanholtz
Enertech Consultants





-----From: Joern Dahl-Stamnes 

>Environment: VC++ 1.52c, Windows95
>
>I'm trying to get a TrackPopupMenu call to work in a view of my app and the
>only way I can seem to get menu items disabled or checked is to manually do
>it right before calling TrackPopupMenu. I know I have gotten it to work
>with the OnUpdateCmdUI handlers way back when I took an MFC class, but I
>don't remember what I did. I think it had something to do with the window
>pointer parameter (passing in something other than "this"). I tried passing
>in "this" and also the main frame's pointer, but messages didn't seem to
>route to my view class.
>
>Here's how I'm calling it (from my view class):
>
>pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON |
>TPM_LEFTBUTTON, point.x, point.y, this);
>
>Jeff Shanholtz
>Enertech Consultants

I checked with my application last night and it work for me. What I do is that
instead of using this as the last argument, I use AfxGetMainWnd() so that
I can include commands that are a part of the document class.

-- 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Joern Yngve Dahl-Stamnes, Norwegian University of Science and Technology  |
| e-mail: Jorn.Dahl-Stamnes@fysel.ntnu.no                                   | 
| phone : +73 59 44 12, fax: +73 59 14 41                                   |
| Surfing the net? Try http://www.fysel.ntnu.no/dahls/dahls.html            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+




| Вернуться в корень Архива |