Click here to Skip to main content
11,413,961 members (76,609 online)
Click here to Skip to main content

XP-style Button Control

, 6 Aug 2002
Rate this:
Please Sign up or sign in to vote.
XP style button control for all version of windows.

Sample Image

Introduction

Here is an XP-style Button. It works on all windows OSs: 95/98/Me/NT/W2K/XP. No subclassing etc is needed to use this control - it's just a plain simple button control.  This code is a modified form of the OCX code I recently saw on codeguru. The button code was for an ActiveX control. I created this CButton derived class with latest Microsoft's sponsored CCP technology (Cut-Copy-Paste).

How to use it?

  • In you resource editor create a button and set the 'owner draw' property.
  • Use classwizard to create a CButton object in your dialog.
  • Include the "xpbutton.h" file in your dialog class file.
  • Rename the CButton object type to CXPButton.
  • Compile and enjoy.

Please visit My Web Site for more tutorials, tweaks, reference.

History

7 Aug 2002 - updated download

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

Share

About the Author

Shrishail Rana

United States United States
No Biography provided

Comments and Discussions

 
QuestionProblems compiling with VS2012 Pin
merano, 21-Apr-13 6:33
membermerano21-Apr-13 6:33 
AnswerRe: Problems compiling with VS2012 Pin
VincyChan, 21-Dec-14 16:10
memberVincyChan21-Dec-14 16:10 
QuestionWhat about the non rounded frame around the button? Pin
agua2, 8-Apr-09 11:57
memberagua28-Apr-09 11:57 
Generalgreat work Pin
ansif_pi, 29-Jul-08 0:53
memberansif_pi29-Jul-08 0:53 
Generalapologies Pin
MKMA, 23-Nov-07 4:37
memberMKMA23-Nov-07 4:37 
Generalproblem if init dialog is used Pin
MKMA, 23-Nov-07 4:22
memberMKMA23-Nov-07 4:22 
QuestionWho has the CXPEdit? Pin
aimar266, 23-Apr-06 5:10
memberaimar26623-Apr-06 5:10 
GeneralNice Pin
Alton Williams, 29-Jun-05 4:21
memberAlton Williams29-Jun-05 4:21 
GeneralToolTips Pin
paramecula, 16-Mar-05 3:19
memberparamecula16-Mar-05 3:19 
Generallittle bug Pin
Harbor Hu, 3-Mar-05 20:39
sussHarbor Hu3-Mar-05 20:39 
GeneralRe: little bug Pin
ladydi99, 12-Apr-05 22:09
memberladydi9912-Apr-05 22:09 
GeneralRe: little bug Pin
vjairam, 1-Jun-05 12:11
membervjairam1-Jun-05 12:11 
QuestionWhat bout other Controls... Pin
Manoj Singh K, 18-Jan-05 20:18
memberManoj Singh K18-Jan-05 20:18 
GeneralInvisible Pin
fl0at, 4-Jul-04 8:24
memberfl0at4-Jul-04 8:24 
GeneralFix For Font example, chinese. Pin
anonymousafsdfasd, 15-May-04 4:58
sussanonymousafsdfasd15-May-04 4:58 
GeneralFix For Font example, chinese. Pin
anonymous, 15-May-04 4:58
sussanonymous15-May-04 4:58 
GeneralLittle BUG fix Pin
Ivo Wubbels, 23-Apr-04 2:31
memberIvo Wubbels23-Apr-04 2:31 
I found a little bug in this control; here's what I changed:
1) i did not want the BOLD font, so used another font, but that's personal...
2) if you use '&Ok' to underline the O of 'Ok', it works okay for disabled buttons, not for enabled. This code fixes that bug.

Ivo


// Draw the text
if (!m_title.IsEmpty()/*!strText.IsEmpty()*/)
{
CFont *oldFont=(CFont*)pDC->SelectStockObject(DEFAULT_GUI_FONT);
CString displayName=m_title;

displayName.Remove('&');
CSize Extent = pDC->GetTextExtent(displayName/*strText*/);
CPoint pt( rect.CenterPoint().x - Extent.cx/2,
rect.CenterPoint().y - Extent.cy/2 );

if (state & ODS_SELECTED)
pt.Offset(1,1);

int nMode = pDC->SetBkMode(TRANSPARENT);
//pOldPen = pDC->SelectObject(pBoundryPen);
//CFont *pOldFont = SelectStockFont( pDC );

if (state & ODS_DISABLED)
pDC->DrawState(pt, Extent, m_title/*strCaption*/, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
else
pDC->DrawState(pt, Extent, m_title/*strCaption*/, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
//pDC->TextOut(pt.x, pt.y, m_title/*strCaption*/);
//pDC->SelectObject(pOldPen);
//pDC->SelectObject(pOldFont);
pDC->SetBkMode(nMode);

pDC->SelectObject(oldFont);
}
Generalnice going. Pin
t2di4u, 28-Jan-04 20:11
membert2di4u28-Jan-04 20:11 
GeneralWhy there is no XP-style Edit Pin
whizzkid@ms28.hinet.net, 16-Dec-03 14:44
memberwhizzkid@ms28.hinet.net16-Dec-03 14:44 
QuestionHow can I set the button colors? Pin
Bobboots, 22-Aug-03 11:36
memberBobboots22-Aug-03 11:36 
Generalhwo can i set icon Pin
liquidsnake183, 29-Apr-03 9:28
memberliquidsnake18329-Apr-03 9:28 
QuestionWhat about xp titlebar? Pin
anon123, 1-Mar-03 11:46
memberanon1231-Mar-03 11:46 
QuestionHow can I get change the font on the CXPButton? Pin
Jaltair, 13-Feb-03 15:58
memberJaltair13-Feb-03 15:58 
AnswerRe: How can I get change the font on the CXPButton? Pin
Jeremy Davis, 14-Feb-03 1:51
memberJeremy Davis14-Feb-03 1:51 
GeneralRe: How can I get change the font on the CXPButton? Pin
Jaltair, 18-Feb-03 7:04
memberJaltair18-Feb-03 7:04 
GeneralRe: How can I get change the font on the CXPButton? Pin
halka, 14-Sep-04 5:06
memberhalka14-Sep-04 5:06 
GeneralRe: How can I get change the font on the CXPButton? Pin
Jeremy Davis, 14-Sep-04 5:16
memberJeremy Davis14-Sep-04 5:16 
AnswerRe: How can I get change the font on the CXPButton? Pin
kbomb987, 13-Oct-05 9:06
memberkbomb98713-Oct-05 9:06 
GeneralUse with PropertySheet Pin
Tim Hodgson, 3-Feb-03 12:10
memberTim Hodgson3-Feb-03 12:10 
GeneralRe: Use with PropertySheet Pin
styx, 13-Feb-03 0:23
memberstyx13-Feb-03 0:23 
QuestionHow use it In Web Explorer Pin
Johnson Chen, 5-Oct-02 6:02
memberJohnson Chen5-Oct-02 6:02 
Generalvb.NET Pin
Jason78, 30-Jul-02 16:15
memberJason7830-Jul-02 16:15 
GeneralRe: vb.NET Pin
Mika, 7-Aug-02 23:09
memberMika7-Aug-02 23:09 
GeneralRe: vb.NET Pin
Mark Pappert, 25-Oct-02 7:58
sussMark Pappert25-Oct-02 7:58 
GeneralDemo Resource File Pin
MJ_Karas, 30-Jul-02 9:58
memberMJ_Karas30-Jul-02 9:58 
GeneralRe: Demo Resource File Pin
srana, 30-Jul-02 22:35
membersrana30-Jul-02 22:35 
QuestionWhat about MultiLine?? Pin
lion, 30-Jul-02 3:20
memberlion30-Jul-02 3:20 
AnswerRe: What about MultiLine?? Pin
srana11, 1-Aug-02 7:53
susssrana111-Aug-02 7:53 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150427.2 | Last Updated 7 Aug 2002
Article Copyright 2002 by Shrishail Rana
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid