Click here to Skip to main content
15,886,032 members
Articles / Desktop Programming / MFC
Article

Office XP look & feel controls

Rate me:
Please Sign up or sign in to vote.
4.77/5 (15 votes)
22 Jan 2002CPOL1 min read 281.1K   4.9K   60   65
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)


Written By
Web Developer CSC
France France
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.

Comments and Discussions

 
GeneralBase Class Pin
jmgurgel23-Mar-02 6:31
jmgurgel23-Mar-02 6:31 
QuestionShading? Pin
Miguel Lopes20-Mar-02 0:03
Miguel Lopes20-Mar-02 0:03 
GeneralGreat Code, I like it ... Pin
Massimo Germi6-Mar-02 9:14
Massimo Germi6-Mar-02 9:14 
GeneralGood job, but ... Pin
5-Mar-02 9:22
suss5-Mar-02 9:22 
GeneralNew problem Pin
MaTrIX2k27-Feb-02 6:36
MaTrIX2k27-Feb-02 6:36 
GeneralRe: New problem Pin
Jean-Michel LE FOL7-Feb-02 11:04
Jean-Michel LE FOL7-Feb-02 11:04 
GeneralGoof but... Pin
MaTrIX2k26-Feb-02 20:02
MaTrIX2k26-Feb-02 20:02 
GeneralRe: Goof but... Pin
Jean-Michel LE FOL6-Feb-02 22:24
Jean-Michel LE FOL6-Feb-02 22:24 
I'm preparing the CMenuXP class...
GeneralRe: Goof but... Pin
MaTrIX2k27-Feb-02 6:29
MaTrIX2k27-Feb-02 6:29 
GeneralRe: Goof but... Pin
Jean-Michel LE FOL8-Feb-02 7:53
Jean-Michel LE FOL8-Feb-02 7:53 
Generalwonderful! but.. Pin
Anthony Chen31-Jan-02 16:38
Anthony Chen31-Jan-02 16:38 
GeneralAbout the compiled demo Pin
Jean-Michel LE FOL23-Jan-02 21:57
Jean-Michel LE FOL23-Jan-02 21:57 
GeneralSetButtonText Pin
Lofote23-Jan-02 9:56
Lofote23-Jan-02 9:56 
GeneralRe: SetButtonText Pin
4-Feb-02 2:12
suss4-Feb-02 2:12 
GeneralSame prob Pin
23-Jan-02 8:17
suss23-Jan-02 8:17 
GeneralRe: Same prob Pin
Lofote23-Jan-02 9:51
Lofote23-Jan-02 9:51 
GeneralRe: Same prob Pin
Jon Newman24-Jan-02 2:53
Jon Newman24-Jan-02 2:53 
GeneralRe: Same prob Pin
Nish Nishant25-Jan-02 22:54
sitebuilderNish Nishant25-Jan-02 22:54 
GeneralRe: Same prob Pin
Jean-Michel LE FOL25-Jan-02 23:23
Jean-Michel LE FOL25-Jan-02 23:23 
GeneralRe: Same prob Pin
Nish Nishant25-Jan-02 23:37
sitebuilderNish Nishant25-Jan-02 23:37 
GeneralGuess this isn't for XP... Pin
Darren Schroeder23-Jan-02 7:50
Darren Schroeder23-Jan-02 7:50 
GeneralRe: Guess this isn't for XP... Pin
Anders Molin23-Jan-02 7:56
professionalAnders Molin23-Jan-02 7:56 
GeneralRe: Guess this isn't for XP... Pin
Ramon Casellas23-Jan-02 23:00
Ramon Casellas23-Jan-02 23:00 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.