IMPLEMENTING A CONTEXT MENU

You need two menus for the context menu: one for when there is an element under the mouse cursor and another for when there isn’t. Change to Resource View and expand the list of resources. Right-click the Menu folder to bring up a context menu — another demonstration of what you are now trying to create in the Sketcher application. Select Insert Menu to create a new menu resource. This has a default ID IDR_MENU1 assigned, but you can change this. Select the name of the new menu in the Resource View and display the Properties window for the resource by pressing Alt+Enter (this is a shortcut to the View ⇒ Other Windows ⇒ Properties Window menu item). You can then edit the resource ID in the Properties window by clicking the value for the ID. You could change it to something more suitable, such as IDR_CONTEXT_MENU, in the right column. Note that the name for a menu resource must start with IDR. Pressing the Enter key saves the new name.

The next step is to create a drop-down menu containing Move and Delete as menu items that will apply when an element is under the cursor. The other drop-down menu will contain menu items from the Element and Color menus to allow the current selections to be changed. You can enter a name for the new item on the menu bar in the Editor pane. This can have any old caption because it won’t actually be seen by the user; the caption “element” will be OK. Now you can add the Move and Delete items to this menu. The default IDs of ...

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.