5
votes

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 added a menu item whose command is handled in my CWinAppEx derived class as follows:

CleanState();
LoadState((CMDIFrameWndEx*)m_pMainWnd);

But it does not seem to work properly.

However, if I put the CleanState() function call before the call to the LoadMainFrame(), the application loads with the default layout (the one I want).

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

Thank you so much.

2

2 Answers

0
votes

I don't have an easy answer for you. I had 3 docking windows using MFC Feature Pack in Visual Studio 2017. I called CleanSlate and then positioned the docking panes making sure they are visible. I experimented with the size of the main frame window and the docking windows to get it to look right.

void CMainFrame::OnButtonWindowResetLayout()
{
    theApp.CleanSlate();

    CRect rcInputsOutputs(0, 0, 400, 50);
    m_wndPaneInputsOutputs.DockToFrameWindow(CBRS_ALIGN_RIGHT, rcInputsOutputs, DT_DOCK_LAST, NULL, -1, FALSE);
    m_wndPaneInputsOutputs.ShowPane(TRUE);

    CRect rcDeviceStatus(0, 0, 600, 180);
    m_wndPaneDeviceStatus.DockToFrameWindow(CBRS_ALIGN_BOTTOM, rcDeviceStatus, DT_DOCK_LAST, NULL, -1, TRUE);
    m_wndPaneDeviceStatus.ShowPane(TRUE);

    CRect rcOutput(0, 0, 600, 70);
    m_wndOutput.DockToFrameWindow(CBRS_ALIGN_BOTTOM, rcOutput, DT_DOCK_LAST, NULL, -1, TRUE);
    m_wndOutput.ShowPane(TRUE);

    AdjustDockingLayout();
    SetWindowPos(&CWnd::wndTop, 0, 0, 900, 680, SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
}

Each pane class has the function:

void CPaneDialogEx::ShowPane(BOOL showPane)
{
    if (showPane != IsVisible()) {

       CMainFrame* pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetTopLevelFrame());

       if (pMainFrame != NULL) {
           pMainFrame->SetFocus();
           pMainFrame->ShowPane(this, showPane, FALSE, FALSE);
           pMainFrame->RecalcLayout();
       }
    }
}
0
votes

Yes, just delete the registry entry assigned with layout saving.