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

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

, 27 Jan 2003 CPOL
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

Comments and Discussions

 
GeneralMy vote of 4 PinmemberXiHong5-Nov-13 14:06 
Questionis it possible for CDialog? PinmemberLee Chi-Feng26-Aug-12 15:35 
GeneralIs it possible to change a button's image at runtime Pinmembermiggedy7-Sep-10 5:24 
Questionhow can I change the background of buttons? Pinmemberwanglinhai88829-Dec-09 21:33 
GeneralWhen using dialog it gives me a memory leak. Pinmembermensfort2-Mar-09 2:35 
GeneralWhen using dialog it gives me a memory leak. Pinmembermensfort2-Mar-09 2:34 
GeneralWhen using dialog it gives me a memory leak. Pinmembermensfort2-Mar-09 2:33 
GeneralGreat,, Just What I've Been Wanting PinmemberMember 36507846-Nov-08 1:26 
Questioncompiler error Pinmembermatangoldman23-May-08 6:02 
AnswerRe: compiler error Pinmembermerano29-Mar-09 13:46 
QuestionNo TOOLTIPS? Pinmemberalex_tver4-Jan-08 13:25 
QuestionGreat!!! How can I disable/enable buttons? PinmemberRomiks7-Jun-07 4:45 
AnswerRe: Great!!! How can I disable/enable buttons? PinmemberDCUtility7-Jun-07 14:47 
AnswerRe: Great!!! How can I disable/enable buttons? PinmemberPaul Sanders (AlpineSoft)26-Oct-07 8:16 
GeneralThanks PinmemberPJ Arends13-Sep-06 8:58 
QuestionHow to replace the default toolbar? Pinmemberli00003-Jun-06 4:24 
QuestionLicense? Pinmemberjuraitwaluzka30-May-06 17:35 
Generalvs2005 compiler error Pinmemberbanbanyy19-Jan-06 4:19 
AnswerRe: vs2005 compiler error Pinmemberakaworks1-Feb-06 10:59 
GeneralBMP at BackGround Pinmemberextus17-Sep-04 14:00 
QuestionHelp! Why these happened? Pinmemberyoufly22-Jun-04 2:10 
AnswerRe: Help! Why these happened? Pinmemberabiendl2-Oct-04 0:35 
GeneralButton to big with drop-down Pinmemberquzi30-Apr-04 2:53 
QuestionGood job,but how can i show text on the button? Pinmemberjoxoy29-Apr-04 23:26 
AnswerRe: Good job,but how can i show text on the button? Pinmemberquzi30-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 | Mobile
Web03 | 2.8.141015.1 | Last Updated 28 Jan 2003
Article Copyright 2003 by DCUtility
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid