ADDING MENU MESSAGE HANDLERS
To create an event handler for a menu item, right-click the item and select Add Event Handler from the pop-up displayed. If you try this with the Black menu item in the Color menu pop-up, you’ll see the dialog shown in Figure 13-6.
The wizard has already chosen a name for the handler function. You could change it, but OnColorBlack seems like a good name to me.
You obviously need to specify the message type as one of the choices shown in the dialog. The “Message type:” box in the window in Figure 13-6 shows the two kinds of messages that can arise for a particular menu ID. Each type of message serves a distinct purpose in dealing with a menu item.
MESSAGE TYPE | DESCRIPTION |
COMMAND | This type of message is issued when a particular menu item has been selected. The handler should provide the action appropriate to the menu item being selected, such as by setting the current color in the document object or setting the element type. |
UPDATE_COMMAND_UI | This is issued when the menu should be updated — checked or unchecked, for example — depending on its status. This message occurs before a pop-up menu is displayed so you can set the appearance of the menu item before the user sees it. |
The way these messages work is quite simple. When you click a menu item in the menu bar, an UPDATE_COMMAND_UI message is sent for each item in that menu ...
Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.