Click here to Skip to main content
15,867,330 members
Articles / Desktop Programming / MFC

A ToolBarCtrl Based Menubar Control

Rate me:
Please Sign up or sign in to vote.
4.85/5 (19 votes)
3 Dec 20011 min read 211.6K   4.3K   67   26
A ToolBarCtrl based menubar control using CMenuXP

Sample Image - MenuBarXP.jpg

Introduction

This menubar control is based on the CToolBarCtrl class rather than CToolBar, so it never assumes that it has a parent window derived from CFrameWnd. It lacks some features like docking or automatic tooltips, but it can be used with any window whose parent is derived from CWnd. You must of course be using MFC.

Implementation

Between CMenuBar and CToolBarCtrl, I wrote a class named CToolBarXP to process customdraw. If you don't need this feature, just modify the base class as CToolBarCtrl, and remove the following line from the messagemap:

C++
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, CToolBarXP::OnCustomDraw)

CToolBarXP includes a LoadToolBar member function to load a toolbar resource. It may be useful to you, even if you don't care about menubars or customdraw.

CMenuXP is used as the menu class to implement ownerdraw. CMenuXP is derived from CMenu so it has all the features of CMenu. If you don't need a ownerdraw menu, just use the CMenu members to construct the menu.

The included sample is simple and far from powerful, but it is a good start I hope.

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.


Written By
China China
I'm a chinese programer living in Shanghai, currently working for a software company whose main business is to deliver computer based testing. Software simulation for computer based testing and certifications is my main responsibility in this company. Execpt for software development, I like out-door activities and photography. I am willing to make friends in China and all over the world, so contact me if you have anything in common with meSmile | :)

Comments and Discussions

 
Generalctoolbarxp didn't display text Pin
wanglinhai88821-Feb-10 20:16
wanglinhai88821-Feb-10 20:16 
GeneralSubMenu Bug Pin
benjamin2321-May-08 4:39
benjamin2321-May-08 4:39 
GeneralApp suddenly exits Pin
Chris982121-Apr-08 8:59
Chris982121-Apr-08 8:59 
GeneralRe: App suddenly exits Pin
hujian_19827-Sep-09 19:39
hujian_19827-Sep-09 19:39 
QuestionSEPARATOR bug Pin
lihe20057-Sep-06 20:16
lihe20057-Sep-06 20:16 
MS Standard Menu SEPARATOR not responding to the message that two (WM_LBUTTONDOWN, WM_RBUTTONDOWN). MenuBarXP how to solve with the same standard Like.
Regards ,
GeneralSome improvement (XP themes) Pin
AlexXF24-Nov-04 7:29
AlexXF24-Nov-04 7:29 
GeneralRe: Some improvement (XP themes) Pin
Frank Overcast22-Jan-06 15:40
Frank Overcast22-Jan-06 15:40 
GeneralCatch Click Events Pin
naumankhan15-Apr-04 21:44
naumankhan15-Apr-04 21:44 
GeneralRe: Catch Click Events Pin
Neil Yao15-Apr-04 21:59
Neil Yao15-Apr-04 21:59 
GeneralRe: Catch Click Events Pin
jagan_gadela21-Apr-04 1:33
jagan_gadela21-Apr-04 1:33 
GeneralRe: Catch Click Events Pin
jagan_gadela21-Apr-04 1:58
jagan_gadela21-Apr-04 1:58 
GeneralRe: Catch Click Events Pin
Neil Yao21-Apr-04 4:10
Neil Yao21-Apr-04 4:10 
GeneralRe: Catch Click Events Pin
jagan_gadela22-Apr-04 2:05
jagan_gadela22-Apr-04 2:05 
GeneralRe: Catch Click Events Pin
Neil Yao22-Apr-04 23:12
Neil Yao22-Apr-04 23:12 
GeneralRe: Catch Click Events Pin
Jim Tomasko24-Apr-04 22:38
Jim Tomasko24-Apr-04 22:38 
Questionpossible to use this on SDI??? Pin
Hirosh16-Feb-03 20:57
Hirosh16-Feb-03 20:57 
GeneralPretty cool, only one thing though Pin
11-May-02 0:50
suss11-May-02 0:50 
Questionhow to change the color of the toolbar? Pin
1-May-02 19:40
suss1-May-02 19:40 
GeneralI have a problem!!! Pin
CSZX3-Apr-02 0:48
CSZX3-Apr-02 0:48 
GeneralDoesn't work with dropdown arrow. Pin
Duc Truong14-Jan-02 14:23
Duc Truong14-Jan-02 14:23 
GeneralChanging background color of Menu Pin
Ritesh2321-Dec-01 22:36
Ritesh2321-Dec-01 22:36 
GeneralGood job Pin
19-Dec-01 1:37
suss19-Dec-01 1:37 
GeneralMenu icon lost itself when mousemove on the popup menu items Pin
10-Dec-01 15:46
suss10-Dec-01 15:46 
GeneralGetParent Pin
orcun colak6-Dec-01 17:44
orcun colak6-Dec-01 17:44 
GeneralRe: GetParent Pin
Neil Yao7-Dec-01 4:13
Neil Yao7-Dec-01 4:13 

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.