tomascz
tomascz

Reputation: 245

MFC: How to save the position of toolbars in the legacy MFC ver 6?

I have a striking question: How to save the position of toolbars in the legacy MFC ver 6?

I can't use CWinApp::SaveBarState because not all toolbars exist at the moment this function would be called (causing it to assert). Instead, I instantiate the toolbars depending on what kind of document is loaded. I unfortunately yet didn't find my way with CToolBarCtrl::SaveState which would be ideal to use, I guess. However, when playing with it, I'm experiencing two problems:

Any helping hand appreciated, many thanks!

Regards,

Tomas

Upvotes: 0

Views: 776

Answers (1)

thomiel
thomiel

Reputation: 2937

Before switching to the ribbon, I used this funcion from this CodeProject article to arrange my toolbars:

void CMainFrame::DockControlBarLeftOf(CToolBar* Bar, CToolBar* LeftOf)
{
    CRect rect;
    DWORD dw;
    UINT n;

    // get MFC to adjust the dimensions of all docked ToolBars
    // so that GetWindowRect will be accurate
    RecalcLayout(TRUE);

    LeftOf->GetWindowRect(&rect);
    rect.OffsetRect(1,0);
    dw=LeftOf->GetBarStyle();
    n = 0;
    n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
    n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
    n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
    n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;

    // When we take the default parameters on rect, DockControlBar will dock
    // each Toolbar on a seperate line. By calculating a rectangle, we
    // are simulating a Toolbar being dragged to that location and docked.
    DockControlBar(Bar,n,&rect);
}

I'm sure, you can use this easily for your save and load code to restore toolbars.

Upvotes: 1

Related Questions