CShadeButtonST - A CxShadeButton made using CButtonST | CodeGuru

CShadeButtonST – A CxShadeButton made using CButtonST

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 11, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

Advertisement

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


CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.