如果删除VC默认生成的MDI程序的菜单在添加自己的菜单就会在pMainFrame->LoadFrame这里出错,
错误是:
Debug Assertion Faild
file xxxxxx\winmdi.cpp
line 139
出现错误的代码是:
BOOL CMDIFrameWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*)
{
CMenu* pMenu = NULL;
if (m_hMenuDefault == NULL)
{
// default implementation for MFC V1 backward compatibility
pMenu = GetMenu();
ASSERT(pMenu != NULL);
// This is attempting to guess which sub-menu is the Window menu.
// The Windows user interface guidelines say that the right-most
// menu on the menu bar should be Help and Window should be one
// to the left of that.
int iMenu = pMenu->GetMenuItemCount() - 2; // If this assertion fails, your menu bar does not follow the guidelines
// so you will have to override this function and call CreateClient
// appropriately or use the MFC V2 MDI functionality.
ASSERT(iMenu >= 0);
pMenu = pMenu->GetSubMenu(iMenu);     //这里返回NULL
ASSERT(pMenu != NULL);
} return CreateClient(lpcs, pMenu);
}如何解决以上的问题

解决方案 »

  1.   

    代码里确定是的menu指针不为空
    ASSERT(pMenu != NULL);
    你定义窗口时不要定义局部的menu对象
    不妨定义menu为类的成员或者全局的试试
      

  2.   

    这段代码是winmdi.cpp中代码,当我修改菜单后,这里就出错
      

  3.   

    问题解决了,但我不知道这样做对不对
    我的解决方法是,再CMainFrame中重写OnCreateClient方法得到菜单资源然后再调用基类CMDIFrameWnd的CreateClient方法