Dec 192017
 
Sample C source file on how to program 'ToolBars' for MS Windows 3.0.
File TOOLBAR.ZIP from The Programmer’s Corner in
Category C Source Code
Sample C source file on how to program ‘ToolBars’ for MS Windows 3.0.
File Name File Size Zip Size Zip Type
TBTEST.C 5105 1546 deflated
TBTEST.DEF 422 228 deflated
TBTEST.EXE 48118 12271 deflated
TBTEST.PRJ 4761 912 deflated
TOOLBAR.C 9222 2374 deflated
TOOLBAR.DOC 7190 2463 deflated
TOOLBAR.H 964 422 deflated

Download File TOOLBAR.ZIP Here

Contents of the TOOLBAR.DOC file


DOCUMENTATION ON THE TOOLBAR LIBRARY
====================================

by Stephen Chung ([email protected])


Introduction
------------

This set of routines implement the slick "toolbar" found in Microsoft
Word for Windows, Excel etc. They are written and compiled using
Borland C++ 2.0. I HAVE NOT tested them on any other compiler.


How to use
----------

Look at the sample program TBTEST.C for an example. That toolbar is
part of a Japanese word processor I am writing. I have not included
the icons because they are embedded in a large .res file with everything
else. If you want some of them, send me email.

First of all, the toolbar is a 3-dimensional, horizontal bar containing
"toolbar buttons". You can add other kinds of child window controls
onto the toolbar as well, such as combo boxes etc.

Before you do anything, you must define an array of TOOLBARICON. Each
element in that array corresponds to one toolbar button. The fields
should be set according to the followoing:

int id /* The numeric ID of the button (0-255) */
int x, y /* The X,Y position of the button, in pixels */
int width, height /* The width/height of the button, in pixels */
int state /* The initial state of the button:
-1 = Disabled
0 = Off
1 = On
2 = Grayed
*/
int cycle /* The mode of that button, upon a mouse click:
0 = Leave the state alone
(Set it with a BM_SETSTATE message)
1 = Always undepressed, but flashed once
2 = Toggle On --> Off --> On
3 = Toggle On --> Off --> Gray --> On
*/

char *disabled /* The name for the DISABLED bitmap */
char *undepressed /* The name for the OFF bitmap */
char *depressed /* The name for the ON bitmap */
char *grayed /* The name for the GRAYED bitmap */
char *pressing /* The name for the bitmap for being pressed */

You should leave the rest of the fields alone. They are used internally
by the routines.

To create the toolbar, call CreateToolbar. This routine has the following
parameters:

HWND CreateToolbar (HWND parent, int x, int y, int width, int height,
int thickness, int id, int nr_buttons, HANDLE hInstance,
TOOLBARICON *icons, char *xcursor)


HWND parent /* The parent window handle */
int x, y, /* X,Y position of the toolbar, in pixels */
int width, height /* Width and height, in pixels */
int thickness /* Its apparant thickness, in pixels */
int id /* ID number */
int nr_buttons /* The number of toolbar buttons */
HANDLE hInstance /* Instance handle */
TOOLBARICON *icons /* Pointer to a TOOLBARICON array */
char *xcursor /* The name of the cursor for a disabled toolbar
button. If NULL, the cursor will remain an
arrow */

The routine will return the handle for the toolbar. You can use this handle
to add more child controls (see TBTEST.C).

The toolbar will send a WM_COMMAND message to its parent when one of its
buttons is clicked. The following paremeters are passed:

message WM_COMMAND

wParam Low Byte = Toolbar ID
High Byte = Toolbar button ID

lParam Low Word = Toolbar button window handle
High Word = BN_CLICKED

REMEMBER that even other child controls that you define (such as list boxes)
will return with wParam = (Child ID << 8) | (Toolbar ID). This means that
you are restricted to having 256 toolbars and 256 toolbar buttons and child
controls on each toolbar. Well, life is tough, isn't it?

You enable and disable toolbar buttons by calling EnableToolbarButton
with the following parameters:

void EnableToolbarButton (HWND hwnd, int child, BOOL on)

HWND hwnd /* The window handle of the TOOLBAR */
int child /* The ID of the toolbar button */
BOOL on /* TRUE = Enable, FALSE = Disable */

You can also set or query the state of a toolbar button by sending the
TOOLBAR BUTTON a BM_GETSTATE or BM_SETSTATE message, just as you would for
a normal push button. You can also send the BM_GETSTATE and BM_SETSTATE
messages to the TOOLBAR, with the toolbar button's ID passed to lParam.

If, for some twisted reason, you want to modify the characteristics
of the toolbar button dynamically, you can first call GetToolbarButton
to fill in a TOOLBARICON structure:

HWND GetToolbarButton (HWND hwnd, int child, TOOLBARICON *icon)

HWND hwnd /* The window handle of the TOOLBAR */
int child /* The ID of the toolbar button */
TOOLBARICON *icon /* Pointer to a TOOLBARICON structure. If not
NULL, the fields will be filled in with
the most current settings. */

This routine will return the window handle of the toolbar button. Now
you can change the settings and then call ModifyToolbarButton:

void ModifyToolbarButton (HWND hwnd, TOOLBARICON *icon)

HWND hwnd /* The window handle of the TOOLBAR BUTTON! */
TOOLBARICON *icon /* The TOOLBARICON structure containing new
settings */

There is also a neat little routine called Create3DEffect which will
make any rectangle within any window look like a 3-dimensional bar:

void Create3DEffect (HDC hdc, RECT *rect, int thickness)

HDC hdc /* Device context to draw on */
RECT *rect /* Pointer to a RECT structure defining the
area to make 3D. If rect is NULL, then
the entire window is 3D'd. */
int thickness /* How thick you want the 3D effect to be */

If you want to change the name of the toolbar classes, they are defined
in TOOLBAR.H

One final thing, you must remember to export ToolbarProc and
ToolbarButtonProc in your .def file of course.


Afterwords
----------

Theoretically, you are required to obtain special approval from me (because
I copyrighted these routines) if you want to use them in your programs.
However, I usually don't really care if you are not using these routines in
a commercial, shareware etc. product.

Any questions and/or bug fixes, please send email to:

Stephen Chung [email protected]

If it bounces, then try [email protected]

Have fun!


 December 19, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)