2

I migrated my MFC MDI application to use the new MFC Feature Pack. I have many toolbars and dockable panes. As far as I understand, the location and size of each of them is saved in the registry when closing the application, and loaded when loading the main frame.

I want to add a feature in my application to reset the layout of the toolbars/panes to the original layout.

I have tabbedpanes also in my application.

sometimes I will dock separate panes to tabbed panes.

Is there a way to actually reset the layout of my application AFTER it has been loaded?

Visual Studio has a similar feature called "Reset Window Layout".

I am getting samples in the internet for restoring mainframe window using SetWindowPlacement() and GetWindowPlacement().

I don't know how to use these functions for toolbars and CDockablePanes and achieve my requirement?

Is there any other solution apart from using SetWindowPlacement() and GetWindowPlacement()?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    Seeing the code of `CFullScreenImpl::ShowFullScreen` may be a good start – sergiol Apr 19 '18 at 09:48
  • 1
    You can have a dedicated method that restores the initial layout using `CDockablePane` methods such as `AttachToTabWindow`, `DockToWindow`, `ShowPane`, ... or simply prevent loading the stored layout by calling `EnableLoadDockState(FALSE)` in the constructor of your `CMainFrameEx` (where the latter requires a restart of your app). – fhe Apr 19 '18 at 12:37
  • sergiol and fhe, thanks for the suggestions. It helped me and able to achieve my requirement. –  Apr 19 '18 at 13:08

3 Answers3

3

I am able to meet my requirement using below code.

 void CMainFrame::OnPanesResetLayout() 
    {
        CDockingManager* pDockMgr = GetDockingManager();
        if (pDockMgr == NULL)return;
        CRect rect;
        rect.SetRectEmpty();
        ClientToScreen(rect);
        SetRedraw(FALSE);

        CObList list;
        pDockMgr->GetPaneList(list, TRUE,0,TRUE);
        // UnDock and hide DockingControlBars
        POSITION pos;
        for (pos = list.GetHeadPosition(); pos != NULL;)
        {
            CBasePane* pBarNext = (CBasePane*) list.GetNext(pos);
            if (!::IsWindow(pBarNext->m_hWnd))continue;
            CDockablePane* pBar = DYNAMIC_DOWNCAST(CDockablePane, pBarNext);
            if (pBar != NULL)
            {
                if(pBar->IsAutoHideMode()) pBar->SetAutoHideMode(FALSE, CBRS_ALIGN_ANY);/*ToggleAutoHide();*/
                if (pBar->IsMDITabbed ())
                    continue;
                pBar->UndockPane();
                ShowPane(pBar, FALSE,FALSE, FALSE);
            }
            CMFCToolbar* pToolBar = DYNAMIC_DOWNCAST(CMFCToolbar, pBarNext);
            if(pToolBar)
                pToolBar->m_recentDockInfo.m_recentSliderInfo.m_rectDockedRect = rect;


        }

        m_wndBar1.DockToFrameWindow(CBRS_LEFT,m_wndBar1.GetAHRestoredRect());
        ShowPane(m_wndBar1, TRUE,FALSE, FALSE);
        m_wndBar2.DockToFrameWindow(CBRS_RIGHT,m_wndBar2.GetAHRestoredRect());
        ShowPane(m_wndBar2, TRUE,FALSE, FALSE);

    //for tabbed pane
    CTabbedPane *pTabbedPane;
    m_wndTab1.DockToFrameWindow(CBRS_BOTTOM,m_wndTab1.GetAHRestoredRect());
        m_wndTab2.AttachToTabWnd(&m_wndTab1, DM_SHOW, FALSE,reinterpret_cast<CDockablePane**>(&pTabbedPane));
        m_wndTab3.AttachToTabWnd(&m_wndTab1, DM_SHOW, FALSE,reinterpret_cast<CDockablePane**>(&pTabbedPane));

    ShowPane(m_wndTab1, TRUE,FALSE, FALSE);
    ShowPane(m_wndTab2, TRUE,FALSE, FALSE);
    ShowPane(m_wndTab3, TRUE,FALSE, FALSE);

    SetRedraw(TRUE);
        RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
        AdjustClientArea();

}
0

As described in my comment above, one option to restore the initial layout from a running application would be to use the methods provided by CDockablePane, specifically

  • AttachToTabWindow
  • DockToWindow and
  • ShowPane

A second option, which would require restarting your application, is to call EnableLoadDockState(FALSE) in the constructor of your CFrameWndEx derived class. This would prevent loading the stored dock state and, as a consequence, restore the initial layout.

fhe
  • 6,099
  • 1
  • 41
  • 44
0

A simple method to solve this is to delete from registry key all keys which store the panels info: "BasePane" and "Pane" from "Workspace" registry folder from your app registry entry :) Easy.

Flaviu_
  • 1,285
  • 17
  • 33