![]() |
In DLG you have a great flexibility in terms of color, font,
pattern, etc. of your UIF. But instead of fix embellishment, wouldn't it be better
to let the user customize his/her personal UIF?
Sure it would be better. But wouldn't it be an enormous programming effort to
implement those customizing features?
No. With Operations 2 it is just
one additional option when creating the button activating it. Giving your application
a higher level of user friendliness is a matter of a few minutes with DLG.
The following sections will give you some insight into
| Let the user select a color | |
| Let the user select a font | |
| Let the user select a pattern | |
| Let the user select a symbol | |
| Partly covered dialog | |
| Pop-up menu to access application-specific features |
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.
| Let the User Select a Color |
![]() |
![]() |
When clicking the button "Color", a sub-dialog opens with
a color scheme in which the user can select one of the pre-defined colors or compose
an own color. The color value is stored back to the main dialog when the sub-dialog
is closed. There it can be processed right away or it can be passed on to a subsequent
dialog that will be colored in the color selected by the user.
Frequently it will be used for customizing the color of the main dialog itself.
This can be done by a few lines of code.
For calling the pre-programmed operation for selecting a color, an extra option is needed when
creating the button. You can see it in the following code line:
| CreateCtl (psh1, ... "Color\bEnableMenu=%x,%d", hPopup, IDM_ACTION1, "Dest=%d", stc1, "CustomOp=%d", CO_COLOR, "IO=%p", &lBkColor, ... ) |
| psh1 | identifier of this button |
| Color | text label of this button |
| \b | DLG-specific separator to introduce options |
| "EnableMenu=%x,%d", hPopup, IDM_ACTION1 | option to enable menu item
IDM_ACTION1 in menu
hPopup . (Initially this menu item is disabled, to prevent the user from applying it as long as the color is undefined.) |
| "Dest=%d", stc1 | option to have color displayed on
Display-control with identifier
stc1 . (Note that this option is coded left of option "CustomOp=" !) |
| "CustomOp=%d", CO_COLOR | option to make this button trigger a sub-dialog for selecting/composing a color |
| "IO=%p", &lBkColor | operation-specific option to have selected color
stored at variable lBkColor . (Note that this option is coded right of option "CustomOp=" !) |
If you want to use this color to re-paint the dialog box in the main dialog, you can do that by one code line in the dialog procedure:
| UpgradeDlg (hDlg, "BkColor=%x", lBkColor, 0) |
| Let the User Select a Font |
![]() |
![]() |
Just as with colors, there is a sub-dialog for selecting a
font (font family, style and point size, to be exact). When the user clicks "OK"
to close the sub-dialog, its font handle is returned to the main dialog. There it
can be used for any purpose; for example, to launch another dialog employing this
font.
This is done simply by an extra option when creating the button that triggers
the sub-dialog, like in the following code line:
| CreateCtl (psh2, ... "Font\b ... ", " Dest=%d", stc2, " CustomOp=%d", CO_FONT, ... ) |
| psh2 | identifier of this button |
| Font | text label of this button |
| \b | DLG-specific separator to introduce options |
| "Dest=%d", stc2 | option to have color displayed on
Display-control with identifier
stc2 . (Note that this option is coded left of option "CustomOp=" !) |
| "CustomOp=%d", CO_FONT | option to make this button trigger a sub-dialog for selecting a font |
| Let the User Select a Pattern |
![]() |
![]() |
Similar to colors and fonts, a sub-dialog for selecting a pattern is
available in DLG. (Or, more exactly, the user selects a bitmap file. Based on this
bitmap, a pattern brush is created. The handle of this brush is passed on to a
Display control (see
Sample 1.10). Not before that the user can see it.
In an application this is done simply by an extra option when creating the button
the user clicks to activate selecting a pattern. You can see it in the following
code line:
| CreateCtl (psh3, ... "Pattern\bEnableMenu=%x,%d", hPopup, IDM_ACTION2, "Dest=%d", stc3, "CustomOp=%d", CO_PATTERN, "IO=%p", &lBkBrush, ... ) |
| psh3 | identifier of this button |
| Pattern | text label of this button |
| \b | DLG-specific separator to introduce options |
| "EnableMenu=%x,%d", hPopup, IDM_ACTION2 | option to enable menu item
IDM_ACTION2 in menu
hPopup . (Initially this menu item is disabled, to prevent the user from applying it as long as the pattern is undefined.) |
| "Dest=%d", stc3 | option to have color displayed on
Display-control with identifier
stc3 . (Note that this option is coded left of option "CustomOp=" !) |
| "CustomOp=%d", CO_PATTERN | option to make this button trigger a sub-dialog for selecting a pattern |
| "IO=%p", &lBkBrush | operation-specific option to have selected color
stored at variable lBkBrush . (Note that this option is coded right of option "CustomOp=" !) |
Just like a color, you can use a pattern to re-paint the dialog box in the main dialog. You can do that by one code line in the dialog procedure:
| UpgradeDlg (hDlg, "BkBrush=%x", hBkBrush, 0) |
NOTEBy Windows-standards, a dialog box cannot have color and pattern
at the same time.
Therefore, in the sample program the color of the dialog box (if any) is removed
when you apply menu item "set background pattern". The bitmap you select in the
sub-dialog is painted as the new pattern, with the default background color (gray).
|
| Let the User Select a Symbol |
![]() |
![]() |
In a similar way like selecting a file for creating a pattern,
the user can select an icon- or bitmap-file for creating an icon or bitmap symbol.
The handle of the icon or bitmap extracted from the file selected is returned to
the main dialog.
This is done by an additional option when creating the button for selecting a symbol.
In the following code line you can see how such a button is created:
| CreateCtl (psh4, ... "Symbol\b ... ", " Dest=%d", stc4, " CustomOp=%d", CO_SYMBOL, ... ) |
| psh4 | identifier of this button |
| Symbol | text label of this button |
| \b | DLG-specific separator to introduce options |
| "Dest=%d", stc4 | option to have color displayed on
Display-control with identifier
stc4 . (Note that this option is coded left of option "CustomOp=" !) |
| "CustomOp=%d", CO_SYMBOL | option to make this button trigger a sub-dialog for selecting a symbol (= icon or bitmap) |
| Partly Covered Dialog |
![]() |
Some dialogs have such a rich functionality that the greater part of
users will use only a limited part of it. Only a few users will need its full power.
So, it would not be good interface design to show the full dialog right from the
beginning. Only if a user clicks a button, the bottom controls are uncovered.
This is easy to implement with one of the Operations 2 -
just create a button like in the following code line:
| CreateCtl (psh5, ... "Up/Down\b ... ", " CustomOp=%d,80", CO_UPDOWN, ... ) |
| psh5 | identifier of this button |
| Up/Down | text label of this button |
| \b | DLG-specific separator to introduce options |
| "CustomOp=%d,80", CO_UPDOWN | option to make this button trigger an
up/down-operation. (Note the second parameter 80. This is the number of pixels the height of dialog box will be varied.) |
| Pop-up Menu for Application-specific Features |
![]() |
One thing that will be needed in almost every major application is
a feature for access of application-specific operations. A good way to do this is
presenting a pop-up menu with the names of these operations, when the user is clicking
a button.
In DLG there is a simple way to do that - just create a button, simply like that:
|
HMENU hPopup = CreatePopupMenu(); AppendMenu (hPopup, MF_STRING, IDM_ACTION1, "applic.-spec. operation 1"); AppendMenu (hPopup, MF_STRING, IDM_ACTION2, "applic.-spec. operation 2"); /* etc. */ |
| CreateCtl (psh6, ... "Menu\b ... ", " CustomOp=%d,%d", CO_POPUP, hPopup, ... ) |
| psh6 | identifier of this button |
| Menu | text label of this button |
| \b | DLG-specific separator to introduce options |
| "CustomOp=%d,%d", CO_POPUP, hPopup | option to make this button trigger an
up/down-operation. (Note the second parameter hPopup. This is the handle of the pop-up menu to be launched.) |
In the dialog procedure you can easily handle the messages coming from the pop-up menu:
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_ACTION1: /* applic.-spec. operation 1 */
break;
case IDM_ACTION2: /* applic.-spec. operation 2 */
break;
/* etc.*/
}
break;
} |