CShadeButtonST - A CxShadeButton made using CButtonST

Sample Image

Environment: VC6 SP4, NT4, Win2000, Win9x

Abstract

These are days where almost everything can be skinned or customized. If you have taken a look at Windows XP you will have noticed that even buttons can have a look far away from what we know. Even if I don't like hard customizations very much, I've noticed how much people liked a button control called CxShadeButton posted by Davide Pizzolato. The idea I have is to make available one or two virtual functions from CButtonST, the reference control for MFC flat buttons, to let the developer 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 a class from CButtonST then implements these two functions in the 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.

Downloads

Download demo project - 682 Kb
Download source - 10 Kb


Comments

  • Tooltips not working

    Posted by stevefr on 01/04/2007 01:14pm

    I can not get tooltips to work for the buttons Anyone have any idea to get tooltips to work. Calling the ActivateTooltip() method for a button does not work. I am running the code compiled in Net 2003

    Reply
  • problem when hosted inside ATL composite controls

    Posted by Legacy on 11/26/2002 12:00am

    Originally posted by: Derradji Rachid

    Reply
  • Need Help

    Posted by Legacy on 10/03/2002 12:00am

    Originally posted by: Jeremy

    Hi, I've downloaded the button control that you created and i found it very useful. And there is one thing i think u might be able to help, which is How to Make a Static Label transparent with the background? From the files, I learnt how to make a Button transparent, but what about the Static Label? I would be glad if you could tell me the solution. Thanks.

    Reply
  • Flicker problem

    Posted by Legacy on 09/17/2001 12:00am

    Originally posted by: John

    Nice piece of work... but again... will the flicker problem be attended to?

    Reply
  • problem in CButtonST maybe ?

    Posted by Legacy on 09/11/2001 12:00am

    Originally posted by: rojo

    I had trouble with CButtonST, it would use up all
    my resources after a while, anybody had same problems ?!

    Reply
  • There is a bug!

    Posted by Legacy on 07/23/2001 12:00am

    Originally posted by: Dimka

    When I work with this buttons for a long time, they stops answer!

    Reply
  • Really Superb!

    Posted by Legacy on 07/22/2001 12:00am

    Originally posted by: Suria

    Really Superb!

    Reply
  • Great Job, thanks !!!

    Posted by Legacy on 07/11/2001 12:00am

    Originally posted by: Adrian

    Fantastic !!!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 18, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT While the idea of using facial and or gesture recognitions to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development. There are many different ways in which Intel and Unity Technologies have been working together to helps speed the develop of games with the Intel® RealSense™ SDK (Software Developer Kit), so come hear from a panel of experts on what we've done …

  • Live Event Date: May 6, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT Where are you in your plans to adopt Disaster Recovery-as-a-Service? Are you just getting started? Fighting an uphill battle with management? At Cisco, Zerto and iland, we've seen it all – from the early adopters who excitedly rushed to implement DRaaS with us nine years ago to the IT folks dragging their business leaders into the future. With our years of experience, we've learned there are six types of DRaaS leaders – but which type …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date