1

I've followed the steps from this question: Higher color depth for MFC toolbar icons?

The code works. But I have another problem - any disabled buttons are just grey boxes. Once they are enabled - they are exactly as they should be.

I suspect that the CToolBar doesn't know how to grey out the supplied images - can anyone help?

thanks in advance.

Community
  • 1
  • 1
anami
  • 152
  • 1
  • 7

2 Answers2

4

CToolBar actually accepts up to three imagelists each to handle the normal, disabled and highlighted states of the button.

To accomplish what I need - just normal and disabled button states. I need two images. One with normal coloured icons and the other with greyed out icons.

Add the images as Bitmap resources to your project - amend and make note of the IDs

Create two imagelists and set them accordingly: (m_wndToolBar is the toolbar in my project)

CImageList imgListActive;
CImageList imgListDisabled;
/* Load your CImageLists */
m_wndToolBar.GetToolBarCtrl().SetImageList(&imgListActive);
m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&imgListDisabled);

To set the highlighted versions of the toolbar:

CImageList imgListHighlighted;
/* Load your CImageList */
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imgListHighlighted);

et voila!

anami
  • 152
  • 1
  • 7
0

Usually two things are necessary to get the high color buttons and the correctly greyed out images:

  1. Always edit the .bmp file for the toolbar outside of VisualStudio.
  2. Add the images to MFC using a call to CMFCToolBar::AddToolBarForImageCollection(IDR_MAINFRAME); in your InitInstance() implementation.

Unfortunately this also means that you have to edit the Toolbar definition directly in the .rc resource file of the application.

Clemens
  • 1,744
  • 11
  • 20