Menus & ON_UPDATE_COMMAND_UI handlers
Eric Kenslow -- webmaster@digilight.com
Monday, September 09, 1996
Environment: Windows NT 4.0b1, MSVC++4.0
Hello all,
I'm writing an app in which I'm using a CWnd-derived (top level) object to
manage lists of icons (ground-breaking stuff, I know :]). I've implemented
a context menu for each of the items, which works fine. However, I got a
surprise tonight when I tried to add ON_UPDATE_COMMAND_UI (hereafter
abbreviated OUCU) handlers for the menu items. When the item is popped up,
the OUCU handlers are NOT called- instead, the OUCU handler for an item is
called AFTER that item has been selected!
This seems very strange to me, especially since I have another context
menu handled by a different window which doesn't display this behavior
(OUCU handlers are called before the menu is displayed).
So, my questions are:
1) Is this 'normal' behavior???
2) Whether it is or not, it's unacceptable to me, so how can I work around
it?
I've tried #include'ing AFXPRIV.H and sending myself a WM_IDLEUPDATECMDUI
(not sure if that's exact), but that didn't have any effect- shot in the
dark anyway.
Anyway, I'm really stumped by this. It goes against all that I've thought
was right and good about MFC, and I don't know how to fix it. Anybody who
can shed some light on this will receive my extreme gratitude.
/* Eric Kenslow - Digital Lighthouse Inc.
* webmaster@digilight.com
* http://www.digilight.com
*/
Wolfgang Loch -- Wolfgang.Loch@RZ.TU-Ilmenau.DE
Wednesday, September 11, 1996
[Mini-digest: 2 responses]
> I'm writing an app in which I'm using a CWnd-derived (top level) object to
> manage lists of icons (ground-breaking stuff, I know :]). I've implemented
> a context menu for each of the items, which works fine. However, I got a
> surprise tonight when I tried to add ON_UPDATE_COMMAND_UI (hereafter
> abbreviated OUCU) handlers for the menu items. When the item is popped up,
> the OUCU handlers are NOT called- instead, the OUCU handler for an item is
> called AFTER that item has been selected!
> This seems very strange to me, especially since I have another context
> menu handled by a different window which doesn't display this behavior
> (OUCU handlers are called before the menu is displayed).
Hi Eric.
You should make your main window the parent of the popup menu:
menu.TrackPopupMenu( ..., AfxGetMainWindow() );
--
/-------------------------------------------------\
| Wolgang Loch (Technical University of Ilmenau) |
| e-mail: Wolfgang.Loch@rz.TU-Ilmenenau.DE |
| www : http://www.rz.tu-ilmenau.de/~wolo |
\-------------------------------------------------/
-----From: "John Bundgaard"
> I'm writing an app in which I'm using a CWnd-derived (top level) object
to
> manage lists of icons (ground-breaking stuff, I know :]). I've
implemented
> a context menu for each of the items, which works fine. However, I got a
> surprise tonight when I tried to add ON_UPDATE_COMMAND_UI (hereafter
> abbreviated OUCU) handlers for the menu items. When the item is popped
up,
> the OUCU handlers are NOT called- instead, the OUCU handler for an item
is
> called AFTER that item has been selected!
[......]
Make sure that the parent windows passed in the TrackPopupMenu() function
is the main
window (CMainFrame).
John Bundgaard
johnb@image.dk
Jeffrey Smith -- wyvern@msn.com
Thursday, September 12, 1996
Make sure your menu ON_UPDATE_COMMAND_UI are handled in your frame class
message map.
Jeff Smith
Kostya Sebov -- sebov@is.kiev.ua
Friday, September 13, 1996
> [Mini-digest: 2 responses]
>
> > I'm writing an app in which I'm using a CWnd-derived (top level) object to
> > manage lists of icons (ground-breaking stuff, I know :]). I've implemented
> > a context menu for each of the items, which works fine. However, I got a
> > surprise tonight when I tried to add ON_UPDATE_COMMAND_UI (hereafter
> > abbreviated OUCU) handlers for the menu items. When the item is popped up,
> > the OUCU handlers are NOT called- instead, the OUCU handler for an item is
> > called AFTER that item has been selected!
> > This seems very strange to me, especially since I have another context
> > menu handled by a different window which doesn't display this behavior
> > (OUCU handlers are called before the menu is displayed).
>
> Hi Eric.
>
> You should make your main window the parent of the popup menu:
> menu.TrackPopupMenu( ..., AfxGetMainWindow() );
>
> --
> /-------------------------------------------------\
> | Wolgang Loch (Technical University of Ilmenau) |
> | e-mail: Wolfgang.Loch@rz.TU-Ilmenenau.DE |
> | www : http://www.rz.tu-ilmenau.de/~wolo |
> \-------------------------------------------------/
> -----From: "John Bundgaard"
>
>
>
> > I'm writing an app in which I'm using a CWnd-derived (top level) object
> to
> > manage lists of icons (ground-breaking stuff, I know :]). I've
> implemented
> > a context menu for each of the items, which works fine. However, I got a
> > surprise tonight when I tried to add ON_UPDATE_COMMAND_UI (hereafter
> > abbreviated OUCU) handlers for the menu items. When the item is popped
> up,
> > the OUCU handlers are NOT called- instead, the OUCU handler for an item
> is
> > called AFTER that item has been selected!
> [......]
>
> Make sure that the parent windows passed in the TrackPopupMenu() function
> is the main
> window (CMainFrame).
>
> John Bundgaard
> johnb@image.dk
>
>
NOT NECCESSARILY _MAIN_ window. The only requirement is that it should be
CWinFrame derivative!
---
Kostya Sebov.
----------------------------------------------------------------------------
Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua
Eric Kenslow -- webmaster@digilight.com
Saturday, September 14, 1996
Are you sure about this? I've successfully used popup menus in a
dialog-based app before (for a tray notify area context menu).
/* Eric Kenslow - Digital Lighthouse Inc.
* webmaster@digilight.com
* http://www.digilight.com
*/
----------
> From: Kostya Sebov
> To: mfc-l@netcom.com
> Subject: Re: Menus & ON_UPDATE_COMMAND_UI handlers
> Date: Friday, September 13, 1996 1:39 AM
>
> > [Mini-digest: 2 responses]
> >
> > > I'm writing an app in which I'm using a CWnd-derived (top
level) object to
> > > manage lists of icons (ground-breaking stuff, I know :]). I've
implemented
> > > a context menu for each of the items, which works fine. However, I
got a
> > > surprise tonight when I tried to add ON_UPDATE_COMMAND_UI
(hereafter
> > > abbreviated OUCU) handlers for the menu items. When the item is
popped up,
> > > the OUCU handlers are NOT called- instead, the OUCU handler for an
item is
> > > called AFTER that item has been selected!
> > > This seems very strange to me, especially since I have
another context
> > > menu handled by a different window which doesn't display this
behavior
> > > (OUCU handlers are called before the menu is displayed).
> >
> > Hi Eric.
> >
> > You should make your main window the parent of the popup menu:
> > menu.TrackPopupMenu( ..., AfxGetMainWindow() );
> >
> > --
> > /-------------------------------------------------\
> > | Wolgang Loch (Technical University of Ilmenau) |
> > | e-mail: Wolfgang.Loch@rz.TU-Ilmenenau.DE |
> > | www : http://www.rz.tu-ilmenau.de/~wolo |
> > \-------------------------------------------------/
> > -----From: "John Bundgaard"
> >
> >
> >
> > > I'm writing an app in which I'm using a CWnd-derived (top level)
object
> > to
> > > manage lists of icons (ground-breaking stuff, I know :]). I've
> > implemented
> > > a context menu for each of the items, which works fine. However, I
got a
> > > surprise tonight when I tried to add ON_UPDATE_COMMAND_UI
(hereafter
> > > abbreviated OUCU) handlers for the menu items. When the item is
popped
> > up,
> > > the OUCU handlers are NOT called- instead, the OUCU handler for an
item
> > is
> > > called AFTER that item has been selected!
> > [......]
> >
> > Make sure that the parent windows passed in the TrackPopupMenu()
function
> > is the main
> > window (CMainFrame).
> >
> > John Bundgaard
> > johnb@image.dk
> >
> >
> NOT NECCESSARILY _MAIN_ window. The only requirement is that it should be
> CWinFrame derivative!
> ---
> Kostya Sebov.
>
----------------------------------------------------------------------------
> Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua
Kostya Sebov -- sebov@is.kiev.ua
Friday, September 20, 1996
> > NOT NECCESSARILY _MAIN_ window. The only requirement is that it should be
> > CWinFrame derivative!
> > ---
> Are you sure about this? I've successfully used popup menus in a
> dialog-based app before (for a tray notify area context menu).
>
> /* Eric Kenslow - Digital Lighthouse Inc.
> * webmaster@digilight.com
> * http://www.digilight.com
> */
I meant that it's CWinFrame class that contains necessary logic (message
handlers) for automatic usage of ON_UPDATE_COMMAND_UI/OnUpdateXXX stuff.
Of course you can call TrackMenuPopup with any window being the owner
(even not having corresponding C++ object) but you should implement your own
menu-popup and menu-selection message handlers and call CYourObject::OnCmdMsg
from within manually.
---
Kostya Sebov.
----------------------------------------------------------------------------
Tel: (38 044) 266-6387 | Fax: (38 044) 266-6195 | E-mail: sebov@is.kiev.ua
| Вернуться в корень Архива
|