Menu Messages Besides the all-important WM_COMMAND message, window provides five other messages at various stages of menu selection: WM_SYSCOMMAND WM_INITMENU WM_ININMENUPOPUP WM_MENUSELECT WM_MENUCHAR Programs may pass these to DefWindowProc() or intercept them if they wish to take any action. 1.WM_SYSCOMMAND:- this is very important window message that arrives in a variety of situations. It is generated whenever user clicks on maximize or minimize icons in the caption bar, double click the caption bar or open up the system menu.
Contd…. WM_SYSCOMMAND message has been sent, while lparam contains mouse co-ordinates if a mouse click is responsible for producing the event. 2. WM_INITMENU:- this message arrives just before the window’s top-level menu is about to be activated. This happens when users click on any of the top-level menu’s options, or a corresponding hotkey is pressed. this gives the program an opportunity to modify the top- level menu before it is activated.
contd 3. WM_INITMENUPOPUP:- this is very commonly intercepted messages. It arrives in two distinct settings:- just before the activation of system menu, and just before the activation of any otherpopup menu. The message paramenters are as follow:- wParam:- handle of the popup menu being activated. lParam LOWORD :- it contains the index of the popup menu in the top-level menu. lParam HIWORD:- system menu flag. A non-zero value indicates that the system menu is being activated. While zero signifies the operating of some other popup menu.
Contd… 4. WM_MENUSELECT:- this messsage indicates that a menu is open, and the user has selected a menu option. This message does not necessarily imply that the particular WM_COMMAND message must arrive: the user could change his selection before he presses ENTER or double clicks the mouse. The message parameters are:- wParam:-Menu item ID, or popup menu handle, as applicable. lParam LOWORD:- contains the menu flags associated with the currently selected menu option. lParam HIWORD:- contains the system menu handle.
5. WM_MENUCHAR:- this is an error-handling messsage from windows, which is issued whenever an invalid hotkey is pressed by the user. Menu Templates:- This is an easiest way to create windows menus. It involves no programming, because window automatically makes all the API function calls required to create and fill up the menu. This method involves writing an ASCII script using a reserved words and placing it into the application’s “resource script file”, which has the extension(.RC). This script is then compiled by the resource compiler and then embedded into the.EXE file, where the windows can load it at runtime.
A menu template BigdinnerMenu Menu { popup “soup” { MENUITEM “Tomato”, 1 MENUITEM “vegetable ”, 2 MENUITEM “chicken ”, 3 }
Using system Menu:- hmenu=GetSystemMenu(hwnd, FALSE); Messages from the system menu:- WM_SYSCOMMAND