5,534,119 members and growing! (16,823 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Custom Controls     Intermediate

Office XP look & feel controls

By Jean-Michel LE FOL

Some controls (toolbar, button, combobox, ...) with the Office XP look and feel.
VC6, VC7, C++Windows, Win2K, WinXP, MFC, VS.NET2002, VS6, Visual Studio, Dev

Posted: 22 Jan 2002
Updated: 22 Jan 2002
Views: 186,456
Bookmarked: 49 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
29 votes for this Article.
Popularity: 6.49 Rating: 4.44 out of 5
0 votes, 0.0%
1
1 vote, 6.7%
2
0 votes, 0.0%
3
3 votes, 20.0%
4
11 votes, 73.3%
5

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 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

Jean-Michel LE FOL


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.
Occupation: Web Developer
Company: CSC
Location: France France

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 64 (Total in Forum: 64) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralFound a way to display 24 bit images in CMenuXP, if anyone is interestedmemberAxiom66616:10 15 Mar '06  
GeneralRe: Found a way to display 24 bit images in CMenuXP, if anyone is interestedmemberAxiom6667:54 20 Mar '06  
GeneralSetButtonTextmembersujee3:07 8 Oct '04  
General? CMenuXP::OnMeasureItem ?memberFrank Lagattuta18:32 24 Sep '04  
GeneralOffice XP Style Edit ControlmemberJigar Mehta23:58 23 Jun '04  
GeneralOffice XP style task panememberSeshagiri0:25 7 Apr '04  
GeneralWindows XP style vs Office XP stylememberMarco van der Kolk23:51 1 Oct '03  
GeneralException in Draw.cppmemberJaime Stuardo16:51 31 Aug '03  
GeneralRe: Exception in Draw.cppmemberagfirehead20:02 14 Sep '03  
GeneralLoading and saving toolbar positionmemberArthurit0:03 19 Jul '03  
GeneralRe: Loading and saving toolbar positionmemberJean-Michel LE FOL9:27 20 Jul '03  
GeneralRe: Loading and saving toolbar positionmemberArthurit23:55 20 Jul '03  
GeneralBugmemberwz_zhou2:56 2 Jun '03  
GeneralIcon style doesn't work in CButtonXP controlmemberjstuardo8:54 19 Apr '03  
GeneralRe: Icon style doesn't work in CButtonXP controlmemberDJ Mantra2:47 4 Feb '05  
GeneralIncompatible with Win95memberadamtegen5:36 25 Mar '03  
GeneralRe: Incompatible with Win95memberMarco van der Kolk5:20 29 Sep '03  
GeneralRe: Incompatible with Win95memberpippa4:44 6 Apr '04  
GeneralHow to change the combo's height.memberDuc Truong22:38 11 Mar '03  
GeneralThe disabled imagem seems a little orangememberfpm111:40 26 Dec '02  
GeneralXP-style NOT shownmemberdarthmaul5:58 3 Dec '02  
GeneralAbout the compiled demomemberJean-Michel LE FOL22:29 3 Dec '02  
Generala bug!sussAnonymous0:23 22 Aug '02  
GeneralRe: a bug!memberTakahiro Araki14:24 16 Jan '03  
GeneralAn error with toolbarsussDMTR13:40 3 Aug '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Jan 2002
Editor: Chris Maunder
Copyright 2002 by Jean-Michel LE FOL
Everything else Copyright © CodeProject, 1999-2008
Web12 | Advertise on the Code Project