Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

High color icons for CPropertySheet

0.00/5 (No votes)
26 Feb 2004 1  
Upgrading CPropertySheet tab control to display high color icons.

Sample Image - HighColorTab.png

Introduction

I wanted to add icons on property pages for my current project. After selecting a few icons, that happened to be in 24 bits, and upgrading my application, I had the unpleasant surprise of seeing that the icons were displayed in only 16 colors.

I checked the Microsoft Knowledge Base and looked around for articles on the web discussing this issue but with no success. After investigating a little bit with CPropertySheet and its dependencies CTabCtrl and CImageList, I came up with the solution presented in this article.

Also note that the solution provided works with the excellent CTreePropSheet[^] control, which is what I was actually using.

Using the code

Using the code is very straightforward. You have to create a new class derived from CPropertySheet in order to override OnInitDialog. Include "HighColorTab.hpp" into the .cpp file of your new property sheet. In the body of OnInitDialog, add the following line:

HighColorTab::UpdateImageList( *this );

That's it: you are done! The demo project provides an example.

How does it work?

The code is pretty straightforward and is located in a single function in HighColorTab.hpp. The function does the following:

  • Get the tab control (CTabCtrl) from the provided property sheet (or object having a similar interface),
  • Create the replacement image list (CImageList) using the provided trait,
  • Populate the image list using the icon information stored in each property page,
  • Replace the image list,
  • Destroy the old image list.

The workflow is such that if anything goes wrong during the image list creation process, the property sheet remains unchanged.

The image list to be used can be customized via the trait provided to UpdateImageListFull. The trait must implement a method with the following signature:

static std::auto_ptr<CImageList> CreateImageList();

UpdateImageList uses a default trait that creates an image list with ILC_COLOR32. Do not forget to set ILC_MASK too or you will end up with a black background for the icons.

History

  • 02/27/2004, Initial release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here