Click here to Skip to main content
15,868,141 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 280K   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

 
QuestionQuestion about article: Office XP look & feel controls Pin
MyOldAccount6-Jun-13 19:22
MyOldAccount6-Jun-13 19:22 
GeneralFound a way to display 24 bit images in CMenuXP, if anyone is interested Pin
Axiom66615-Mar-06 15:10
Axiom66615-Mar-06 15:10 
GeneralRe: Found a way to display 24 bit images in CMenuXP, if anyone is interested Pin
Axiom66620-Mar-06 6:54
Axiom66620-Mar-06 6:54 
/////////////////////
CBitmap bit, mask;
bit.LoadBitmap(IDB_BITMAP2);
mask.LoadBitmap(IDB_BITMAP3);

m_icons.Create(16,16,ILC_MASK | ILC_COLOR24,0,3);
m_icons.Add(&bit, &mask);

CMenuXP::SetXPLookNFeel(this);
CMenuXP::SetMenuItemImage(ID_NEW, m_icons.m_hImageList, 0);
CMenuXP::SetMenuItemImage(ID_OPEN, m_icons.m_hImageList, 1);
CMenuXP::SetMenuItemImage(ID_SAVEAS, m_icons.m_hImageList,2);
//////////////////////////////////

It works for me


Axiom

One of many...
GeneralSetButtonText Pin
sujee8-Oct-04 2:07
sujee8-Oct-04 2:07 
Question? CMenuXP::OnMeasureItem ? Pin
fjlaga24-Sep-04 17:32
fjlaga24-Sep-04 17:32 
GeneralOffice XP Style Edit Control Pin
Jigar Mehta23-Jun-04 22:58
Jigar Mehta23-Jun-04 22:58 
GeneralOffice XP style task pane Pin
Seshagiri6-Apr-04 23:25
Seshagiri6-Apr-04 23:25 
GeneralWindows XP style vs Office XP style Pin
Member 476071-Oct-03 22:51
Member 476071-Oct-03 22:51 
GeneralException in Draw.cpp Pin
Jaime Stuardo31-Aug-03 15:51
Jaime Stuardo31-Aug-03 15:51 
GeneralRe: Exception in Draw.cpp Pin
agfirehead14-Sep-03 19:02
agfirehead14-Sep-03 19:02 
GeneralLoading and saving toolbar position Pin
Arthurit18-Jul-03 23:03
Arthurit18-Jul-03 23:03 
GeneralRe: Loading and saving toolbar position Pin
Jean-Michel LE FOL20-Jul-03 8:27
Jean-Michel LE FOL20-Jul-03 8:27 
GeneralRe: Loading and saving toolbar position Pin
Arthurit20-Jul-03 22:55
Arthurit20-Jul-03 22:55 
GeneralBug Pin
zhou_wz2-Jun-03 1:56
zhou_wz2-Jun-03 1:56 
GeneralIcon style doesn't work in CButtonXP control Pin
Jaime Stuardo19-Apr-03 7:54
Jaime Stuardo19-Apr-03 7:54 
GeneralRe: Icon style doesn't work in CButtonXP control Pin
Master^Tristar4-Feb-05 1:47
Master^Tristar4-Feb-05 1:47 
GeneralIncompatible with Win95 Pin
adamtegen25-Mar-03 4:36
adamtegen25-Mar-03 4:36 
GeneralRe: Incompatible with Win95 Pin
Member 4760729-Sep-03 4:20
Member 4760729-Sep-03 4:20 
GeneralRe: Incompatible with Win95 Pin
½pippa6-Apr-04 3:44
½pippa6-Apr-04 3:44 
QuestionHow to change the combo's height. Pin
Duc Truong11-Mar-03 21:38
Duc Truong11-Mar-03 21:38 
GeneralThe disabled imagem seems a little orange Pin
fpm126-Dec-02 10:40
fpm126-Dec-02 10:40 
GeneralXP-style NOT shown Pin
darthmaul3-Dec-02 4:58
darthmaul3-Dec-02 4:58 
GeneralAbout the compiled demo Pin
Jean-Michel LE FOL3-Dec-02 21:29
Jean-Michel LE FOL3-Dec-02 21:29 
Generala bug! Pin
Anonymous21-Aug-02 23:23
Anonymous21-Aug-02 23:23 
GeneralRe: a bug! Pin
Takahiro Araki16-Jan-03 13:24
Takahiro Araki16-Jan-03 13:24 

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.