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

Very simple true color toolbar (It's true!)

Rate me:
Please Sign up or sign in to vote.
4.74/5 (37 votes)
27 Jan 2003CPOL 215.9K   9.6K   94   37
This is TrueColor Toolbar class

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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Canada Canada

Comments and Discussions

 
GeneralMy vote of 4 Pin
XiHong5-Nov-13 14:06
XiHong5-Nov-13 14:06 
Questionis it possible for CDialog? Pin
Lee Chi-Feng26-Aug-12 15:35
Lee Chi-Feng26-Aug-12 15:35 
GeneralIs it possible to change a button's image at runtime Pin
miggedy7-Sep-10 5:24
miggedy7-Sep-10 5:24 
Questionhow can I change the background of buttons? Pin
wanglinhai88829-Dec-09 21:33
wanglinhai88829-Dec-09 21:33 
GeneralWhen using dialog it gives me a memory leak. Pin
mensfort2-Mar-09 2:35
mensfort2-Mar-09 2:35 
GeneralWhen using dialog it gives me a memory leak. Pin
mensfort2-Mar-09 2:34
mensfort2-Mar-09 2:34 
GeneralWhen using dialog it gives me a memory leak. Pin
mensfort2-Mar-09 2:33
mensfort2-Mar-09 2:33 
GeneralGreat,, Just What I've Been Wanting Pin
MackemSteve6-Nov-08 1:26
MackemSteve6-Nov-08 1:26 
Questioncompiler error Pin
matangoldman23-May-08 6:02
matangoldman23-May-08 6:02 
AnswerRe: compiler error Pin
merano29-Mar-09 13:46
merano29-Mar-09 13:46 
QuestionNo TOOLTIPS? Pin
alex_tver4-Jan-08 13:25
alex_tver4-Jan-08 13:25 
QuestionGreat!!! How can I disable/enable buttons? Pin
Romiks7-Jun-07 4:45
Romiks7-Jun-07 4:45 
AnswerRe: Great!!! How can I disable/enable buttons? Pin
DCUtility7-Jun-07 14:47
professionalDCUtility7-Jun-07 14:47 
AnswerRe: Great!!! How can I disable/enable buttons? Pin
Paul Sanders (the other one)26-Oct-07 8:16
Paul Sanders (the other one)26-Oct-07 8:16 
GeneralThanks Pin
PJ Arends13-Sep-06 8:58
professionalPJ Arends13-Sep-06 8:58 
QuestionHow to replace the default toolbar? Pin
transoft3-Jun-06 4:24
transoft3-Jun-06 4:24 
QuestionLicense? Pin
juraitwaluzka30-May-06 17:35
juraitwaluzka30-May-06 17:35 
Generalvs2005 compiler error Pin
banbanyy19-Jan-06 4:19
banbanyy19-Jan-06 4:19 
maybe something different in ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)?
AnswerRe: vs2005 compiler error Pin
akaworks1-Feb-06 10:59
akaworks1-Feb-06 10:59 
GeneralBMP at BackGround Pin
extus17-Sep-04 14:00
extus17-Sep-04 14:00 
QuestionHelp! Why these happened? Pin
youfly22-Jun-04 2:10
youfly22-Jun-04 2:10 
AnswerRe: Help! Why these happened? Pin
abiendl2-Oct-04 0:35
abiendl2-Oct-04 0:35 
GeneralButton to big with drop-down Pin
quzi30-Apr-04 2:53
quzi30-Apr-04 2:53 
QuestionGood job,but how can i show text on the button? Pin
joxoy29-Apr-04 23:26
joxoy29-Apr-04 23:26 
AnswerRe: Good job,but how can i show text on the button? Pin
quzi30-Apr-04 0:12
quzi30-Apr-04 0:12 

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.