Click here to Skip to main content
11,565,382 members (38,240 online)
Click here to Skip to main content

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

, 27 Jan 2003 CPOL 176.3K 8.6K 86
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

DCUtility
DCUtility
Canada Canada

You may also be interested in...

Comments and Discussions

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

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 28 Jan 2003
Article Copyright 2003 by DCUtility
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid