EarthWeb
Where Wireless Technology & Business Intersect

Developer.com
Where Wireless Technology & Business Intersect
CodeGuru Sites
Visual C++/MFC
.NET (C# and more)
Visual Basic

Discussion Boards
Books on .NET
Book Reviews
Newsletters (subscribe)
Newsletters (archived)

Article Sections
C++
algorithms & formulas
c++ & mfc
date & time
string
COM-based Technologies
atl & wtl
com & activex
com+
shell programming
Controls
button control
combobox
edit control
imagelist control
listbox control
listview control
menu
other controls
property sheet
rich edit control
static control
status bar
toolbar
treeview control
Data
database
miscellaneous
Frameworks
ui & printing frameworks
Graphics & Multimedia
bitmaps & palettes
directx
gdi
multimedia
opengl
Internet & Networking
ie programming
internet protocols
isapi
network protocols
Miscellaneous
miscellaneous
Visual Studio
debugging
add-ins & macros
editor tips
Windows Programming
ce
clipboard
dll
file & folder
help systems
printing
win32
system
Windows & Dialogs
console
dialog
docking window
doc/view
splitter
Interact
Newsletters
Guestbook
Recommend Us!
About Us

[Internet Jobs]
   

CXPStyleButtonST v1.0

Windows XP buttons with all CButtonST features

This article was contributed by Davide Calabro'.

Sample Image Sample Image

SoftechSoftware homepage
SoftechSoftware Email

Environment: VC++ 6.0, XP, Win2k, NT 4.0, Win9x/ME

Abstract

CXPStyleButtonST is a scalable CButtonST-derived control.
If running under Windows XP the application buttons will be skinned using the current selected theme (if any), while if running under Windows 9x/ME/NT/2000 the buttons will have the standard, well known CButtonST flat style. In both cases all CButtonST features are granted! Using CXPStyleButtonST, with a zero-cost implementation, your applications running under XP will have the new, smooth and elegant style but also will run error-less under old Windows versions.

How to integrate CXPStyleButtonST in your application

In your project include the following files:

  • BtnST.h
  • BtnST.cpp
  • XPStyleButtonST.h
  • XPStyleButtonST.cpp
  • ThemeHelperST.h
  • ThemeHelperST.cpp
Create a instance of CThemeHelperST. This class encapsulates all the required APIs to access the current selected theme (if any) or to run error-less if none is selected or if running under a old Windows version. You need only one instance for all the buttons, so this can be global to the application or only to the current dialog.

CThemeHelperST m_ThemeHelper;

Create a CXPStyleButtonST object statically

With dialog editor create a standard button called, for example, IDOK (you don't need to make it owner drawn) and create a member variable for this button:

CXPStyleButtonST m_btnOk;

Now attach the button to CXPStyleButtonST. For dialog-based applications, in your OnInitDialog:

// Call the base-class method
CDialog::OnInitDialog();

// Create the IDOK button
m_btnOk.SubclassDlgItem(IDOK, this);

Or in your DoDataExchange:

// Call the base method
CDialog::DoDataExchange(pDX);

// Create the IDOK button
DDX_Control(pDX, IDOK, m_btnOk);

Assign the CThemeHelperST instance to the button. This is fundamental or your button will not have the current theme style even if running under XP !

In your OnInitDialog:

// Assign theme helper instance to the button
m_btnOk.SetThemeHelper(&m_ThemeHelper);

Create a CXPStyleButtonST object dynamically

In your application, create a member variable for the button. Please note that this variable is a pointer:

CXPStyleButtonST* m_pbtnOk;

Now create the button. For dialog-based applications, in your OnInitDialog:

// Call the base-class method
CDialog::OnInitDialog();

// Create the IDOK button
m_pbtnOk = new CXPStyleButtonST;
m_pbtnOk->Create(_T("&Ok"), 
                    WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP,
					CRect(10, 10, 200, 100), 
					this, 
					IDOK);
// Set the same font of the application
m_pbtnOk->SetFont(GetFont());

Assign the CThemeHelperST instance to the button as described in the previous section.

Remember to destroy the button or you will get a memory leak. This can be done, for example, in your class destructor:

if (m_pbtnOk) delete m_pbtnOk;

Class methods

SetThemeHelper
Assigns a CThemeHelperST instance to the button.

// Parameters:
//     [IN]   pTheme
//            Pointer to a CThemeHelperST instance.
//            Pass NULL to remove any previous instance.
//
void SetThemeHelper(CThemeHelperST* pTheme)

GetVersionI

Returns the class version as a short value.

// Return value:
//     Class version. Divide by 10 to get actual version.
//
static short GetVersionI()

GetVersionC

Returns the class version as a string value.

// Return value:
//     Pointer to a null-terminated string containing 
//     the class version.
//
static LPCTSTR GetVersionC()

Remarks

To compile CXPStyleButtonST you need the Platform SDK (August 2001 or newer). This is not mandatory because at compile-time, if not found, it will be emulated. At run-time you don't need any additional SDK or libraries installed.

History

  • Date Posted: January 22, 2002
    v1.0 (21/January/2002)
    First release

Credits

CThemeHelperST is based on the CVisualStylesXP code published by David Yuheng Zhao (yuheng_zhao@yahoo.com). Thanks very much!

Downloads

Download demo project - 106 Kb
Download source - 5 Kb

Comments:

Add Comment

Where Wireless Technology & Business Intersect

internet.commerce
 Be A Commerce Partner 
 Search the Web  
 Data Recovery  
 Send a Press Release  
 Send HTML Newsletters  
 Software Store  
 Get .SHOP Domains  
 Free Site Analysis  


Where Wireless Technology & Business Intersect
EarthWeb is a service of INT Media Group, Incorporated.
Copyright 2002 INT Media Group, Incorporated. All Rights Reserved.
Feedback,   Advertising Info,   Legal NoticesLicensing, Reprints, & Permissions,   Privacy Policy.
http://www.internet.com/