Set up CMenu menu item to implement selected menu item left-click Response Event

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.