CImageButton - An advanced bitmap button control.
Although MFC’s CBitmapButton class is perfect most cases, I found some of it’s features needed some improvement. Fortunately Microsoft released a much more advanced version of CBitmapButton as a part of its WTL classes. I decided to take this as a basis for this MFC class and add some minor improvements like: button text, autoload and transparency.
Here’s a description of the class methods:
void SetBitmapButtonExtendedStyle(DWORD dwExtendedStyle, DWORD dwMask);
Set extended style of the bitmap button.
Available styles are:
BMPBTN_HOVER - when mouse is on top of the button, change to focus state.
BMPBTN_AUTO3D_SINGLE - - draws a single button border to resemble "classic" Windows buttons.
BMPBTN_AUTO3D_DOUBLE - draws a double button border to resemble "classic" Windows buttons.
BMPBTN_AUTOSIZE - autosize button to image size.
BMPBTN_SHAREIMAGELISTS - indicates that the button's internal image list is shared with other buttons.
BMPBTN_AUTOFIRE - autofire buttons repeat the button clicked message when they are held down.
HIMAGELIST SetImageList(HIMAGELIST hImageList);
Set the imagelist for the button. Returns the previous assigned imagelist.
BOOL SetToolTipText(LPCTSTR lpstrText);
Set the tooltip text for the button.
void SetImages(int nNormal, int nPushed, int nDisabled, int nFocusOrHover);
Set index (from imagelist) for the image for each button state.
void SetTextColor(COLORREF clrText);
Set color of button text.
BOOL AutoLoad(UINT nBitmapID, int nImageCount, int nBorderLeft, int nBorderTop, int nBorderRight, int nBorderBottom);
Automatically load button images and size them to button dimensions.
nBitmapID is resource ID of the bitmap with the button images.
nImageCount is where you specify how much images the bitmap resource contains.
nBorderLeft is the left border offset that may not be resized.
nBorderTop is the top border offset that may not be resized.
nBorderRight is the right border offset that may not be resized.
nBorderBottom is the bottomleft border offset that may not be resized.
Download example executable
Download source code
This class is part of the Pablo Software Solutions MFC Extension Package - Controls Edition