Downloads and version review
||Source program |
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.
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.
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:
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.
- All buttons work independently
- All buttons work in one check group - only one button is checked/down
(Screnshot above is about functionality 2 - first button is checked)
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:
Following functions are optional
- 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
- 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.
- void SetCheckGroup(BOOL bGroup=TRUE)
Set all buttons in one check group (default is not)
- void SetToolbarBorderStyle(int iBorderStyle)
There are 7 border styles for toolbar, screenshot of above is NONE (flat)
- BOOL SetCheckedButton(int iBtn,BOOL bMessage=FALSE);
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.
- 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).
- void SetToolbarBorderColor(COLORREF clr)
Similar to function 6, but for color of toolbar.
- 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 is posted to toolbar's parent window in the format:
- 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: 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
Toolbar style: STONG_COLORED
Toolbar style: STRONG_RAISED
More info about styles:
- 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.
- Toolbar styles
Toolbar size is fixed with all toolbar styles, because draw room (3 pixels) is prepared for different styles.