請教:除錯時出現的問題

Nicky_Lai發表於2004-09-09

問題類如下:

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;
}

請問怎麼會這樣?

相關文章