
DLG 1.0 provides control types Static and Edit. There are great many variations of how you can form and embellish them. ('Embellishment' is something new in DLG. In standard Windows programming you can only 'form' controls.)
The following sections will give you some insight into
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.
| Upgrading a Conventional Static Control / Edit Box |
Conventionally programmed Windows applications can be upgraded to full DLG functionality. This is done for a control by procedure UpgradeCtl.
| UpgradeCtl ( ..., IDC_EDIT, "\bBkColor=%x", RGB_YELLOW, ... ); |
| IDC_EDIT | identifier of this control (same as in .rc-file; #define'd in a header file, e.g. resource.h) |
| \b | DLG-specific separator to introduce options |
| "BkColor=%x", RGB_YELLOW | The window text of an Edit control is not used in conventional programming.
DLG however uses it to pass any number of "options" to the upgrading/creation procedure. In this example you see how easy it is to set the background color at yellow. |
In this sample program you have an interesting comparison: The topmost edit box is kept in conventional programming, all the other are DLG controls (with the second edit box being conventional but upgraded to DLG). You see how much effort is needed for fetching the initial input and store-back of the final user input. This is done automatically by DLG - the application effort is next to zero!
| DLG Edit Box with "Notempty" Check |
Programming in DLG is very efficient for many reasons. One of it is the 'Check' feature:
user inputs can be submitted to various checks before a dialog is closed. Thus the application programmer can be sure
that all the data stored back from a user dialog will comply with the requirements. (Otherwise they would
have been intercepted by the Check feature, the user would not have been able to leave the dialog.) Therefore the
programmer can concentrate fully on the application itself.
An example for DLG-checking before storing the user inputs back to the calling program you see in the following code line.
Apart from upgrading conventional controls you can create controls in full DLG mode from the very beginning. Static and Edit control is created in DLG just like any other type of control by a procedure CreateCtl:
| CreateCtl (.., edt2, "Edit", DYN_EDIT, ..,..,..,.., "\bBkColor=%x", RGB_RED, " Color=%x", RGB_WHITE, " Notempty", ... ); |
| edt2 | identifier of this control |
| "Edit" | window class of this control |
| DYN_EDIT | DLG-specific style combination
(Normally you don't need more. An example where an additional style indicator is needed you see under "Numeric Edit box with custom check proc") |
| \b | DLG-specific separator to introduce options |
| "BkColor=%x", RGB_RED | this combination of a format specifier and a constant (#define'd in DLG header file) is printed to a hexadecimal number - by it DLG knows how to paint the background. |
| "Color=%x", RGB_WHITE | option to tell DLG the color the foreground (i.e. the letters within the Edit box) |
| "Notempty" | option to activate input checking: if the control is empty when the user clicks
the 'OK' button, it is "blinked" and the dialog does not close. Another way of input checking you see under "Numeric Edit box with custom check proc" |
| Fully Embellished Edit Box |
In DLG a control is not bound to be in boring gray color, with a lettering in standard system font with standard point size. Instead, a control can be painted in any RGB-color (foreground or background), brush or bitmap pattern. Lettering can be in any font and any point size available on your system. Thus your application can appear in your specific "corporate identity" on the screen of your user.
Following is the source code of this example:
| CreateCtl (..., edt3, "Edit", DYN_EDIT, ..., ..., ..., ..., "\bBkPattern=*%x", hBmp, " Color=%x", RGB_YELLOW, " BkMode=%d", TRANSPARENT, ... ); |
| edt3 | identifier of this control |
| "Edit" | window class of this control |
| DYN_EDIT | DLG-specific style combination |
| \b | DLG-specific separator to introduce options |
| "BkPattern=*%x", hBmp | hBmp is the handle of the bitmap to be used to paint the background pattern |
| "Color=%x", RGB_YELLOW | Normally the letters would be black on dark background (i.e. hard to read). Therefore, the color of the foreground (i.e. the letters the Edit box) is set to yellow by this option. |
| "BkMode=%d", TRANSPARENT | Now the letters would be yellow on white background (i.e. exempted from the pattern). Therefore the background mode is altered from opaque to transparent. |
| Right-click Edit Box with Italic Font |
In some applications it would be useful to provide the user with some features
that are beyond the standard functionality of a user dialog. In DLG you can do this easily by
linking a "callback" procedure into the DLG framework.
Then DLG handles all the routine tasks. You only need to program the extra functions, and to tell
DLG to call this procedure when the user performs a certain manipulation.
(In this example: clicking the edit box by the right mouse button.)
Additionally, this example shows how easily you can set the font and point size of the letters within the Edit box.
| CreateCtl (..., edt4, "Edit", DYN_EDIT, ..., ..., ..., ..., "\bFont='Arial Cursive' Size=18 RClickProc=%p", RClickProc, ... ); |
| edt4 | identifier of this control |
| "Edit" | window class of this control |
| DYN_EDIT | DLG-specific style combination |
| \b | DLG-specific separator to introduce options |
| Font='Arial Cursive' Size=18 | option to set the font of the Edit box at 'Arial Cursive'
with a font size of 18 (Depending on the version of your Windows system not all fonts and sizes may be available; if not, fonts default to 'MS Sans Serif' with the closest size available in your system.) |
| "RClickProc=%p", RClickProc | option telling DLG to execute the application-specific
callback procedure 'RClickProc' whenever the user right-clicks the Edit box. |
|
Numeric Edit box with Custom Check Proc, Responsive to Doubleclick |
This example assumes, the user should be prompted for any numeric input greater than zero. So it must be made sure that only digits can be entered and that the user input is greater than zero when the user clicks the "OK" button to close the dialog. If it is not, the user should decently be made aware of this error. The dialog should not be closed before the user input is valid.
Additionally, this example demonstrates how easy it is in DLG to enrich the standard functionality of an Edit box. (Edit box is just an example; double-click function can be attached to any of the DLG controls).
| CreateCtl ( ..., edt5, "Edit", DYN_EDIT | ES_NUMBER, ..., ..., ..., ..., "\bCheckProc=%p", CheckProc, "DblClickProc=%p", DblClickProc, ... ); |
| edt5 | identifier of this control |
| "Edit" | window class of this control |
| DYN_EDIT | ES_NUMBER | DLG-specific style combination plus additional style to allow user to input digits only |
| \b | DLG-specific separator to introduce options |
| "CheckProc=%p", CheckProc | option making application-specific callback procedure 'CheckProc'
to the check procedure (For details please see the source code of this example.) |
| "DblClickProc=%p", DblClickProc | option to make the application-specific callback procedure 'DblClickProc'
being called whenever the user doubleclicks the Edit box. (For details please see the source code of this sample.) |