47.1.9 Menu Messages

Windows reports the user's menu-related activity by sending messages to the window procedure of the window that owns the menu. The first menu-related message that the window procedure receives is WM_SYSCOMMAND. Windows sends this message when the user activates the menu by clicking the menu bar or pressing a key that activates the menu (see Section 0.1.5.1, “Standard Keyboard Interface”). The WM_SYSCOMMAND message includes a flag, either SC_KEYMENU or SC_MOUSEMENU, that indicates the hardware device used to activate the menu.

Next, Windows sends the WM_INITMENU message. Your window procedure receives this message before Windows displays any pop-up menus, so you can modify the pop-up menus before the user sees them. Windows sends the WM_INITMENU message only once per menu activation.

When the user selects a pop-up item, Windows sends the owner window the WM_INITMENUPOPUP message before displaying the pop-up menu. By processing this message, you can modify the pop-up menu before Windows displays it.

Each time the user moves the highlight from one item to another, Windows sends a WM_MENUSELECT message to the window procedure of the menu's owner window. This message identifies the currently-selected menu item. Many applications provide an information area at the bottom of their main windows, and use this message to display additional information about the selected menu item.

Windows sends a WM_COMMAND message to the window procedure when the user chooses a command item from a menu. The low-order word of the WM_COMMAND message's wParam parameter contains the identifier of the chosen item. Your window procedure should examine the identifier and process the message accordingly.