Click here to Skip to main content
Licence 
First Posted 25 Jun 2001
Views 147,864
Bookmarked 46 times

CShadeButtonST

By | 25 Jun 2001 | Article
A Shaded Button made using CButtonST

Sample Image - cshadebuttonst.jpg

Abstract

These are days where almost everything can be skinned or customized.
If you have taken a look at the new Windows XP you will have noticed that even buttons can have a look far away from that we know.

Even if I don't like very much hard customizations I've noticed how much people liked a button control called CxShadeButton posted by Davide Pizzolato. The idea I've got is to make available one or two virtual functions from CButtonST, the reference control for MFC flat buttons, to let the developer to derive his own class and implement custom background paint still having all the features from the CButtonST control.
To show this new feature I've decided to reproduce the look and feel of CxShadeButton. I've extracted from the original code the class called CxDib and the code that creates and draws the background effects.

All credits for this code snippets go to Davide Pizzolato.

Virtual functions

CButtonST makes available two virtual functions.

OnDrawBackground

This function is called every time the button background needs to be painted.
If the button is in transparent mode this function will NOT be called.

// Parameters:
//        [IN]    pDC
//                Pointer to a CDC object that indicates the device context.
//        [IN]    pRect
//                Pointer to a CRect object that indicates the bounds of the
//                area to be painted.
//
// Return value:
//        BTNST_OK
//               Function executed successfully.
//
DWORD OnDrawBackground(CDC* pDC, LPCRECT pRect)

OnDrawBorder

This function is called every time the button border needs to be painted.
If the button is in standard (not flat) mode this function will NOT be called.

// Parameters:
//        [IN]    pDC
//                Pointer to a CDC object that indicates the device context.
//        [IN]    pRect
//                Pointer to a CRect object that indicates the bounds of the
//                area to be painted.
//
// Return value:
//        BTNST_OK
//               Function executed successfully.
//
DWORD OnDrawBorder(CDC* pDC, LPCRECT pRect)

The developer derives his own class from CButtonST then implements these two functions in his new class.

Example

The CButtonST demo application includes a page that shows how to implement new effects. A class called CShadeButtonST has been derived from CButtonST and the new effects has been implemented mainly in the OnDrawBackground method.

Remarks

This architecture makes possible to produce a whole range of buttons not available by default. If someone implements the look and feel of the new buttons found in Windows XP I will happy to include his code in the next CButtonST demo application.

License

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

About the Author

Davide Calabro

Web Developer

Italy Italy

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalabout transparent button Pinsussleo peng19:40 17 Nov '03  
GeneralFlickering PinsussAnonymous3:03 18 Jul '02  
GeneralRe: Flickering PinmemberDavide Calabro3:18 18 Jul '02  
Anonymous wrote:
Any idea?????????
 
Yes, do not use 100 buttons! What kind application of application needs
more than 100 buttons on the same window Confused | :confused:
To avoid flickering a solution might be to implement the CMemDC class
done by Keith Rule.
 
Cheers,
 
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://www.softechsoftware.it
Questionhi Calabro, now, how to make other transparent icons/bitmaps ? Pinmemberlimona23:12 3 Jul '02  
AnswerRe: hi Calabro, now, how to make other transparent icons/bitmaps ? PinmemberDavide Calabro23:31 3 Jul '02  
GeneralERROR : Low user and system resource PinmemberCris3:54 2 May '02  
GeneralPlease, take care when reading articles PinmemberDavide Calabro4:29 2 May '02  
Generalu just copied clit ! PinmemberAnonymous2:43 23 Feb '02  
GeneralRe: ??? PinmemberDavide Calabro4:25 2 May '02  
GeneralRe: Resource Leak PinmemberDavide Calabro22:36 28 Aug '01  
Generalcheckbox problem... PinmemberMario M.3:40 1 Jul '01  
GeneralRe: checkbox problem... PinmemberDavide Calabro21:55 3 Jul '01  
GeneralRe: checkbox problem... PinmemberMario M.5:21 4 Jul '01  
GeneralInfact, you can't use UpdateData PinmemberDavide Calabro7:22 4 Jul '01  
GeneralRe: Infact, you can't use UpdateData PinmemberMario M.7:32 4 Jul '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 26 Jun 2001
Article Copyright 2001 by Davide Calabro
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid