With this class you can easily give a skin to your buttons in few steps:
- Add xSkinButton.cpp and xSkinButton.h to the project.
- Include xSkinButton.h in the header file where the controls are defined
- Create (or edit) a member variable for each button you want to customize as
CxSkinButton. If the Class Wizard doesn't show the
CxSkinButton type, select
CButton and then edit the code manually.
- Add the bitmap resource for the buttons:
- NORMAL bitmap: default button image.
- DOWN bitmap: pushed button image.
- OVER bitmap:(optional) image to shown when the mouse is over the button. If NULL, NORMAL bitmap will be used.
- DISABLED bitmap: (optional) image for the disabled state. If NULL, NORMAL bitmap will be used.
- FOCUS bitmap: (optional) image for the focused state. If NULL, NORMAL bitmap will be used.
- MASK bitmap: (optional) clipping region. If you don't use the MASK, the button will be a rectangular owner-draw control. The default transparent color is RGB(255,255,255).
- In the window initialization add the
SetToolTipText are self explaining;
void CxSkinButton::SetSkin(UINT normal,UINT down,UINT over,
UINT disabled, UINT focus,UINT mask,
short drawmode, short border,
- normal, down, over, disabled, focus, mask = bitmap resource IDs
- drawmode = if mask is not NULL, this should be 0 (normal); else you can try 1 (stretch) or 2 (tiled).
- border = if mask is not NULL or is not rectangular, this should be 0; else you can try 1 to draw the standard 3D border around the button.
- margin = if mask is not NULL or is not rectangular, this should be 0; else you can try to change this value to draw a dotted rectangle over the button when the control has the focus.
- The BS_OWNERDRAW style is added automatically, you don't need to set the "Owner draw" property in the resource editor.
- only NORMAL and DOWN bitmaps are essential; OVER bitmap is a plus.
- DISABLED bitmap is not necessary if the button is always enabled. You can also use the button text (automatically etched) to show the disabled state.
- MASK bitmap is not necessary if the button is rectangular.
- for rectangular buttons you should set the margin parameter greater than 0 (4 is a good choice), or use the FOCUS bitmap.
- for rectangular buttons you can use 'flat' bitmaps and set the border parameter to 1. In this situation, NORMAL and DOWN bitmaps can also share the same resource.
v1.00 - 15/03/2001
- basic implementation and interface.
v1.10 - 28/03/2001
enhanced mouse tracking implementation (by Milan Gardian).
SetCapture removed: accelerators now are dispatched.
- Double-click handling.
- Better behavior during "button-pressed" (mouse button down & holding) phase
v1.20 - 02/04/2001
CreateRgnFromBitmap() implementation. Mask bitmap now works in any display color mode, any mask color depth and any mask size.
v1.21 - 14/04/2001
OnMouseLeave cast error fixed.
FocusRect defect when OVER bitmap was NULL.
v1.30 - 25/04/2001
- Fixed CreateRgnFromBitmap failure under WinNT4.0
v1.40 - 29/06/2001
- check & radio button add on.
- added "focus" bitmap.
- fixed CreateRgnFromBitmap bug.
- fixed shortcut bug.
- fixed text drawing code.
v1.41 - 27/10/2001
- Fixed memory leakage in
v1.50 - 07/07/2008
- fixed memory leaks using
GetDC (thanks to sachelis and Bernd Giesen)
SetToolTipColor (thanks to Mykel)
Win95,WinNT = Yes, requires IE3.0 or higher
Win98, WinME, W2k, WinXP = Yes
Thanks to all the Code Project developers!
Special thanks to:
Milan Gardian for mouse and keyboard tracking code.
Fable(at)aramszu(dot)net for ExtCreateRegion replacement code.
Rainer Mangold for radio-button and check-box code.
Andy Green and Cameron Epp for suggestions & debugging.