Window and Dialog Templates

Templates defining standard windows and dialog boxes may be defined within the resource script file. Typically, a window or dialog template is designed using the Dialog Box Editor application supplied with the IBM Developer's Toolkit for OS/2 2.0, and is saved in a text file with an extension .DLG which is included in the resource script file with an rcinclude statement. A window or dialog template may also be defined directly into the resource script file. In either case, the template is defined using the WINDOWTEMPLATE or DLGTEMPLATE keywords. These keywords are actually synonymous, and the resource compiler interprets either keyword in the same way.

Within a single window or dialog template, there may be multiple WINDOW or DIALOG statements that define individual windows or dialog boxes. The nesting of the statements defines the parent/child window hierarchy. Figure "Window Template Resource Definition" shows an example of nested windows within a window template.

The window template WCP_001 contains a frame window with the title "Window Class X" and with size and positional coordinates as specified. The style attributes of the frame window are specified using the CTLDATA statement. The client window for this frame window is created using the WINDOW keyword nested within the window template, with no window title, the identifier FID_CLIENT, no size or positional coordinates (these are defined by the frame window), the class "MyClass" and the default client style.

The use of the WINDOWTEMPLATE keyword and WINDOW statements is a useful way for an application developer to predefine particular window types and styles for use by one or more applications. The template definitions may be used to create modal dialog boxes, which are loaded into memory and executed by the use of WinLoadDlg() and WinProcessDlg() calls. Definitions may also be created for standard windows or modeless dialog boxes, which are loaded into memory using the WinLoadDlg() function and executed by making the window or dialog box visible using the WinShowWindow() function.

Predefinition of windows is particularly useful when applied to dialog boxes. Here, the number and complexity of control window definitions is often such that creating such windows dynamically is a complicated task. A dialog box is defined in the resource script file (or a .DLG file, which is incorporated into the resource script file using the rcinclude statement) using the DLGTEMPLATE keyword.

Within a dialog template, there may be multiple dialogs defined using the DIALOG statement, and each dialog box may have multiple control windows defined using CONTROL keywords. Figure "Dialog Template Resource Definition" shows an example of a dialog template containing a dialog box with several control windows:

The dialog template is equivalent to a frame window, and is named DC_CREATE. This symbolic name is used to identify the dialog resource and is passed as a parameter to the WinDlgBox() function, which loads and processes the dialog box.

The dialog box is defined with a title bar and a dialog border, and is also named using the symbolic name DC_CREATE. The dialog box contains a static text control window providing instructions to the user, and an entry field into which the user may enter text. It also contains an "Enter" and a "Cancel" pushbutton.

Note that the resource identifier for the static text string does not use a symbolic constant, but simply has the value "-1". This is done because there is no need for the application to access the text string; it is merely present as a prompt to the user. It is therefore conventional to omit the symbolic constant and use "-1" as the value. Multiple text strings may have the same value.


[Back: Help Tables]
[Next: Resource Script File]