Here I just based on their own projects to do some summary, the realization of the right-click popup menu items, click the Left button to select menu items:
CMenu menu; VERIFY (menu. CreatePopupMenu ());//Create a new CMenu menu itemMenu. APPENDMENUW (Mf_string,10001, _t (" Redefine")); Menu. APPENDMENUW (0, Mf_separator);//Add a lineMenu. APPENDMENUW (Mf_string,10002, _t ("Modify")); Menu. APPENDMENUW (0, Mf_separator); Menu. APPENDMENUW (mf_string,10003, _t ("Delete")); Menu. APPENDMENUW (0, Mf_separator); CPoint pt;//menu item Pop-up pointGetCursorPos (&PT); Menu. TrackPopupMenu (Tpm_leftbutton, Pt.x, Pt.y, This);//Displays the shortcut menu at the specified location, which is a left-button event
Menu. DestroyMenu ();//Select to destroy the menu item
The code above establishes a menu item that includes three menus, namely, "redefine", "modify", and "delete".
Completed the above section, we just set up a menu item, here we also need to corresponding to our selection after the event, we need to complete the OnCommand (WPARAM WPARAM, LPARAM LPARAM) function below the dialog box, in this function, All the commands go through this function. In this project, our OnCommand (WPARAM WPARAM, LPARAM LPARAM) functions are:
BOOL Csdpalette::oncommand (WPARAM WPARAM, LPARAM LPARAM) {//TODO: Add private code here and/or call base classUINT UID = (UINT) WParam;//The ID of the selected item Switch(UID)//determine which item is selected { Case 10001: Acdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("redefinety\n"),false,true);//Select RedefineAcdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("updatepalette\n"),false,true); Break; Case 10002: Acdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("alterdefinety\n"),false,true);//Select to modifyAcdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("updatepalette\n"),false,true); Break; Case 10003: Acdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("deletety\n"),false,true);//Select to deleteAcdocmanagerptr ()->sendstringtoexecute (Curdoc (), _t ("updatepalette\n"),false,true); Break; default: Break; } returnCzduipalette::oncommand (WParam, LParam);}
Here is the completion of a menu bar establishment and the corresponding process! These are only for this project to write, for the CMenu class there are many ways to implement the Setup menu and corresponding, later encountered will continue to refine this note.
Set up CMenu menu item to implement selected menu item left-click Response Event