When i use GetMenu()->GetSubMenu(2)-> 'xxx', there is an error: Exception thrown at 0x00007FFEF70E4FD3 (mfc140d.dll) (in Menu.exe): 0xC0000005: An access violation occurred while reading location 0x0000000000008.
I added the above code at the end of the OnCreate function in the CMainFrame class.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){
GetMenu()->GetSubMenu(2)->CheckMenuItem(0, MF_BYPOSITION | MF_CHECKED);
}
CodePudding user response:
3.Class "Cxxxx" does not have member "GetContextMenuManager" 'GetContextMenuManager': is not a member of'Cxxxx' After analysis, it is found that the current class Cxxx is inherited from CWinApp, which does not have the GetContextMenuManager function. If you select Use Menu Bar and Toolbar when creating a project, no error is reported. After analysis, it is found that Cxxx is derived from CWinAppEx. It has the GetContextMenuManager() member method. Therefore, do not report an error, manually modify the derived class.
CodePudding user response:
It's true that GetMenu() got a null pointer. I found two solutions:
Change the value of CMFCMenuBar m_wndMenuBar in Mainfrm.h mainfrm.cpp. Delete the code of the. The compilation is successful.
When creating a project, select Use a classic menu.