BOOL CGuiFrameWnd::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) CString strFullString; if (strFullString.LoadString(nIDResource)) AfxExtractSubString(m_strTitle, strFullString, 0); // first sub-string VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG)); // attempt to create the window LPCTSTR lpszClass = GetIconWndClass(dwDefaultStyle, nIDResource); LPCTSTR lpszTitle = m_strTitle; if (!Create(lpszClass, lpszTitle, dwDefaultStyle, rectDefault,pParentWnd, NULL, 0L, pContext)) { return FALSE; // will self destruct on failure normally } // save the default menu handle ASSERT(m_hWnd != NULL); m_hMenuDefault = ::GetMenu(m_hWnd); // load accelerator resource LoadAccelTable(MAKEINTRESOURCE(nIDResource)); if (pContext == NULL) // send initial update SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE); return TRUE; }
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); ASSERT(m_hMenuShared == NULL); // only do once 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 ASSERT(m_hMenuShared == NULL); // only do once 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 { TRACE0("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; }