none
Changed CMDIChildWnd to CMDIChildWndEx: does not show anything inside the frame RRS feed

  • Question

  • Hi all

    I have an MFC application that works perfectly with the CMDIChildWnd class, the frame is loaded and a splitterwnd is shown. I needed to create a new MFC application that uses the ribbon as the interface, and for that the only change I made was that my classes inherited from CMDIChildWndEx.
    The two MFC applications should work with CMDIChildWndEx, but the old application does not show anything in the frames, it does not show errors, exceptions, it does not show inside the window. I already tried changing the style, forcing the frame size, changing the spliterwnd but nothing worked. See the LoadFrame code:

    void CMyFrame::ActivateFrame(int nCmdShow)
    {
    	if (m_pMDIFrame && m_pMDIFrame->SendMessage(WM_IS_ENABLE_MDI_TAB))
    	{
    		LONG style = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE) | WS_MAXIMIZE;
    		style &= ~WS_BORDER & ~WS_THICKFRAME & ~WS_DLGFRAME & ~WS_CAPTION;
    		::SetWindowLong(GetSafeHwnd(), GWL_STYLE, style);
    		style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
    		style &= ~WS_EX_CLIENTEDGE;
    		::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
    		ShowWindow(SW_SHOWMAXIMIZED);
    		return;
    	}
    
    	if (m_bInsideMDIFrame)
    	{
    		CMDIChildWndEx::ActivateFrame(nCmdShow);
    		return;
    	}
    
    	long style = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE);
    	style &= ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX;
    	::SetWindowLong(GetSafeHwnd(), GWL_STYLE, style);
    	style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
    	style &= ~WS_EX_CLIENTEDGE;
    	::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
    
    	SetWindowPos(NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); 
    	
    	CFrameWnd::ActivateFrame(SW_SHOWNOACTIVATE);
    }
    
    BOOL CMyFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
    	CWnd* pParentWnd, CCreateContext* pContext)
    {
    	if (g_globalVariables.GetParentWnd() == NULL)
    	{
    		if (m_bInsideMDIFrame)
    			return CMDIChildWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
    
    		return CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
    	}
    
    	ASSERT(m_nIDHelp == 0 || m_nIDHelp == nIDResource);
    
    	m_bInsideMDIFrame = FALSE;
    
    	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));
    
    	dwDefaultStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
    
    	// attempt to create the window
    	LPCTSTR lpszClass = GetIconWndClass(dwDefaultStyle, nIDResource);
    	LPCTSTR lpszTitle = m_strTitle;
    	
    	if (!CFrameWnd::Create(lpszClass, lpszTitle, dwDefaultStyle, rectDefault, g_globalVariables.GetParentWnd(), 0, 0, 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;
    }

    Another difference is if application uses MDI tabs, in my tests everything indicates that CMDIChildWndEx does not work without the ribbon. See the image:

    Has anyone had the same problem? Please, can anyone help me?
    Thank you very much


    Sunday, February 3, 2019 9:55 AM