goodking
goodking

Reputation: 145

How to change CMFCToolBar runtime

I need under certain conditions to switch toolbars in my SDI application using the same CMFCToolBar object, which is the member of CMainFrame. I'm trying to do it like this:

void CMainFrame::ChangeTlbr(const int tlbIdx)
{
    m_wndToolBar.ResetImages();
    switch (tlbIdx)
    {
        case 0 :

            m_wndToolBar.LoadToolBar(IDR_TLBR1);

            break;
        case 1:

            m_wndToolBar.LoadToolBar(IDR_TLBR2);

            break;
    }

    m_wndToolBar.Invalidate();
    m_wndToolBar.UpdateWindow();
}

But bitmap of the next toolbar is not loaded.

What am i doing wrong in this case, and if there is better way to do this?

Upvotes: 2

Views: 1247

Answers (2)

Victor
Victor

Reputation: 8925

The following function shows how to replace the current toolbar by another one, defined as IDR_MAINFRAME1:

void CMainFrame::OnChangeToolbar()
{    
    m_wndToolBar.ResetAllImages();
    m_wndToolBar.LoadToolBar(IDR_MAINFRAME1);
    m_wndToolBar.LoadBitmap(IDR_MAINFRAME1);
    m_wndToolBar.AdjustSizeImmediate();        
}

Upvotes: 3

IInspectable
IInspectable

Reputation: 51414

You aren't passing the required resource IDs of the bitmaps to be loaded in your call to CMFCToolBar::LoadToolBar:

uiColdResID
The resource ID of the bitmap that refers to the cold toolbar images.

uiMenuResID
The resource ID of the bitmap that refers to the regular menu images.

uiDisabledResID
The resource ID of the bitmap that refers to the disabled toolbar images.

uiMenuDisabledResID
The resource ID of the bitmap that refers to the disabled menu images.

uiHotResID
The resource ID of the bitmap that refers to the hot toolbar images.

At the very least you need to specify uiHotResID. If you do not want (or have) images for the other parameters, you can call CMFCToolBar::LoadBitmap instead. A final call to CMFCToolBar::AdjustLayout recalculates the controls size and position.

Upvotes: 2

Related Questions