Use the ccontextmenumanager menu

Source: Internet
Author: User

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.

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.