|
#ifndef __ImageUtil_h__
#define __ImageUtil_h__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error ImageUtil.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error ImageUtil.h requires atlwin.h to be included first
#endif
#ifndef __ATLGDI_H__
#error ImageUtil.h requires atlgdi.h to be included first
#endif
namespace ImageUtil
{
enum eCheckbox
{
eCheckboxUnchecked,
eCheckboxChecked,
eCheckboxIndeterminate,
eCheckboxLast
};
inline HBITMAP CreateCheckboxImage(HDC dcScreen,
eCheckbox checkState,
int cx, int cy,
COLORREF transparentColor,
HWND hWndControl = NULL)
{
#ifdef __ATLTHEME_H__
UINT stateDTB = CBS_CHECKEDNORMAL;
UINT stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_FLAT);
switch(checkState)
{
case eCheckboxUnchecked:
stateDTB = CBS_UNCHECKEDNORMAL;
stateDFC = (DFCS_BUTTONCHECK | DFCS_FLAT);
break;
case eCheckboxChecked:
stateDTB = CBS_CHECKEDNORMAL;
stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_FLAT);
break;
case eCheckboxIndeterminate:
stateDTB = CBS_MIXEDNORMAL;
stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE | DFCS_FLAT);
break;
}
#else
UINT stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_FLAT);
switch(checkState)
{
case eCheckboxUnchecked:
stateDFC = (DFCS_BUTTONCHECK | DFCS_FLAT);
break;
case eCheckboxChecked:
stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_FLAT);
break;
case eCheckboxIndeterminate:
stateDFC = (DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE | DFCS_FLAT);
break;
}
#endif
HBITMAP bitmap = NULL;
WTL::CDC dc;
dc.CreateCompatibleDC(dcScreen);
if(!dc.IsNull())
{
RECT rcImage = {0,0,cx,cy};
bitmap = ::CreateCompatibleBitmap(dcScreen, cx, cy);
WTL::CBitmapHandle hOldBitmap = dc.SelectBitmap(bitmap);
dc.FillSolidRect(&rcImage, transparentColor);
::InflateRect(&rcImage, -1, -1);
#ifdef __ATLTHEME_H__
WTL::CTheme theme;
if(theme.OpenThemeData(hWndControl, L"Button"))
{
theme.DrawThemeBackground(dc, BP_CHECKBOX, stateDTB, &rcImage);
theme.CloseThemeData();
}
else
{
dc.DrawFrameControl(&rcImage, DFC_BUTTON, stateDFC);
}
#else
dc.DrawFrameControl(&rcImage, DFC_BUTTON, stateDFC);
#endif
dc.SelectBitmap(hOldBitmap);
}
return bitmap;
}
};
#endif //__ImageUtil_h__
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
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
Daniel Bowen used to work as a Software Engineer for Evans & Sutherland in Salt Lake City, Utah working on the modeling tools for high end flight simulators. He then worked for the startup company WiLife Inc. in Draper, Utah working on the software portion of an easy to use and affordable digital video surveillance system. WiLife Inc. is now part of Logitech Inc.