Click here to Skip to main content
Email Password   helpLost your password?

Sample Image - CTrueColorToolBar_Update.jpg

Introduction

CTrueColorToolBar is a real true color toolbar. Implementation of the class is very very easy. The particularity of this toolbar is the auto detection of the mask color with the DIB section of the first pixel of bitmap toolbar.

Steps to use

  1. Create dummy 16 color toolbar in VC with the number of buttons and final size you need.
  2. In your favorite painter, make 3 other true color toolbar bitmaps for state buttons (Normal, Hot, Disabled) based on the first one.
  3. Import your new true color toolbars in VC.
  4. Create new CTrueColorToolBar toolbar with the sample implementation of normal toolbar.
  5. Call LoadTrueColorToolBar function with your 3 true color toolbar bitmaps and the size of a button.
  6. That's it!

Example

//In Mainframe.h

#define TOOLBAR_DRAW_BUTTON_WIDTH 24
#include "TrueColorToolBar.h"

class CMainFrame : public CFrameWnd
{
    CTrueColorToolBar m_ToolBarDrawLeft;
}

//In Mainframe.cpp

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    if (!m_ToolBarDrawLeft.Create(this, WS_CHILD | 
        WS_VISIBLE | CBRS_LEFT  | CBRS_GRIPPER | 
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_ToolBarDrawLeft.LoadToolBar(IDR_TOOLBAR_DRAW))
    {
        TRACE0("Failed to create toolbar\n");
        return -1; //Failed to create

    }

    //Add bitmap to toolbar

    m_ToolBarDrawLeft.LoadTrueColorToolBar(
        TOOLBAR_DRAW_BUTTON_WIDTH,
        IDB_TOOLBAR_DRAW,
        IDB_TOOLBAR_DRAW_HOT,
        IDB_TOOLBAR_DRAW_DISABLED);

    //Add DropDown Button

    m_ToolBarDrawLeft.AddDropDownButton(this, ID_BUTTON1, IDR_MENU1);

    return 0;
}

Conclusion

Note also that in the function LoadTrueColorToolBar, if you omit the last parameter for disabled toolbar, you will get a default embossed disabled toolbar. Enjoy!

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalhow can I change the background of buttons?
wanglinhai888
22:33 29 Dec '09  
Hello, you have done very well, but the only regret is that there is no button of ctoolbar to change it's background color, so the button will make people feel ugly.do you have any idea to change it?
GeneralWhen using dialog it gives me a memory leak.
mensfort
3:35 2 Mar '09  
Hi,

The demo is derived from CFrameWnd. However when I use a simple CDialog, there is a memory leak in SetTrueColorToolBar. How to solve this ?

LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar), IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_CREATEDIBSECTION)

Greetings from Mensfort
GeneralWhen using dialog it gives me a memory leak.
mensfort
3:34 2 Mar '09  
Hi,

The demo is derived from CFrameWnd. However when I use a simple CDialog, there is a memory leak in SetTrueColorToolBar. How to solve this ?

LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar), IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE|LR_CREATEDIBSECTION)

Greetings from Mensfort
GeneralWhen using dialog it gives me a memory leak.
mensfort
3:33 2 Mar '09  
Hi,

The demo is derived from CFrameWnd. However when I use a simple CDialog, there is a memory leak in SetTrueColorToolBar. How to solve this ?

LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar),
IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE|LR_CREATEDIBSECTION)

Greetings from Mensfort

GeneralGreat,, Just What I've Been Wanting
Member 3650784
2:26 6 Nov '08  
So simple a class too. Makes you wonder why MS didn't already have the facility!
Questioncompiler error
matangoldman
7:02 23 May '08  
Linking...
CVTRES : fatal error CVT1100: duplicate resource. type:MANIFEST, name:1, language:0x0409
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

what should i do

thanks
AnswerRe: compiler error
merano
14:46 29 Mar '09  
Yes there must be a bug in the manifest. I cant find the error, but you can compile
if you go to project configuration properties -> Manifest Tool -> Input and Output -> Embed Manifest and setting it to "no."

see: social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/4724cf11-2942-4fa3-9b74-314afe40a9f5/

GeneralNo TOOLTIPS?
alex_tver
14:25 4 Jan '08  
Thanks a lot, works great. However why there are no tool tips show? Style CBRS_TOOLTIPS is set...
GeneralGreat!!! How can I disable/enable buttons?
Romiks
5:45 7 Jun '07  
Hi,
I need disable/enable buttons in my app,
please show how can I do this.

GeneralRe: Great!!! How can I disable/enable buttons?
DCUtility
15:47 7 Jun '07  
Look API EnableWindow();

L'enfer est pavé de bonnes intentions! Rose The road to hell is paved with good intentions!

GeneralRe: Great!!! How can I disable/enable buttons?
Paul Sanders (AlpineSoft)
9:16 26 Oct '07  
SendMessage (hToolbar, TB_ENABLEBUTTON, ctl_id, FALSE);
Where ctl_id is the command identifier of the button in question.


GeneralThanks
PJ Arends
9:58 13 Sep '06  
Thanks for the article. I used your toolbar in my article here[^].


You may be right
I may be crazy
-- Billy Joel --


Within you lies the power for good, use it!!!

GeneralHow to replace the default toolbar?
li0000
5:24 3 Jun '06  
Hi

Can I replace default toolbar?

Where can I find the true color icons for "open, save, copy, ...."?

Thanks,
GeneralLicense?
juraitwaluzka
18:35 30 May '06  
Very nice code. What is the license? Can it be used in commercial applications?

Thanks!
Generalvs2005 compiler error
banbanyy
5:19 19 Jan '06  
maybe something different in ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)?
AnswerRe: vs2005 compiler error
akaworks
11:59 1 Feb '06  
To Fix it, you need to change the first OnToolbarDropDown argument to use a NMHDR* instead of a NMTOOLBAR*.

TrueColorToolBar.h
afx_msg void OnToolbarDropDown(NMHDR* pnmhdr, LRESULT* plRes);

TrueColorToolBar.cpp
void CTrueColorToolBar::OnToolbarDropDown(NMHDR* pnmhdr, LRESULT *plr)
{
NMTOOLBAR *pnmtb = (NMTOOLBAR*)pnmhdr;

... rest of code...
}

GeneralBMP at BackGround
extus
15:00 17 Sep '04  
Does anyone know if i can put a BackGround Image to the white area of an SDI application. if(yes)
{
Can you tell me how i do it;
}
else
{
nevermind;
}
Smile
GeneralHelp! Why these happened?
youfly
3:10 22 Jun '04  
I`m a beginner of VC++(MFC).
I used your resource files in my application,and it worked very well at first.But when delete the files except useful files in Debug and complied and linked it ,or ,I pressed "Rebuild all",it told me these:

g:\lyf\mymfc\mainfrm.h(41) : error C2146: syntax error : missing ';' before identifier 'm_wndToolBar'
g:\lyf\mymfc\mainfrm.h(41) : error C2501: 'CTrueColorToolBar' : missing storage-class or type specifiers
g:\lyf\mymfc\mainfrm.h(41) : error C2501: 'm_wndToolBar' : missing storage-class or type specifiers
MyMFCDoc.cpp
MyMFCView.cpp
TrueColorToolBar.cpp
Generating Code...
Error executing cl.exe.

MyMFC.exe - 3 error(s), 0 warning(s)

And if I change "CTrueColorToolBar m_wndToolBar;"
to "CToolBar m_wndToolBar;" then press F5 ,nothing wrong happens;and if I then change it back,F5,nothing wrong happens too--it works very well.Confused

Who can tell me what happened?
Thank you very much!


GeneralRe: Help! Why these happened?
abiendl
1:35 2 Oct '04  
you should include TrueColorToolBar.h in mainfrm.h

#include "TrueColorToolBar.h"

GeneralButton to big with drop-down
quzi
3:53 30 Apr '04  
I is like this class the very much. I now has problem that I can not solving. When I am useing the AddDropDownButton then the size of button is very big. I cann't figure to make smaller. Is always same to big size.

Thanksing
GeneralGood job,but how can i show text on the button?
joxoy
0:26 30 Apr '04  
need your help!;)
GeneralRe: Good job,but how can i show text on the button?
quzi
1:12 30 Apr '04  
int btnIdx = m_wndToolBar.CommandToIndex(ID_BUTTON1);
m_wndToolBar.SetButtonText(btnIdx, _T("your text"));
m_wndToolBar.SetButtonStyle(btnIdx, TBSTYLE_AUTOSIZE);

GeneralRe: Good job,but how can i show text on the button?
joxoy
16:42 7 May '04  
It seemed the code did't work...
GeneralRe: Good job,but how can i show text on the button?
Einst
17:52 9 Jan '06  
If it doesn't work, why don't we put the text inside the image when you are creating the image button?
Smile
hope help
Generaldisable button
quzi
20:49 1 Apr '04  
How is disable an button? I is want that there is two buttons that only one of the two is enabled oncely. Is possibles?


Last Updated 28 Jan 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010