views:

506

answers:

2

I have a CMFCToolBar-derived class and an insance thereof is the member of a CDockablePane-derived class.

I looked at the VisualStudioDemo sample to see how it's done and have this so far:

int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    // Removed all "return -1 on error" code for better readability

    CDockablePane::OnCreate(lpCreateStruct);

    if(m_toolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_MY_TOOLBAR) &&
       m_toolBar.LoadToolBar(IDR_MY_TOOLBAR, 0, 0, TRUE /* Is locked */))
    {

        if(theApp.m_bHiColorIcons) // Is true, i.e. following code is executed
        {
            m_toolBar.CleanUpLockedImages();
            m_toolBar.LoadBitmap(IDB_MY_TOOLBAR_24, 0, 0, TRUE /*Locked*/);
        }

        m_toolBar.SetPaneStyle(m_toolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
        m_toolBar.SetPaneStyle(m_toolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));

        m_toolBar.SetOwner(this);

        // All commands will be routed via this control , not via the parent frame:
        m_toolBar.SetRouteCommandsViaFrame(FALSE);
    }

    return 0;
}

The high-color image (24bit) is loaded but the magenta mask (R255 G0 B255) is visible. I don't see how I can tell the toolbar to recognize the mask.
Is this even possible?

A: 

I just found out that a workaround is to use 32bit images together with their alpha channel. I tried using a 32bit image earlier but didn't get it to work for some other reason and then figured 32bit images won't work.

mxp
+3  A: 

I don't know if this works every time but I use RGB(192, 192, 192) as the mask color and it does get recognized.

(Seems like the CMFCToolBar control is prepared to use ::GetSysColor(COLOR_BTNFACE) as the transparent color...)

djeidot
Accepting this as answer because this may be the solution for 24bit images, which is what the question is about. Although my solution is different, this may help others that must use 24bit images.
mxp
I admit it is not the perfect solution. Once the user changes the button face color the transparency will probably go away.
djeidot