Click here to Skip to main content
Licence CPOL
First Posted 22 Jan 2002
Views 224,994
Bookmarked 59 times

Office XP look & feel controls

By | 22 Jan 2002 | Article
Some controls (toolbar, button, combobox, ...) with the Office XP look and feel.

Sample Image

Introduction

Yet another owner drawn toolbar. This one has the Office XP look & feel. Have a look to the source code (ToolbarXP.h and ToolbarXP.cpp) for more details. Some parts of code are copied from other articles. Thanks to their authors!

How to use the CToolBarXP class

Include the ToolbarXP.h file and just replace the CToolBar m_wndToolBar declaration in your files by CToolBarXP m_wndToolBar. That's all ! (see the demo)

Other classes

CButtonXP, CListBoxXP, CComboBoxXP: Flat controls with "mouseover" and "mouseout" effects.
CStatusBarXP: Flat statusbar.
CPopup: Allow any control to be popped over frame (as shown in the image).
CWindowsManagerDlg: MDI child window manager.

CBufferDC: An easy-to-use class to simplify the bufferized drawing.

Example: Replace in your code:

void CToolBarXP::OnPaint ()
{
    CPaintDC cDC (this);

    cDC.FillSolidRect (CRect(10,10,100,100), 255);
    cDC.MoveTo (10, 10);
    cDC.LineTO (100, 100);
    // Etc...
}
by:
void CToolBarXP::OnPaint ()
{
    CPaintDC cpDC (this); // Modified line
    CBufferDC cDC (cpDC); // Added line

    cDC.FillSolidRect (CRect(10,10,100,100), 255);
    cDC.MoveTo (10, 10);
    cDC.LineTO (100, 100);
    // Etc...
}
And it works too with any HDC (see the CButtonXP::DrawItem method for another exemple).
The only constraint: you have to do all drawing with the same CBufferDC instance. You cannot have a first part in the OnEraseBkgnd and another one in the OnPaint.

CPenDC and CBrushDC: Simplify the use of local CPen and CBrush objects.

Without those classes:

    // ...
    CPen pen (PS_SOLID, 1, RGB(0,0,255));
    CBrush brush (RGB(0,255,0));
    CPen* pOldPen = cDC.SelectObject (&pen);
    CBrush* pOldBrush = cDC.SelectObject (&brush);
    cDC.Rectangle (10,10,100,100);
    cDC.SelectObject (pOldPen);
    cDC.SelectObject (pOldBrush);
    // ...
With them:
    // ...
    CPenDC pen (cDC, RGB(0,0,255));
    CBrushDC brush (cDC, RGB(0,255,0));
    cDC.Rectangle (10,10,100,100);
    // ...

CClientRect and CWindowRect: Encapsulate GetClientRect and GetWindowRect calls.

Without:

    // ...
    CRect rcClient;
    GetClientRect (rcClient);
    cDC.FillSolidRect (rcClient, 255);
    // ...
With:
    // ...
    cDC.FillSolidRect (CClientRect (this), 255);
    // ...

CWindowText: Encapsulate GetWindowText calls.

Without:

    // ...
    CString sText;
    GetWindowText (sText);
    CDC.DrawText (sText, rc, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    // ...
With:
    // ...
    cDC.DrawText (CWindowText (this), rc, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    // ...

Credit

Thanks to Christian Rodemeyer for his RGB<->HLS conversion methods from the article CColor - RGB and HLS combined in one class.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jean-Michel LE FOL

Web Developer
CSC
France France

Member

Jean-Michel LE FOL is a GraphTalk product architect.
GraphTalk is a set of products which cover the whole scope of the development process. GraphTalk is used by the main insurance compagnies over the world.
The development team is currently based in France near Paris.

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralFound a way to display 24 bit images in CMenuXP, if anyone is interested PinmemberAxiom66615:10 15 Mar '06  
GeneralRe: Found a way to display 24 bit images in CMenuXP, if anyone is interested PinmemberAxiom6666:54 20 Mar '06  
GeneralSetButtonText Pinmembersujee2:07 8 Oct '04  
Question? CMenuXP::OnMeasureItem ? PinmemberFrank Lagattuta17:32 24 Sep '04  
GeneralOffice XP Style Edit Control PinmemberJigar Mehta22:58 23 Jun '04  
GeneralOffice XP style task pane PinmemberSeshagiri23:25 6 Apr '04  
GeneralWindows XP style vs Office XP style PinmemberMarco van der Kolk22:51 1 Oct '03  
GeneralException in Draw.cpp PinmemberJaime Stuardo15:51 31 Aug '03  
GeneralRe: Exception in Draw.cpp Pinmemberagfirehead19:02 14 Sep '03  
GeneralLoading and saving toolbar position PinmemberArthurit23:03 18 Jul '03  
GeneralRe: Loading and saving toolbar position PinmemberJean-Michel LE FOL8:27 20 Jul '03  
GeneralRe: Loading and saving toolbar position PinmemberArthurit22:55 20 Jul '03  
GeneralBug Pinmemberwz_zhou1:56 2 Jun '03  
GeneralIcon style doesn't work in CButtonXP control Pinmemberjstuardo7:54 19 Apr '03  
GeneralRe: Icon style doesn't work in CButtonXP control PinmemberDJ Mantra1:47 4 Feb '05  
GeneralIncompatible with Win95 Pinmemberadamtegen4:36 25 Mar '03  
GeneralRe: Incompatible with Win95 PinmemberMarco van der Kolk4:20 29 Sep '03  
GeneralRe: Incompatible with Win95 Pinmemberpippa3:44 6 Apr '04  
QuestionHow to change the combo's height. PinmemberDuc Truong21:38 11 Mar '03  
GeneralThe disabled imagem seems a little orange Pinmemberfpm110:40 26 Dec '02  
GeneralXP-style NOT shown Pinmemberdarthmaul4:58 3 Dec '02  
GeneralAbout the compiled demo PinmemberJean-Michel LE FOL21:29 3 Dec '02  
Generala bug! PinsussAnonymous23:23 21 Aug '02  
GeneralRe: a bug! PinmemberTakahiro Araki13:24 16 Jan '03  
GeneralAn error with toolbar PinsussDMTR12:40 3 Aug '02  
I have tested your code on Win2K SP2 machine. Everything seems OK but the toolbar is looking as it is simple, not as it is on the demopicture - with shadows, highlight, etc - just simple Windows toolbar. What is wrong?

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 23 Jan 2002
Article Copyright 2002 by Jean-Michel LE FOL
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid