Click here to Skip to main content
Click here to Skip to main content

XP-style Button Control

By , 6 Aug 2002
 

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

About the Author

Shrishail Rana
United States United States
Member
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionProblems compiling with VS2012membermerano21 Apr '13 - 5:33 
Can´t compile the Sample with VS2010.
 
Something seems to be wrong with ::~CMemDC
 
1>nafxcw.lib(afxglobals.obj) : error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) ist bereits in XPButton.obj definiert.
1>.\Release\xpbtn.exe : fatal error LNK1169: Mindestens ein mehrfach definiertes Symbol gefunden.
 
How to fix this ?
QuestionWhat about the non rounded frame around the button?memberagua28 Apr '09 - 10:57 
As was said before, when you use a non white color background, the round rectangle button drawn by this CXPButton class is stil visible in a non-rounded white rectangular frame...
Is there a way to handle that so that the frame is also rounded and XPstyle on such a different colored background?
Generalgreat workmemberansif_pi28 Jul '08 - 23:53 
great work....Congragulations Smile | :)
GeneralapologiesmemberMKMA23 Nov '07 - 3:37 
My sincere apologies, i was not using CDialog::OnInitDialog(); in my implimentation.
 

 
Cheers,
Mujeeb.
Generalproblem if init dialog is usedmemberMKMA23 Nov '07 - 3:22 
The button is really nice, Appreciate you for that..
I am facing a small problem with this XP-style button, this works fine for any dialog, but when i add the event handler, InitDialog, the button looses the xp-style.
Please help...Sigh | :sigh:
 
Mujeeb Ahmed.
QuestionWho has the CXPEdit?memberaimar26623 Apr '06 - 4:10 
I can see many CXPButton ,but no CXPEdit.Who has it,can he send to me ?Thank you.:->Laugh | :laugh:
 
Don't ask.Just do it!
GeneralNicememberAlton Williams29 Jun '05 - 3:21 
I like it, Thanks
GeneralToolTipsmemberparamecula16 Mar '05 - 2:19 
Hi
 
nice buttons, but when I convert my existing ones to XPButtons, the tooltips which worked previously when hovering over the buttons, no longer work. Is there a way to fix this ?

Generallittle bugsussHarbor Hu3 Mar '05 - 19:39 
Laugh | :laugh: Laugh | :laugh:
good job!
The four corners of the button have not deal to transparent.
so i put the button on the window with colors backgroud, the button will not so nice.
 
TKS!

 
Harbor Hu
GeneralRe: little bugmemberladydi9912 Apr '05 - 21:09 
how did you fix this bug?
GeneralRe: little bugmembervjairam1 Jun '05 - 11:11 
vjairamDoes any have fix for this
QuestionWhat bout other Controls...memberManoj Singh K18 Jan '05 - 19:18 
Hi
 
The XP-style Button Control is fine, the problem is, only the Buttons show in XP-style, but what bout the other controls like the Edit box, List controls and other dialog box controls, they are still in the old style...
 
Can anyone tell me how to change the other controls to XP-style, so that the dialog box doesn't looks odd.
 
Thanks and Regards
 
Manoj Singh
GeneralInvisiblememberfl0at4 Jul '04 - 7:24 
If I create XP buttons in my own workspace I can't see the buttons but I can click on it. What's wrong?
GeneralFix For Font example, chinese.sussanonymousafsdfasd15 May '04 - 3:58 
void yourbuttonclass::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
     ...
     GetWindowText(strText);
     CFont* oldFont = pDC->SelectObject(GetParent()->GetFont());
            ...
            pDC->SelectObject(oldFont);
     return;
}
GeneralFix For Font example, chinese.sussanonymous15 May '04 - 3:58 
void yourbuttonclass::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
     ...
     GetWindowText(strText);
     CFont* oldFont = pDC->SelectObject(GetParent()->GetFont());
            ...
            pDC->SelectObject(oldFont);
     return;
}
GeneralLittle BUG fixmemberIvo Wubbels23 Apr '04 - 1: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.membert2di4u28 Jan '04 - 19:11 
thanks
: )
GeneralWhy there is no XP-style Editmemberwhizzkid@ms28.hinet.net16 Dec '03 - 13:44 
I can find a lot of CXPButton, CButtonXP, CWinXPButton...
but I cannot find the CXPEdit or CEditXP except WTL

QuestionHow can I set the button colors?memberBobboots22 Aug '03 - 10:36 
I like the button style but I want to set buttons to different initial color states. The pushed state or hover state can be common to all buttons.
 
Bob
Generalhwo can i set iconmemberliquidsnake18329 Apr '03 - 8:28 
hi, is you your button class accept Icons if yes tell me hwo???
please reply,
Thanks,
Bye
 
liquid
QuestionWhat about xp titlebar?memberanon1231 Mar '03 - 10:46 
What about xp titlebar?
QuestionHow can I get change the font on the CXPButton?memberJaltair13 Feb '03 - 14:58 
I compile the project and i don´t know how to change font, can you help me?
 
thanks
AnswerRe: How can I get change the font on the CXPButton?memberJeremy Davis14 Feb '03 - 0:51 
m_buttonctrl.SetFont(.....);
 


I feel like I'm diagonally parked in a parallel universe
 
Jeremy Davis
http://www.astad.org
http://www.jvf.co.uk
GeneralRe: How can I get change the font on the CXPButton?memberJaltair18 Feb '03 - 6:04 
Ok, I forgot it, I´m trying to learn Visual c++, I'm not very experimented with the Functions, so could you give me an example, p.ex. with the font MS Sans Serif?Confused | :confused:
GeneralRe: How can I get change the font on the CXPButton?memberhalka14 Sep '04 - 4:06 
m_buttonctrl.SetFont(...) doesn't look to work Frown | :-(
The following code perfectly works with CButton and doesn't with CXPButton:
 
CFont *pFont = new CFont;
pFont->CreateFont( 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
m_btn1.SetFont(pFont, TRUE);

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

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