How to implement a dynamic menu in the VC

zhaozj2021-02-11  180

1. Generate a dynamic menu First define a menu class object: cMenu m_menumain; create a menu: createMenu (cMenu *) Create a normal menu CreatePopUpMenu () Create a pop-up menu item 2. Use menu and application hooks to use SetMenu (CMenu) *) 3. Modify the menu item Add and Insert Use appendmenu () and INSERTMENU () DeleteMenu ()

** 4. Messages for dynamic menu items We can process in oncmdmsg (uint nid, int ncode, void * pextra, afx_cmdhandlerinfo * handlerinfo). The NID in the parameter is the message ID number sent, for the menu, is the menu ID, if ncode = cn_command indicates the message sent by the menu item. Below is sample code: oncmdmsg (uint nid, int ncode, void * pextra, afx_cmdhandlerinfo * handlerinfo) {wparam menuid = getCurrentMessage () -> wparam; // The ID number IF (MENUID> = ID_MENU) / / check the ID is dynamically established {if (MenuID == Nid && Ncode == CN_COMMAND) // menu item is clicked {cstring strmenuname; / / Menu name getMenu () -> getmenustring (menuid, strident, mf_string); // Different processing according to StrMenuname}}}

The above is a little experience when I am writing the dynamometer menu, welcome you to make better solutions.

转载请注明原文地址:https://www.9cbs.com/read-5865.html

New Post(0)