Solved

In Visual C++ App, disabled toolbar buttons show as solid grey boxes

Posted on 2015-01-06
3
232 Views
Last Modified: 2015-01-07
I have a VC++ app created using VS2012.  In said app, I have a few toolbars.  When the toolbar images are enabled, the images on each toolbar button display nicely.  However, when a toolbar button is disabled (intentionally), the image(s) on the toolbar buttons display as a solid grey boxes, instead of as a greyed out (disabled) version of the original image.

Here's some more detail:

I am loading the images at run-time by using the following:

CToolBarCtrl& bar = m_wndMyToolBar.GetToolBarCtrl();      
CImageList *pList = bar.GetImageList();      

HICON hIconSomeImage = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_SOME_ENABLED_ICON));      
      
pList->Replace(0, hIconSomeImage);       
      
bar.SetImageList(pList);
m_wndMyToolBar.Invalidate();

This code works well to get the image to display when the toolbar button is enabled.

To solve the issue of the image being a solid grey box when the toolbar button is disabled, I tried creating an image list for disabled toolbar images, as follows:

CImageList m_imgListDisabled;
imgListDisabled.Create(16, 15, ILC_COLOR32, 8, 8);

HICON hIconTest = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_SOME_DISABLED_ICON));
      
m_imgListDisabled.Add(hIconTest);      
bar.SetDisabledImageList(&m_imgListDisabled);
m_wndMyToolBar.Invalidate();

The above code compiles, and runs without throwing any errors, yet the net result is a solid grey box instead of the disabled image.

I should add that the images I am using for the toolbar buttons are icon files (.ico files), and these icons have a high color depth.

Any help would be greatly appreciated.
0
Comment
Question by:cjm20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 40535206
CImageList m_imgListDisabled;
from your code snippet it looks like the m_imgListDisabled is a local variable (and not a member). if that is the case the object will be freed after scope and the pointer to the disabled image list was invalid as well. either make it a static variable or a member to solve the issue.

Sara
0
 

Author Comment

by:cjm20
ID: 40535542
Bingo!  Moving the image list to the member level fixed my issue. I can now see the correct disabled icon when i would expect to. Thanks very much, Sara!
0
 

Author Closing Comment

by:cjm20
ID: 40535543
My kind of solution: nice and simple :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question