Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / MFC

A raw toolbar for Dialog and Property page with plenty nice styles (version 1.00)

Rate me:
Please Sign up or sign in to vote.
2.97/5 (17 votes)
23 Aug 2006CPOL4 min read 52.6K   710   27   2
A raw toolbar for Dialog and Property page with plenty nice styles

Downloads and version review

VersionReleased onSource program 
1.00August/17/2006download
 
The new version 1.01 of the toolbar is available at HERE.
I will submit updates in new articles to save time and keep developing history. 

Introduction

I don't like Window's toolbar too much when I use it for dialog and property page, because it has less styles.

Last week, I decided to forget all of Windows toolbar issues and created a raw toolbar of mine.
After several hours of interesting work, I developed the "raw" toolbar, which is inherited from CWnd and has a CImageList as member variable - that is all - there is no any CToolBarCtrl or Win32 toolbar issues involved.

Now I feel I am master of the toolbar, because I can update it in anyway as I like.
 
Following is screenshot of source program, which displays 14 toolbars in different button styles.
(Toolbar has 7 styles, 3 more screenshots of them are displayed at bottom of the page).

Texts on left side of the screenshot describe 14 Button styles (not toolbar styles) about the 14 toolbars, which use same resource bitmap.

Image 1
  

Current state and usage

Usage is simple: draw a long bitmap in VC resource, which represents all buttons on toolbar, then tells the toolbar about the bitmap's ID - see function Create(...) bellow - the toolbar will be created.

Currently the toolbar has 2 functionalities:

  1. All buttons work independently
  2. All buttons work in one check group - only one button is checked/down
    (Screnshot above is about functionality 2 - first button is checked)
I developed the bar last week, I only need the 2 functionalities now, I will update it and add new downloads here when I need more functionalities.

Files and class

There are 2 files inside directory "lib" of source program: ToolbarMine (h and cpp).
The file contains only one class: ToolbarMine (inherented from CWnd).

Suffix Mine means it is mine - it is yours if you modify it - but not Microsoft's.

Functions of the class

The 2 functions must be called:

  1. BOOL Create(CWnd*pMum,int iBmpID,int cx,int iBarID=-1)iBmpID: bitmap ID in resource
    cx: width of button image in the bitmap (same as cx fot CImageList)
    iBarID: toolbar ID, the toolbar uses iBmpID as control ID if iBarID is not specified (default).
    Note: iBarID must be unique (similar to menu or other control ID) for parent window - it is related to message
     
  2. BOOL DockingOnTop(int iL, int iT, int iR=0,int iButtonStyle=Button::RAISED)
    iL: left position
    IT: top position
    iR: right position, it will be changed to right side of client area of parent window inside the function if input is 0 
    The 3 values are the same as values of left, top and right of CRect, bottom is useless because the bar auto resize its height according to buttons. If room (iR-iL) is not big enough, buttons are displayed in multiple rows.
    iButtonStyle: totally 14 button styles (refer to screenshot above), button styles can not be changed by other functions - but the function can be called multiple times for changing button styles.
      
    Note: there is no function for docking on bottom, left and right, because I only need to dock the bar on top now - but source code is very easy to be modified for docking to other sides.
Following functions are optional
  1. void SetCheckGroup(BOOL bGroup=TRUE)
    Set all buttons in one check group (default is not)
     
  2.  void SetToolbarBorderStyle(int iBorderStyle)
    There are 7 border styles for toolbar, screenshot of above is NONE (flat)
     
  3. BOOL SetCheckedButton(int iBtn,BOOL bMessage=FALSE);
    int GetCheckedButton();
    If the bar is in check-group, button can be checked programmatically.
    bMessage means if message is posted with the function.
    Second function gets which button is checked.
     
  4. void SetButtonBorderColor(COLORREF clr)
    If button style is COLORED, LARGE_COLORED, STRONG_COLORED or LARGE_STRONG_COLORED,  border color of buttons can be changed (see screenshot above).
     
  5. void SetToolbarBorderColor(COLORREF clr)
    Similar to function 6, but for color of toolbar.
     
  6. CSize GetToolbarSize();
    Get toolbar size, similar to GetWindowRect() function of VC.

Other functions are useful but not important, such as GetButtonSize(), which are not listed here one by one.

Message:

  • If toolbar is in check-group
    Message is posted at once if press (WM_LBUTTONDOWN) a button which is not checked
    Message will NOT be posted if the button is in checking state previously.
     
  • Otherwise (independent buttons)
    Message is posted if press a button then release (WM_LBUTTONUP) mouse cursor in the button's rectangle.
    Message will NOT be posted if mouse leaves the pressed button's rectangle.
    (Simulate to feature of Window button).
Message is posted to toolbar's parent window in the format:
message: WM_COMMAND, wParam: toolbar's ID, lParam: button index.
The toolbar use only the message.
(The message is displyed as caption text on sample program)

Other 3 screenshots of different toolbar styles:

Toolbar style of screenshot above is NONE (default), which can be changed at any time.
Total count of toolbar styles are 7, following screenshots are 3 more of them.
Note: button styles (14 styles) are the same for all screenshots.
 
Toolbar style: STRONG_SUNKEN

Image 2

 
Toolbar style: STONG_COLORED

Image 3

Toolbar style: STRONG_RAISED

Image 4

More info about styles:

  1. Button styles:
    Button size of top 3 toolbars on screenshots have same button size as CToolBar.
    LARGE, STRONG, RAISED_SUNKEN or SUNKEN_RAISED increases button size for 2x2 pixels more.

    For example, LARGEE_STRONG_RAISED increases button size for 4x4 pixels.
    STRONG means to draw button border for twice.

  2. Toolbar styles
    Toolbar size is fixed with all toolbar styles, because draw room (3 pixels) is prepared for different styles.

License

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


Written By
Web Developer
Australia Australia

Please visit our Download Home to obtain many interesting software for free ...


Comments and Discussions

 
QuestionWhy two articles? Pin
Jun Du23-Aug-06 3:55
Jun Du23-Aug-06 3:55 
AnswerRe: Why two articles? Pin
Rama Krishna Vavilala23-Aug-06 7:27
Rama Krishna Vavilala23-Aug-06 7:27 

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.