![]() |
Desktop Development »
Button Controls »
General
Intermediate
License: The Code Project Open License (CPOL)
CreateCheckboxImageList - a non-MFC function to create an imagelist of themed checkboxesBy Hans DietrichCreateCheckboxImageList is a function that creates an imagelist of themed or non-themed checkboxes, suitable for use in tree controls, list controls, and list boxes. |
C++ (VC6, VC8.0), Windows, Visual Studio (VS2005), Dev
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
//============================================================================= // // CreateCheckboxImageList() // // Purpose: Create themed checkbox image list // // Parameters: hDC - device context for drawing // nSize - height and width of images // crBackground - fill color // bUseVisualThemes - TRUE = use themes if enabled // // Returns: HIMAGELIST - imagelist handle; NULL if create fails //The CreateCheckboxImageList function creates an imagelist of 16 images, as defined by this
enum:
enum { COLD_UNUSED_1 = 0, // 0000 COLD_UNCHECKED_NORMAL, // 0001 COLD_CHECKED_NORMAL, // 0010 COLD_TRISTATE_NORMAL, // 0011 COLD_UNUSED_2, // 0100 COLD_UNCHECKED_DISABLED, // 0101 COLD_CHECKED_DISABLED, // 0110 COLD_TRISTATE_DISABLED, // 0111 HOT_UNUSED_1, // 1000 HOT_UNCHECKED_NORMAL, // 1001 HOT_CHECKED_NORMAL, // 1010 HOT_TRISTATE_NORMAL, // 1011 HOT_UNUSED_2, // 1100 HOT_UNCHECKED_DISABLED, // 1101 HOT_CHECKED_DISABLED, // 1110 HOT_TRISTATE_DISABLED }; // 1111The first 8 images are "cold", the next 8 "hot". To switch from cold to hot, you can OR the state with 8. To switch from normal to disabled, you can OR the state with 4.
HIMAGELIST to a CImageList:
HIMAGELIST hil = 0; hil = HDCheckboxImageList::CreateCheckboxImageList(pDC->m_hDC, 16, GetSysColor(COLOR_WINDOW), TRUE); CImageList imagelist; // usually this will be class variable imagelist.Attach(hil);
To integrate CreateCheckboxImageList into your app, you first need to add following files to your project:
The .cpp file should be set to Not using precompiled header in Visual Studio. Otherwise, you will get error
fatal error C1010: unexpected end of file while looking for precompiled header directive
OnInitDialog or other initialization routine,
add code to create imagelist, and then draw appropriate image in
DrawItem() or OnPaint() function.
This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Apr 2008 Editor: |
Copyright 2008 by Hans Dietrich Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |