Sample32: Toolbar

Screenshot: Sample32.exe

"User-friendliness" is offering the user exactly those features needed most frequently, as directly accessible as possible: controls right at hand on the screen, ideally to be activated by one mouse click only. That's just the thinking behind a toolbar.

When the user sets about a different task, the subset of features "needed most frequently" will change - and so another subset of controls should be on screen. Consequently the user will exchange some old toolbars for some new ones - and the work goes on.

The following sections will show you some examples of

default Toolbar
Menubar
standard Toolbar
complex Toolbar

In DLG the design principle behind toolbars
goes far beyond conventional wisdom:

In conventional programming the toolbar controls are mostly buttons, only to save the user from a rummage through all the menus.
In DLG, however, a toolbar is just one (modeless) sub-dialog among others. Any of the controls of DLG 1.0 can be used for a toolbar as well. The users can choose any subset they want at a time. Any number of toolbars can be on screen at the same time. During all that time the current work is still in sight. Toolbars can even be How this looks like you can see in the following pictures:

Screenshot: docked toolbars change size with main dialog Screenshot: floating toolbars - always minimum size

After each section you will find a bookmark at the right edge of the screen (top). You can jump back to the top by clicking on it.


Default Toolbar


Screenshot: default Toolbar

In its simplest form a toolbar is a gray bar at the top of the main window with some buttons on it. Instead of getting hold of a feature in a menu, the user can trigger it by clicking a button.
Yet, more than a "go now!"-decision cannot be done by a conventional toolbar.

You can declare a default toolbar simply by the following code lines:

 CreateToolbar (hDlg, "<title>"
			"\bReloc"	// if you want it relocatable
		Control ( ..., "Button", ... ),
		0);

For details of how to declare a button see Sample 1.1

hDlg window handle of main window
"<title>" title of toolbar
(visible only when toolbar is floating)
\b DLG-specific separator to introduce options
"Reloc" option to make toolbar relocatable
(without this option it is always docked, the user cannot drag it to floating state)

Messages are relayed to the main window by the standard toolbar procedure. So you can handle a  WM_COMMAND  message sent by a toolbar button simply by the following code lines in your message loop:

case <id>: <*** Action ***>
break;


<id> identifier of toolbar button
(Windows system sends a message  WM_COMMAND  with this <id> when the user clicks the button)
<*** Action ***> action to be triggered by the button

top

Menubar


Screenshot: floating Menubar

One of the drawbacks of conventional menus is that they are always located fix at the top edge of the work area. Wouldn't it be better to offer a menu that can be placed everywhere on screen, next to the work in progress currently?
With a DLG-toolbar you can do just that: Provide a toolbar with a number of buttons and attach an operation  CO_POPUP  to each of them (see Sample111.htm, "Pop-up Menu"). This operation presents a pop-up menu when the button is clicked.
So the user can trigger any number of activities by one button only.

This can easily be implemented by something like the following code lines:

CreateToolbar (hDlg, "<title>\bReloc BkColor=%x", RGB_WHITE,
Control (..., "Button", ...
\b ... " CustomOp=%d,%d", CO_POPUP, hPopup, 0),
0);

For details of how to declare a button see Sample 1.1
especially "Pop-up Menu for Application-specific Features"

hDlg window handle of main window
"<title>" title of toolbar
(visible only when toolbar is floating)
\b DLG-specific separator to introduce options
"Reloc" option to make toolbar relocatable
(without this option it is always docked, the user cannot drag it to floating state)
"CustomOp=%d,%d", CO_POPUP, hPopup option to attach a custom operation (presenting pop-up menu  hPopup ) to a button
(for details see Sample 1.11, CO_POPUP)

You can declare the pop-up menu (presented when the button is clicked) by a few code lines:

HMENU hPopup = CreatePopupMenu();
AppendMenu (hPopup, MF_STRING, id1, "item 1");
AppendMenu (hPopup, MF_STRING, id2, "item 2");
AppendMenu (hPopup, MF_STRING, id3, "item 3");


hPopup menu handle by which the button handles the pop-up menu
(details see standard Windows procedures  CreatePopupMenu  and  AppendMenu )
id1, id2, id3 identifiers of menu items
(by these identifiers you can trigger the respective action when the user clicks an item)
"item1", "item2", "item3" texts of menu items
(these texts the user will see in the pop-up menu)

top

Standard Toolbar


Screenshot: standard Toolbar

In DLG, like every other UIF-element, also a toolbar can be colored (by any RGB-color, by a brush or a pattern). Formally a toolbar is an ordinary modeless dialog. So it can be colored and equipped with controls in the usual way.
You just need to apply an option determining the background color, like in the following code lines:

CreateToolbar (hDlg, "<title>\bReloc BkColor=%x", RGB_YELLOW,
Control (..., "Button", ... , 0),
Control (..., "ComboBox", ... , 0),
Control (..., "Button", ... , 0),
0);

For details of how to declare a button see Sample 1.1,
for a ComboBox see Sample 1.3

hDlg window handle of main window
"<title>" title of toolbar
(visible only when toolbar is floating)
\b DLG-specific separator to introduce options
"Reloc" option to make toolbar relocatable
(without this option it is always docked, the user cannot drag it to floating state)
"BkColor=%x", RGB_YELLOW option to paint the toolbar's background in yellow color

In order to access toolbar controls you need something like the following code lines:

case <id0>:	hTb = GetToolbar (<index>);
		hCmb = GetDlgItem (hTb, <id>);
		GetWindowText (hCmb, text, sizeof(text));
		  :
		break;


hTb window handle of toolbar, needed to access toolbar controls
(details see standard Windows procedures  GetDlgItem  and  GetWindowText )

top

Complex Toolbar


Screenshot: complex Toolbar

Formally a toolbar is an ordinary modeless dialog. So it can carry not only buttons or a ComboBox but any other control as well. These controls are declared as usual for launching a DLG dialog, as in the following example:

 CreateToolbar (hDlg, "<title>\bReloc Index=.. BkColor=%x", RGB_BEIGE,
		Control (..., "Button", ... , 0),
		Control (..., "Slider", ... , 0),
		Control (..., "Slider", ... , 0),
		0);

For details of how to declare a button see Sample 1.1,
for Slider see Sample 1.7

hDlg window handle of main window
"<title>" title of toolbar
(visible only when toolbar is floating)
\b DLG-specific separator to introduce options
"Reloc" option to make toolbar relocatable
(without this option it is always docked, the user cannot drag it to floating state)
"Index=.." index by which this toolbar will be identified by auxiliary procedures
(auxiliary procedures are the tools to integrate toolbars into your own programming)
BkColor=%x", RGB_BEIGE option to paint the toolbar's background in beige color

For toolbar handling the following auxiliary procedures come with Dlg 3.2:

DockToolbar (<index> [,hDlg]);
DockAllToolbars ([hDlg]);
GetToolbar (<index> [,hDlg]);
DestroyToolbar (<index> [,hDlg]);


DockToolbar DLG procedure to dock an individual toolbar
(it is docked at top of the main window; at bottom of toolbars already docked, if any)
DockAllToolbars DLG procedure to dock all toolbars
(they are docked at top of the main window; in order of the indices by which they were declared)
GetToolbar DLG procedure to retrieve the window handle of a toolbar
DestroyToolbar DLG procedure to remove a toolbar from dialog
(thus freeing its index)
index index by which the toolbar was declared
hDlg optional: window handle of main window
(current active window, if omitted)

top

Home | Outline | DLG