The Code Project View our sponsorsClick here for Dundas Software's TCP/IP Development KitAdvertise on the CodeProject
Home >> Button Controls >> Owner-draw buttons

CxShadeButton
By Davide Pizzolato

An owner-drawn button class that gives a professional look to your buttons. 
 VC 4-6, Win95-98, NT4, W2K, MFC
 Posted 18 May 2001
 Updated 5 Jun 2001
Articles by this author
Send to a friend
Printer friendly version
Lounge New Articles Sign in Forums Contribute
Broken links? Email us!
29 users have rated this article. result:
4.97 out of 5.

Sample Image - sample.gif

Introduction

With this class you can easily give a professional look to your buttons in a few steps. No resources are needed - all bitmaps are generated at runtime. Parts of the code come from the CxSkinButton article.

  1. Add "xShadeButton.cpp" and "xShadeButton.h" to the project.
  2. Include "xShadeButton.h" in the header file where the controls are defined
  3. Create (or edit) a member variable for each button you want to customize as CxShadeButton. If the Class Wizard doesn't show the CxShadeButton type, select CButton and then edit the code manually.
  4. In the window initialization add the CxShadeButton methods:
    BOOL CxShadeButtonDemoDlg::OnInitDialog()
    {
    	//	...
    	m_btn1.SetTextColor(RGB(255,0,0));
    	m_btn1.SetToolTipText("Button1");
    	m_btn1.SetShade(SHS_DIAGSHADE,8,10,5,RGB(55,255,55));
    //	...
    

CxShadeButton Class Members & Operations

CxShadeButton is derived from CButton. CxShadeButton uses 6 member functions to tune the button appearance.
The BS_OWNERDRAW style is added automatically, you don't need to set the "Owner draw" property in the resource editor.
void SetShade(UINT shadeID=0,BYTE granularity=8,BYTE highlight=10,BYTE coloring=0,COLORREF color=0);
void SetToolTipText(CString s);
COLORREF SetTextColor(COLORREF new_color);
void SetIcon(UINT nIcon, UINT nIconAlign=BS_CENTER);
void SetTextAlign(UINT nTextAlign=BS_CENTER);
void SetFlat(bool bFlag);

Release History

v1.00 - 12/05/2001

basic implementation and interface.

v1.10 - 23/05/2001

added text shift on button down.
fixed many CxDib bugs.
fixed SHS_HARDBUMP bug.
added icon support.
added text alignment.
added flat style.

Compatibility

Win95,WinNT = Yes, requires IE3.0 or higher
Win98, WinME, W2K, WinXP = Yes

For any questions, e-mail to: ing.davide.pizzolato@libero.it

Thanks to all the Code Project developers!
Special thanks to:
Milan Gardian for mouse and keyboard tracking code.
Andre Brogli, Richard Cunday, Shanker Chandrabose,
Luis, Rainer Mangold, Gilad, Rui Lopes, Tom Archer for suggestions, debugging & support.

[Top] Sign in to vote for this article:     PoorExcellent  
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
 Keyword Filter
 View   Per page   Messages since
New threadMessages 1 to 21 of 21 (Total: 21)First Prev Next Last
Subject 
Author 
Date 
  & (underscore character) problem
Davide Pizzolato 9:43 10 Jun 01 
  Flicker during mouse moves
Jeremy Davis 7:54 7 Jun 01 
  Fix for offcenter text
Robert Prouse 1:08 28 May 01 
  Re: Fixed in release 1.10
Davide Pizzolato 2:15 7 Jun 01 
  Can a dialog be skinned like this?
Keijo Paananen 9:36 24 May 01 
  Re: Can a dialog be skinned like this?
Robert Prouse 0:57 28 May 01 
  Little things
George 6:25 24 May 01 
  Another Improvement?
Richard Cunday 18:22 21 May 01 
  Re: Another Improvement?
Richard Cunday 10:16 22 May 01 
  A Tiny Improvement
Gilad 3:43 20 May 01 
  Heap Problems
Rainer Mangold 4:14 19 May 01 
  Re: Heap Problems
Rainer Mangold 9:51 20 May 01 
  Re: Heap Problems
Anonymous 11:08 20 May 01 
  Re: Heap Problems
Andre Brogli 8:22 21 May 01 
  Re: Heap Problems (corrected)
Andre Brogli 8:47 21 May 01 
  Re: Heap Problems fixed in release 1.10 (FINAL, I hope)
Davide Pizzolato 13:42 21 May 01 
  GDI+ ?
Anonymous 14:23 18 May 01 
  Re: GDI+ ?
Christian Graus 5:54 19 May 01 
  Impressive!
Rui Lopes 11:04 18 May 01 
  Incredible!
Tom Archer 5:40 18 May 01 
  Re: Incredible!
Shanker Chandrabose 21:11 21 May 01 
Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

Home >> Button Controls >> Owner-draw buttons
last updated 5 Jun 2001
Article content copyright Davide Pizzolato, 2001
everything else © CodeProject, 1999-2001.
The Code Project View our sponsorsClick here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASPAdvertise on the CodeProject