如果删除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);
}如何解决以上的问题
错误是:
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);
}如何解决以上的问题
ASSERT(pMenu != NULL);
你定义窗口时不要定义局部的menu对象
不妨定义menu为类的成员或者全局的试试
我的解决方法是,再CMainFrame中重写OnCreateClient方法得到菜单资源然后再调用基类CMDIFrameWnd的CreateClient方法