A vPopupMenu is used to show a floating popup menu, usually as the result of right clicking the mouse. They use the vMenu structure to define the items of the menu. Submenus are supported, but hot keys are not. Just leave the hot key field blank.
To use a popup menu, you usually track mousedown events in your canvas pane and watch for right clicks. You then can create a vPopupMenu object, and call the ShowMenu method to display the popup menu. When the user picks an item on the popup menu, a message is sent to the WindowCommand method of the parent window of the canvas. The application program can also change attributes of the various menu items of the popup menu using methods provided by vPopupMenu.
When the vPopupMenu object is defined, you provide the vMenu definition, and the parent vWindow of the canvas. You can use vCanvasPane::GetPaneParent() to easily get this value.
Call this method to display the popup menu. This method will usually be called from the overridden MouseDown method of your canvas. This will popup the menu at canvas coordinates x,y. (Note: for vTextCanvasPanes, you should override MouseDown, not TextMouseDown) This method does not return until the user has either picked a menu item, or dismissed the popup menu. If the user picks a menu item, then a message will be sent to the WindowCommand method of the parent window to the canvas pane. This is generally what you want to do, and it keeps all the command actions localized to that method.
The following example is very simple, and shows how to override the MouseDown method to detect a right click, and then how to display the popup menu. Remember that the parent window of the canvas will use its WindowCommand method to receive the messages when the user picks an item.
//===================>>> popTextCanvasPane::TextMouseDown <<<================== void popTextCanvasPane::MouseDown(int x, int y, int button) { // Note - override MouseDown for all canvas types // Meaningless menu examples static vMenu SubMenu[] = { {"&Close...", M_CloseFile, isSens, notChk, noKeyLbl, noKey, noSub}, {"Exit", M_Exit, isSens, notChk, noKeyLbl, noKey, noSub}, {NULL} }; static vMenu FileMenu[] = { {"&New", M_New, isSens, notChk, noKeyLbl, noKey, noSub}, {"&Open...", M_Open, isSens, notChk, noKeyLbl, noKey, noSub}, {"Other", 0, isSens, notChk, noKeyLbl, noKey, &SubMenu[0]}, {NULL} }; vPopupMenu pm(FileMenu,GetPaneParent()); // define the popup if (button == 3) // check for right button (void) pm.ShowMenu(x, y); else // default action otherwise vTextCanvasPane::MouseDown(x,y,button); }