In DLG you can create dynamically not only controls but dialog boxes as well.
Both, modeless and modal dialogs, can be created. Additionally, conventional dialogs
(i.e. dialogs declared in an .rc-file and implemented by standard Windows programming) can be upgraded to full
DLG functionality. Thus your investment into old software is protected.
In the next sections you will find details to the following subjects:
Both, modeless and modal dialog, can be created in DLG. You will find sample programs to
all the subjects mentioned above, each of them with to two dialog boxes (for modeless and modal dialog)
upgrading a conventional dialog
creating a DLG dialog (controls created in
dialog procedure)
creating a DLG dialog (controls created
when launching the dialog)
On each dialog box there are controls of all standard types (Button, Static, Edit, ListBox,
ComboBox). Clicking on the button
triggers multimedia support,
you hear an audible signal. If you click in the top-left corner of the dialog box (beneath the title), a
debug-list with details of all dialog-controls appears.
(You don't need to launch the sample again and again for
the following examples. Just click the browser's surface and it is hidden
in the background. By clicking its button in the taskbar you can make it appear again.
After clicking in the top-left corner of the dialog box it stays in front permanently.)
Starting at DLG 2.1 you can have also a tooltip to each control. That's a small pop-up window with one line of text,
appearing when you put the cursor on the control and leave it there for approximately one-half second. Tooltips will
make your applications much more "user-friendly".
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 Dialog |
![]() |
![]() |
A conventional dialog can be upgraded to full DLG functionality by calling the procedure
UpgradeDlg in case of message WM_INITDIALOG
of the dialog procedure. However, don't forget to replace the standard Windows procedure
DefDlgProc by the DLG procedure DefDlgPrc.
Once upgraded, DLG makes no difference between a conventional dialog and a full DLG dialog.
For example, you can paint even a conventional dialog in any background color,
as in the first sample program (284 kB).
| UpgradeDlg (hDlg, "\b<options>", ...); |
| hDlg | window handle of dialog, delivered as input parameter to the dialog procedure |
| \b | DLG-specific separator to introduce options |
| <options> | Any number of DLG options, in keyword-notation: <keyword>=<value>. In DLG you can assign to a dialog any property you like, simply by keyword-notation. No need to care about strange formalisms any more! |
| Creating a DLG dialog (controls created in dialog procedure) |
![]() |
![]() |
DLG makes deliberate use of nested procedure calls - something that is hardly found in any sample program of conventional programming. The C/C++ syntax allows to call a procedure A nested within the call of another procedure B. To the compiler the return value of procedure A is just another parameter when calling procedure B. To the human programmer, however, this means a much more compact notation: B(..., A(...), ...); With a single line of code you can implement a very powerful operation!
In DLG this nicety of C/C++ is used to design a procedure that creates the template of the dialog box:
| Dlg (<style>, x, y, w, h, "<title>[\b<options>]", ... ) |
| <style> | Style of dialog box. For a modeless dialog at least WS_VISIBLE is needed. For a modal dialog a more complicated combination of window styles is required. Therefore, there is a DLG-specific shortcut provided for you: DYN_MODAL . |
| x, y, w, h | Dimensions of dialog box: x ... x-coordinate of top-left corner (screen units) y ... y-coordinate of top-left corner (screen units) w ... width of dialog box (screen units) h ... height of dialog box (screen units) By these parameters you can form your dialog box in any (rectangular) shape, placed anywhere on the screen. |
| <title> | Title of the dialog. This text will appear in the title bar of the dialog box. |
| ----------------------------------------- optional -------------------------------------------- | |
| \b | DLG-specific separator to introduce options |
| <options> | Placeholder for any number of options for embellishing, for input checking, etc. |
By nesting Dlg in another procedure you can launch a dialog by a single line of code only:
| CreateDlg (hInstance, Dlg (...), hParent, (DLGPROC) DlgProc, ... ); |
| hInstance | Application instance, delivered by Windows system (as the first parameter of WinMain) |
| Dlg (...) | Nested call of procedure Dlg. |
| hParent | Handle of parent window. (If this is a main window, i.e. executed by the Windows system, it is simply 0). |
| DlgProc | Dialog procedure. For formal reasons you will frequently have to type-cast it as being (DLGPROC). |
| Creating a DLG dialog (controls created when launching the dialog) |
![]() |
![]() |
Creating the controls of a dialog in the dialog procedure is fine as long as the dialog is not too
complicated or part of an application with many software modules.
Then the idea of "data hiding" comes in: Data objects should be
accessible to those modules only that are supposed to handle it. They should be "hidden" to all other modules for
avoiding the notorious "side effects".
However, all the associated variables just have to be global when they are needed in the dialog procedure as well as in the
calling program. Thus they are accessible to all the application's modules. Hard-to-debug errors can be caused by it.
Therefore, in DLG there is a way to launch a dialog with all the data involved being strictly local. The dialog controls
are declared just when the dialog is launched, by a nested procedure Control
. (It corresponds to procedure CreateCtl.
Details to this procedure you find in Sample 1.0, section
"DLG Edit box with 'Notempty' check".)
| Control (id, "<window class>", <style>, x, y, w, h, "<title>[\b<options>]", ...) |
| id | identifier of this control |
| "<window class>" | window class of this control |
| <style> | Style of this control. Can be a DLG-specific style combination and/or standard Windows styles. |
| x, y, w, h | dimensions of control: x ... x-coordinate of top-left corner (dialog units) y ... y-coordinate of top-left corner (dialog units) w ... width of control (dialog units) h ... height of control (dialog units) By these parameters you can form your control to any (rectangular) shape, placed anywhere on the dialog box. |
| <title> | Title of the dialog. This text will appear in the title bar of the dialog box. |
| ----------------------------------------- optional -------------------------------------------- | |
| \b | DLG-specific separator to introduce options |
| <options> | Placeholder for any number of options for embellishing, for input checking, etc. |
In DLG you can nest the procedure Control into the same procedure by which the dialog is launched:
Modeless dialog:
hDlg = CreateDlg (hInstance, Dlg ( ... ), hParent, (DLGPROC) DlgProc,
Control ( ... ),
Control ( ... ),
:
:
0); |
Modal dialog:
ret = DlgBox (hInstance, Dlg ( ... ), hParent, (DLGPROC) DlgProc,
Control ( ... ),
Control ( ... ),
:
:
0); |
| hInstance | Application instance, delivered by Windows system (as the first parameter of WinMain) |
| Dlg ( ... ) | nested call of procedure Dlg |
| hParent | Handle of parent window. (If this is a main window, i.e. executed by the Windows system, it is simply 0). |
| DlgProc | Dialog procedure. For formal reasons you will frequently have to type-cast it as being (DLGPROC). |
| return value | CreateDlg: window handle of new dialog (or 0 if unsuccessful) DlgBox: return value passed back in dialog procedure |