请教:调试时出现的问题

类别:VC语言 点击:0 评论:0 推荐:

问题类如下:

class CUserFrame : public CMDIChildWnd

调用函数如下,实现功能是只能生成一个子框架和视图:

void CDatamartApp::OnUserManagement()
{
 extern CUserFrame * bUserManagement;
 if(!bUserManagement)
 {
  CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
  bUserManagement=(CUserFrame *)pFrame->CreateNewChild(RUNTIME_CLASS(CUserFrame), IDR_MAINFRAME, m_hMDIMenu, m_hMDIAccel);
 }
 else
 {
  bUserManagement->SendMessage(WM_SETFOCUS);
 }
   
}

程序运行后,只要调用OnUserManagement(),跟踪器就出现:

Warnning:  no shared menu/acceltable for MDI Child window.

经过追踪,发现问题是winmdi.cpp中以下函数(红色部分)导致的:

BOOL CMDIChildWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
  CWnd* pParentWnd, CCreateContext* pContext)
{
 // only do this once
 ASSERT_VALID_IDR(nIDResource);
 ASSERT(m_nIDHelp == 0 || m_nIDHelp == nIDResource);

 m_nIDHelp = nIDResource;    // ID for help context (+HID_BASE_RESOURCE)

 // parent must be MDI Frame (or NULL for default)
 ASSERT(pParentWnd == NULL || pParentWnd->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)));
 // will be a child of MDIClient
 ASSERT(!(dwDefaultStyle & WS_POPUP));
 dwDefaultStyle |= WS_CHILD;

 // if available - get MDI child menus from doc template
 CMultiDocTemplate* pTemplate;
 if (pContext != NULL &&
  (pTemplate = (CMultiDocTemplate*)pContext->m_pNewDocTemplate) != NULL)
 {
  ASSERT_KINDOF(CMultiDocTemplate, pTemplate);
  // get shared menu from doc template
  m_hMenuShared = pTemplate->m_hMenuShared;
  m_hAccelTable = pTemplate->m_hAccelTable;
 }
 else
 {
  TRACE(traceAppMsg, 0, "Warning: no shared menu/acceltable for MDI Child window.\n");
   // if this happens, programmer must load these manually
 }

 CString strFullString, strTitle;
 if (strFullString.LoadString(nIDResource))
  AfxExtractSubString(strTitle, strFullString, 0);    // first sub-string

 ASSERT(m_hWnd == NULL);
 if (!Create(GetIconWndClass(dwDefaultStyle, nIDResource),
   strTitle, dwDefaultStyle, rectDefault,
   (CMDIFrameWnd*)pParentWnd, pContext))
 {
  return FALSE;   // will self destruct on failure normally
 }

 // it worked !
 return TRUE;
}

请问怎么会这样?

本文地址:http://com.8s8s.com/it/it705.htm