Article ID: 139469 - Last Review: November 21, 2006 - Revision: 3.1 HOWTO: How to Use TrackPopupMenu() and Update UI HandlersThis article was previously published under Q139469 On This PageSUMMARY
Floating popup 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.
MORE INFORMATION
Menu items in an MFC application are updated in response to the
WM_INITMENUPOPUP message. The MFC CFrameWnd::OnInitMenuPopup() function
has special code for handling the Update UI mechanism.
The code in CFrameWnd::OnInitMenuPopup iterates through the menu items and checks for the Update UI and Command handlers in the command route, for each item. Depending on the result of this search, it updates the state of the menu item. The WM_INITMENUPOPUP message is sent only to the owner of the menu. Hence for the menus to be updated correctly, you need to make a CFrameWnd-derived class the owner of the floating popup menu. The Update UI mechanism doesn't work for a dialog-based application because the code that calls the UI handlers is not found in a CDialog-derived class. The following sample code displays the File popup menu in the CView-derived class (CMyView) in response to the WM_RBUTTONUP message. Note that the main frame window pointer is used in the call to the CMenu::TrackPopupMenu() function, so the Update UI mechanism will work correctly. Sample CodeREFERENCES
For information about command and message routing, please refer to MFC
Technical Note 21 in Books Online
APPLIES TO
| Article Translations
|

Back to the top
