Click here to Skip to main content
Click here to Skip to main content

Bitmap ToolBar

By , 25 Apr 2002
 

Sample Image - screen.jpg

Introduction

This is my attempt to create a simple toolbar class that allows to set a bitmap in the background of a toolbar. It is not as successful as the BCGControl lib but that's a beginning...

Some improvements could be made; for example, a hot image is not used. The process also flickers a little when clicking a button. The class should also be modified to Load the background only once to update only the buttons rect.

To use

  • Create the toolbar as usual:
    if (!myToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, 
    		DB_BITMAP_TAHITI, IDB_BITMAP_TOOLBAR, 9, false) ||
    		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    	TRACE0("Failed to create toolbar\n");
    	return -1;      // fail to create
    }

    DB_BITMAP_TAHITI = id of the background bitmap.
    IDB_BITMAP_TOOLBAR = id of the toolbar bitmap.
    9 is the number of buttons of the bitmap.
    false is a boolean that define if the background bitmap must be stretched if its size is different of the toolbar.

    Note that TBSTYLE_FLAT will create flat format buttons... else, standard 3D buttons will be added.

  • Set the style of the process, IM_STRECH or IM_TRANSPARENT. IM_TRANSPARENT will take the toolbar image as it is and remove the background color. IM_STRECH stretch the bitmap to the size of the button.
    m_wndToolBar.ImageStyle = IM_TRANSPARENT;
    m_wndToolBar.MaskColor = RGB(198, 195, 198);
  • Define if the bitmap must be applied on the complete control frame or only on the toolbar. m_wndToolBar.all_frame = true;

  • You can modify the type of button with the DrawEdge function's options.

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

Nicolas Gazelle
Web Developer
Monaco Monaco
Member
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionProblem with docking at CBRS_LEFT or CBRS_RIGHT.memberhunzaixa16 Apr '08 - 23:10 
Confused | :confused: Confused | :confused: Confused | :confused:
QuestionCan anyone explain me a bit about the source code?memberBomberofdoom4 May '07 - 6:29 
Hi, I'm a basic C, C++ programmer and I'm trying to do a toolbar project on my own by looking at others porjects and I'm having a some trouble understanding this toolbar's source code.
Is there any chance someone could explain it to me in an email or through MSN?
My MSN is nir_levanon_a@hotmail.com
Thanks.
GeneralProblem with Dockingmemberdnataraja28 Mar '06 - 1:54 
Hi,
The bitmap in toolbar is working fine, but i came across two problems while using it.. One is when i am dragging the toolbar to the leftside of the window, the bit map is spreading across the entire width.
secondly when we drag the toolbar alone to the right(still on the top of the window)i see some gap in the place of image..
can u plz let me know how to rectify this.
 
Thanks in advance
 
Rgds,
Raju
Generalthank you Nicolasmemberquike604128 Dec '05 - 11:45 
Than You nicolasCool | :cool:
 
-- modified at 17:45 Wednesday 28th December, 2005
GeneralToolbar with gifmemberquike60412 Oct '05 - 5:06 
How to display .gif file on the toolbar and react to user click?
 
it will be very nice to any program.:->
QuestionHow to display .gif file on the toolbar and react to user clickmemberquike604130 Aug '05 - 13:11 
Sniff | :^) can I display .gif file on the toolbar ?
how ? tell me

AnswerRe: How to display .gif file on the toolbar and react to user clicksussNicolas Gazelle30 Aug '05 - 21:53 
You may use one of the image management class that are provided in codeproject to load the gif file. It should not be difficult, then to provide the toolbar required image format.
GeneralIs it possible on C#memberInquire2you3 Sep '04 - 14:11 
Anyone know is it possible on C# ?
If it is possible, how to do ?
 
Thank you
GeneralRe: Is it possible on C#memberchengser14 Aug '05 - 19:16 
这个是不可能的,每一个语言都有自己的特定之处!
I thing it can't
AnswerRe: Is it possible on C#memberThe Dogcow Farmer9 Jul '08 - 6:30 
Use the ToolStrip class.
 
"What's everyone so worked up about? So there's a comet -- big deal. It'll burn up in our atmosphere and what's ever left will be no bigger than a chihuahua's head." - Homer Simpson

Questiondont work well why??memberjason_pei23 Jun '04 - 16:01 
the image on the toolbar dont show well ??
QuestionHow to display .gif file on the toolbar and react to user clicksussSam Morgan3 May '04 - 8:50 
Hi, Good example.
 
I am think to display .gif file on the toolbar and react to user click -- something like the banner ads. Can anyone let me know how to do it using SDK or WTL?
 
Thanks,
 

Sam
GeneralNot so BadsussAnonymous19 Nov '02 - 7:15 
Laugh | :laugh: Laugh | :laugh: Laugh | :laugh: Laugh | :laugh: Laugh | :laugh: Laugh | :laugh:
You code is pretty gooood. But there is one problem that needs to be solved.
If the mouse is over any of the Toolbar buttons and you move the mouse out of the toolbar, the button never looses the focused image. i.e. it looks like the button is depressed.
How would you fix this, if you haven't?
Any help will be appreciated.
Thanks in Advance.
GeneralToobarControlsmemberAnthonyWinters30 Oct '02 - 9:28 
This is not directly related to this article but I thought you would know how to help me. I am trying to disable a toolbar button in a CTreeView MFC generated program. In MainFraim.cpp in the OnCreate function, I do the following:
 
CToolBarCtrl& tools = m_wndToolBar.GetToolBarCtrl();
tools.EnableButton(ID_ADD_PAGE,false);

 
The EnableButton function does nothing! Other functions like DeleteButton and Indeterminate work fine, but EnableButton doesn't work. Do I have to do something else to make this change go into effect?
 

Much Appreciated

 
Anthony
GeneralRe: ToobarControlsmemberBeer7 Dec '02 - 7:27 
use the command UI's to enable/disable the buttons
 

void CMainFrame::OnUpdateMrbutton(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_MrBOOL) { pCmdUI->Enable(FALSE); } else { pCmdUI->Enable(TRUE); }
}

GeneralRe: ToobarControlsmemberSir.Costy5 Dec '06 - 22:30 
hello
yes it's a god idea, but i have a litle question
 
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_XXXXX, OnUpdateMrbutton)
 
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
what <button id> would you set in message map for ON_UPDATE_COMMAND_UI
how can you get ID_XXXXX
GeneralBitmap Toolbarsusspremdutt15 Aug '02 - 20:29 
The background color of disabled buttons in toolbar becomes gray and loses it's image .I want the it's behaviour as normal application has.
Pls help me to solve the problem.
thanks
prem

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 26 Apr 2002
Article Copyright 2002 by Nicolas Gazelle
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid