Click here to Skip to main content
Licence CPOL
First Posted 20 Aug 2002
Views 186,649
Bookmarked 68 times

CTrueColorToolBar

By | 21 Aug 2002 | Article
Very simple true color toolbar (It's true!)

Sample Image - TrueColorToolBar.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;
    m_ToolBarDrawLeft.SetBorders(1, 1, 
        1, 1); //Fix for WinXP

    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
    }

    m_ToolBarDrawLeft.ModifyStyle(0, 
        TBSTYLE_FLAT);//Fix for WinXP
    m_ToolBarDrawLeft.LoadTrueColorToolBar(
        TOOLBAR_DRAW_BUTTON_WIDTH,
        IDB_TOOLBAR_DRAW,
        IDB_TOOLBAR_DRAW_HOT,
        IDB_TOOLBAR_DRAW_DISABLED);
    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)

About the Author

DCUtility

Other
DCUtility
Canada Canada

Member

Home Page

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionbug in docking... Pinmembermsh_kr3:07 29 Aug '11  
GeneralMy vote of 3 PinmemberKarstenK0:39 29 Oct '10  
Generaladding text PinmemberJabraJabra23:20 8 Jul '04  
Generalusing CTrueColorToolBar Pinsusssatadru1:05 15 Dec '03  
GeneralGDI leak Pinmembermanero3:33 1 Jul '03  
GeneralAdding text to toolbar Pinmemberahmad019:49 29 May '03  
GeneralRe: Adding text to toolbar Pinmemberluca diciotti23:05 9 Jun '03  
GeneralRe: Adding text to toolbar PinmemberEric Forget8:36 17 Nov '03  
GeneralRe: Adding text to toolbar Pinmemberluca diciotti21:42 17 Nov '03  
GeneralProblem with TBSTYLE_AUTOSIZE PinmemberZebster2:26 26 Feb '03  
GeneralRe: Problem with TBSTYLE_AUTOSIZE PinmemberZebster2:47 26 Feb '03  
GeneralTransparency issue on checked state Pinmemberrb263:59 28 Jan '03  
GeneralRe: Transparency issue on checked state PinmemberDany Cantin4:27 28 Jan '03  
GeneralRe: Transparency issue on checked state Pinmemberrb264:47 28 Jan '03  
Generalwhere is the Flat PinmemberGozhhu19:27 23 Jan '03  
Generalhelp with the drop arrow! PinmemberMingming Lu20:12 9 Jan '03  
GeneralRe: help with the drop arrow! PinmemberDany Cantin12:46 13 Jan '03  
QuestionAfxGetInstanceHandle vs. AfxGetResourceHandle? PinmemberFranck Pascutti0:33 13 Dec '02  
GeneralToolBarCtrl help PinmemberAnthonyWinters9:31 30 Oct '02  
GeneralRe: ToolBarCtrl help PinmemberDany Cantin9:55 30 Oct '02  
GeneralRe: ToolBarCtrl help PinmemberAnthonyWinters11:30 30 Oct '02  
GeneralRe: ToolBarCtrl help PinmemberAnthonyWinters12:28 30 Oct '02  
GeneralRe: ToolBarCtrl help PinmemberDany Cantin5:10 31 Oct '02  
QuestionCan tell me the truth? PinmemberLove In Snowing2:00 23 Aug '02  
AnswerRe: Can tell me the truth? PinmemberDany Cantin2:43 23 Aug '02  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120528.1 | Last Updated 22 Aug 2002
Article Copyright 2002 by DCUtility
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid