VC自定义菜单资源

1.首先建立菜单资源; 2.用这个菜单类已经是别人实现的,定义一个CMyCoolMenu类对象m_mnu,在CMainFrame类中int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)调用m_mnu.AttachMenu(GetMenu()->GetSafeHmenu(),IDR_MENU1,CSize(16,15))方法关联菜单与菜单资源 3.在CMainFrame类的头文件中的宏定义之间加两个函数 protected: //{{AFX_MSG(CMainFrame) afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct); afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct); // NOTE - the ClassWizard will add and remove member functions here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG 4.在CMainFrame类的实现文件中的消息映射部分添加映射宏 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() ON_WM_DRAWITEM() ON_WM_MEASUREITEM() //}}AFX_MSG_MAP END_MESSAGE_MAP() 4.在CMainFrame类的实现文件中改写主窗口的“OnDrawItem”方法、“OnMeasureItem”方法。 void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { m_mnu.DrawItem(lpDrawItemStruct); } void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { m_mnu.MeasureItem(lpMeasureItemStruct); }

你可能感兴趣的:(VC初学)