Today, I saw someone asking the context menu manager class ccontextmenumanager on the forum. I remember that I did it, but I forgot to remember it, so I may not forget it again next time...
Ccontextmenumanager and cmenu are also inherited from cobject. Please refer to here. However, menus look much better than cmenu, so many people prefer to use them. This is how to use msdn.
However, if you do not want to create a ccontextmenumanager class to manage your menus. In fact, there is another method: cwinappex has another method, the ccontextmenumanager type. If you want to add a menu,
Theapp. getcontextmenumanager ()-> addmenu (L "menu", idr_menu1 );
It is actually the ccontextmenumanager method. If your menu has not been initialized, call the cwinapp: initcontextmenumanager Method for initialization.
When using this menu, I encountered a problem when I wanted to gray a menu item. At first, I used methods like cmenu to solve the problem, but they didn't work. Later, I found a solution in the msdn forum. Call the on_update_command_ui macro to update the Object ID of the attribute window. Use the onupdatecontextfirst method.
Theapp. getcontextmenumanager ()-> addmenu (L "menu", idr_menu1 );
Header file afx_msg void onupdatecontextfirst (ccmdui * pcmdui );
Source File
On_update_command_ui (id_vod_menu_unpublish, & cxxxdlg: onupdatecontextfirst)
Void cxxxdlg: onupdatecontextfirst (ccmdui * pcmdui)
{ Pcmdui-> enable (m_benable );// M_benable makes you feel that the menu item is disabled
}
Assume that you want to disabled a certain item
M_benable = false;
Hmenu = theapp. getcontextmenumanager ()-> getmenubyid (idr_menu1 );
Enablemenuitem (hmenu, 1, mf_byposition | mf_disabled | mf_grayed );
Theapp. getcontextmenumanager ()-> showpopupmenu (idr_menu1, point. X, point. Y, this, true );
Okay, but that's a small problem. The effect of ccontextmenumanager menus is unsatisfactory. If you are willing to search for problems, most of them can be solved.