我用向导建了一个多文档视图程序,想在程序一开始就往里面添加一些菜单项,并可以显示,比如我想在帮助那个菜单下增加一个子菜单,我使用了以下的方法:先手工在用户菜单栏上添加了一个菜单项test,以后就往这里追加菜单项。然后是在文档类中添加了一个函数void testmenu(),并放在文档类的构造函数中调用,
void CTestDoc::testmenu()
{
CFrameWnd *pWnd=(CFrameWnd*)AfxGetApp()->GetMainWnd();
CMenu *pMenu=pWnd->GetMenu();
CString str;
pMenu->GetMenuString(1,str1,MF_BYPOSITION);//测试一下所先的菜单是不是想要的用户菜单
MessageBox(NULL,str1,"2",MB_OK);//输出的却是系统菜单中的菜单项
}
我想请问一下如何才能得到用户菜单的指针。注:多文档的菜单有两个,我不知道应该怎样叫,所以将一个称为系统菜单,另一个称为用户菜单。我想要的是在打开或新增文档后显示的那个。
void CTestDoc::testmenu()
{
CFrameWnd *pWnd=(CFrameWnd*)AfxGetApp()->GetMainWnd();
CMenu *pMenu=pWnd->GetMenu();
CString str;
pMenu->GetMenuString(1,str1,MF_BYPOSITION);//测试一下所先的菜单是不是想要的用户菜单
MessageBox(NULL,str1,"2",MB_OK);//输出的却是系统菜单中的菜单项
}
我想请问一下如何才能得到用户菜单的指针。注:多文档的菜单有两个,我不知道应该怎样叫,所以将一个称为系统菜单,另一个称为用户菜单。我想要的是在打开或新增文档后显示的那个。
// CMainFrame::OnReplaceMenu() is a menu command handler for CMainFrame
// class, which in turn is a CFrameWnd-derived class. It loads a new
// menu resource and replaces the SDI application window's menu bar with
// this new menu. CMainFrame is a CFrameWnd-derived class.
void CMainFrame::OnReplaceMenu()
{
// Load the new menu.
m_NewMenu.LoadMenu(IDR_SHORT_MENU);
ASSERT(m_NewMenu); // Remove and destroy the old menu
SetMenu(NULL);
::DestroyMenu(m_hMenuDefault); // Add the new menu
SetMenu(&m_NewMenu); // Assign default menu
m_hMenuDefault = m_NewMenu.GetSafeHmenu(); // or m_NewMenu.m_hMenu;
}