PRB: Accelerator Key Not Disabled with ON_UPDATE_COMMAND_UI

ID: Q120598


The information in this article applies to:


SYMPTOMS

If a popup menu contains a submenu and a menu item on that submenu uses an accelerator key, you can't enable or disable the accelerator key by calling CCmdUI::Enable() in the ON_UPDATE_COMMAND_UI for that menu item.

Example

For example, if an application has the following menu structure for the main application window, pressing CTRL+M sends the command for MenuItem.

   File  Other
          Popup
             MenuItem Ctrl+M
          Item Ctrl+T 
The MenuItem command can be disabled and enabled by using an ON_UPDATE_COMMAND_UI() handler such as this:

   void CMyView::OnUpdateMenuItem(CCmdUI* pCmdUI)
      {
         pCmdUI->Enable(m_bEnabled);
      } 
However, this doesn't enable or disable the accelerator key (CTRL+M). To see whether the accelerator was disabled or enabled correctly, select the MenuItem menu item manually by choosing "Other," then "Popup," and then "MenuItem." This calls the ON_UPDATE_COMMAND_UI() function to disable (grey out) the MenuItem command.


CAUSE

The ON_UPDATE_COMMAND_UI() handler is called for menu items from the OnInitMenuPopup() handler of the menu's frame window. Windows only sends the WM_INITMENUPOPUP message to top-level popups, not submenus, when an accelerator key is used. This explains why the accelerator key for Item in the menu above will be disabled as expected but not the menu item in the submenu.


RESOLUTION

To resolve the problem:

Additional query words: 1.50 2.50 2.51 2.52 pop-up pop up


Keywords          : kb16bitonly 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: July 21, 1999