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

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


Pop-up menu lists

Spencer Jones -- Spencer@azure.com
Tuesday, February 04, 1997

Environment: MSVC 4.0 Win NT 4.0

In my application I have a view menu with the options:

	Toolbar
	Status Bar

standard, as supplied by App Wizard. And my own commands:

	RGB Values - for toggling a dialog bar added using Component Gallery
	Magnify Image - selects a magnify tool, handled by me
	Pointer Tool - selects a pointer tool, handled by me
	Zoom Percent - pop-up with a list of zoom percents, handled by me.

What I have attempted to do is to add a pop-up menu that is available
when the right hand mouse button is clicked. I have created a new menu,
with the same options as those in the view option, and the same resource
ID.

My problem is:

1. the menu options added by App Wizard / Component Gallery do not work
in the pop-up menu. I.E. selecting Toolbar does not switch off the
toolbar.

2. The zoom percent allows the image to be resized, this works fine from
both menus. However I wish to check the selected percent. I have done
this in the OnUpdateHandler() for the function, and it works fine for
the main menu, but nothing is ever checked in the new pop-up menu. I
have placed a breakpoint in the handler and it is not called when the
pop-up menu is opened.

I get a handle to the menu using the CMenu function

	VERIFY(menu.LoadMenu(IDR_MYPOPUPMENU));

and display it using:

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

where pPopup is a pointer to the pop-up menu, and 'this' is the View.

I have also tried making pPopup the pointer to the View menu, using the
main menu and the function GetSubMenu(1). But this gives the same
problem. Also the Toolbar, Status Bar and RGB Values, menu items never
become checked, and these should be controlled from the App Wizard /
Component Gallery derived code?

Any Help?

Spencer Jones
Chief Software Developer
Azure Limited
E-Mail (spencer@azure.com)
Web Page (http://www.azure.com/~spencer)
User Location Service (uls.azure.com)






John Moulder -- jm@wg.icl.co.uk
Wednesday, February 05, 1997

[Mini-digest: 2 responses]

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

Try using the frame window instead of the view window :

pPopup->TrackPopupMenu(	TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
				point.x, point.y, AfxGetMainWnd());

This will direct the messages to the frame window, not the view.


----------
> From: Spencer Jones 
> To: 'MFC List' 
> Subject: Pop-up menu lists
> Date: 04 February 1997 11:19
> 
> Environment: MSVC 4.0 Win NT 4.0
> 
> In my application I have a view menu with the options:
> 
> 	Toolbar
> 	Status Bar
> 
> standard, as supplied by App Wizard. And my own commands:
> 
> 	RGB Values - for toggling a dialog bar added using Component Gallery
> 	Magnify Image - selects a magnify tool, handled by me
> 	Pointer Tool - selects a pointer tool, handled by me
> 	Zoom Percent - pop-up with a list of zoom percents, handled by me.
> 
> What I have attempted to do is to add a pop-up menu that is available
> when the right hand mouse button is clicked. I have created a new menu,
> with the same options as those in the view option, and the same resource
> ID.
> 
> My problem is:
> 
> 1. the menu options added by App Wizard / Component Gallery do not work
> in the pop-up menu. I.E. selecting Toolbar does not switch off the
> toolbar.
> 
> 2. The zoom percent allows the image to be resized, this works fine from
> both menus. However I wish to check the selected percent. I have done
> this in the OnUpdateHandler() for the function, and it works fine for
> the main menu, but nothing is ever checked in the new pop-up menu. I
> have placed a breakpoint in the handler and it is not called when the
> pop-up menu is opened.
> 
> I get a handle to the menu using the CMenu function
> 
> 	VERIFY(menu.LoadMenu(IDR_MYPOPUPMENU));
> 
> and display it using:
> 
> 	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
> 	point.x, point.y, this);
> 
> where pPopup is a pointer to the pop-up menu, and 'this' is the View.
> 
> I have also tried making pPopup the pointer to the View menu, using the
> main menu and the function GetSubMenu(1). But this gives the same
> problem. Also the Toolbar, Status Bar and RGB Values, menu items never
> become checked, and these should be controlled from the App Wizard /
> Component Gallery derived code?
> 
> Any Help?
> 
> Spencer Jones
> Chief Software Developer
> Azure Limited
> E-Mail (spencer@azure.com)
> Web Page (http://www.azure.com/~spencer)
> User Location Service (uls.azure.com)
> 
> 
> 
-----From: ktm@ormec.com

On mfc-l, Spencer Jones (Spencer@azure.com) writes:
> the menu options added by App Wizard / Component Gallery do not work 
> in the pop-up menu. I.E. selecting Toolbar does not switch off the 
> toolbar.
> 
> [...]
> 
> I get a handle to the menu using the CMenu function
>     VERIFY(menu.LoadMenu(IDR_MYPOPUPMENU));
> and display it using:
>     pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
>     point.x, point.y, this);
> 
> where pPopup is a pointer to the pop-up menu, and 'this' is the View.

Dispatch of the CommandUI messages is done by the frame window, not by the view.
Change "this" to AfxGetMainWnd(), and your popup menu should work as expected.

See also KB article Q139469, which is available in Books Online.

  Katy
-- 
Katy Mulvey                            ktm@ormec.com
Software Development Engineer
ORMEC Systems                          http://www.ormec.com



Geoffrey C. Begen -- geoff@stage1.com
Thursday, February 06, 1997

You mention that you pass a pointer to your view as the last parameter
to TrackPopupMenu(). This will invoke the CView::OnCmdMsg() handler when
a menu item is selected. If you look at the code in CView::OnCmdMsg()
you will see that when a view receives a command message it tries to
handle itself, then tries the document, then gives up. The handlers for
the commands you are having trouble with are in your main frame window.
Therefore, you need to pass AfxGetMainWnd() as the last parameter to
TrackPopupMenu().

The frame window will then route the message to your view, and when your
view gives up, it will handle the command itself or pass it to the
application.

--- Geoff
>----------
>From: 	Spencer Jones[SMTP:Spencer@Azure.com]
>Sent: 	Tuesday, February 04, 1997 3:19 AM
>To: 	'MFC List'
>Subject: 	Pop-up menu lists
>
>Environment: MSVC 4.0 Win NT 4.0
>
>In my application I have a view menu with the options:
>
>	Toolbar
>	Status Bar
>
>standard, as supplied by App Wizard. And my own commands:
>
>	RGB Values - for toggling a dialog bar added using Component Gallery
>	Magnify Image - selects a magnify tool, handled by me
>	Pointer Tool - selects a pointer tool, handled by me
>	Zoom Percent - pop-up with a list of zoom percents, handled by me.
>
>What I have attempted to do is to add a pop-up menu that is available
>when the right hand mouse button is clicked. I have created a new menu,
>with the same options as those in the view option, and the same resource
>ID.
>
>My problem is:
>
>1. the menu options added by App Wizard / Component Gallery do not work
>in the pop-up menu. I.E. selecting Toolbar does not switch off the
>toolbar.
>
>2. The zoom percent allows the image to be resized, this works fine from
>both menus. However I wish to check the selected percent. I have done
>this in the OnUpdateHandler() for the function, and it works fine for
>the main menu, but nothing is ever checked in the new pop-up menu. I
>have placed a breakpoint in the handler and it is not called when the
>pop-up menu is opened.
>
>I get a handle to the menu using the CMenu function
>
>	VERIFY(menu.LoadMenu(IDR_MYPOPUPMENU));
>
>and display it using:
>
>	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
>	point.x, point.y, this);
>
>where pPopup is a pointer to the pop-up menu, and 'this' is the View.
>
>I have also tried making pPopup the pointer to the View menu, using the
>main menu and the function GetSubMenu(1). But this gives the same
>problem. Also the Toolbar, Status Bar and RGB Values, menu items never
>become checked, and these should be controlled from the App Wizard /
>Component Gallery derived code?
>
>Any Help?
>
>Spencer Jones
>Chief Software Developer
>Azure Limited
>E-Mail (spencer@azure.com)
>Web Page (http://www.azure.com/~spencer)
>User Location Service (uls.azure.com)
>
>
>
>




Become an MFC-L member | Вернуться в корень Архива |