Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


If the CWnd object is associated with a menu, OnMenuSelect is called by the framework when the user selects a menu item.

afx_msg void OnMenuSelect( 
   UINT nItemID, 
   UINT nFlags, 
   HMENU hSysMenu  



Identifies the item selected. If the selected item is a menu item, nItemID contains the menu-item ID. If the selected item contains a pop-up menu, nItemID contains the pop-up menu index, and hSysMenu contains the handle of the main (clicked-on) menu.


Contains a combination of the following menu flags:

  • MF_BITMAP   Item is a bitmap.

  • MF_CHECKED   Item is checked.

  • MF_DISABLED   Item is disabled.

  • MF_GRAYED   Item is dimmed.

  • MF_MOUSESELECT   Item was selected with a mouse.

  • MF_OWNERDRAW   Item is an owner-draw item.

  • MF_POPUP   Item contains a pop-up menu.

  • MF_SEPARATOR   Item is a menu-item separator.

  • MF_SYSMENU   Item is contained in the Control menu.


If nFlags contains MF_SYSMENU, identifies the menu associated with the message. If nFlags contains MF_POPUP, identifies the handle of the main menu. If nFlags contains neither MF_SYSMENU nor MF_POPUP, it is unused.

If nFlags contains 0xFFFF and hSysMenu contains 0, Windows has closed the menu because the user pressed the ESC key or clicked outside the menu.


This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

Community Additions

© 2015 Microsoft