Creating a Dialog

In this example, we will create a simple dialog that asks the user to enter his/her name, providing a text box for input, plus both "OK" and "Cancel" buttons. To create the dialog, first we use the DIALOG NEW statement:

LOCAL hParent AS DWORD

LOCAL hDlg AS DWORD

...

DIALOG NEW hParent, Caption$,,, 160, 50, Style&, exStyle& TO hDlg

hParent refers to the parent window handle. If this value is 0 (or %HWND_DESKTOP), the dialog has no parent window, and may be referred to as a "top-level" window. However, if the dialog has a parent window and the dialog is a MODAL dialog, Windows will automatically disable the parent window while the DDT dialog is displayed.

Caption$ is the text displayed in the caption of the dialog. This may be the name of your program, or it can be used to convey other information to the user.

The next two parameters for the location on the screen are omitted (this causes the dialog to be centered on the screen), and the size is set to 160 dialog units wide by 50 dialog units tall. Style& specifies how the dialog is drawn on the screen (with a caption, without a caption, etc). exStyle& specifies an extended style attributes for drawing the dialog. For information on the range of possible dialog styles, please see the DIALOG NEW statement.

Once the dialog has been created, the handle for it is placed in the hDlg variable. hDlg may be a Long-integer or Double-word variable (i.e., hDlg& or hDlg???), but a Double-word variable is recommended. This handle is used by Windows (and your program) code to identify the dialog. Windows gives each dialog a unique handle value at run-time; no two windows, dialogs, or controls can have the same handle value. This means that the actual handle value will be different every time the dialog is created.

Note that the height and width values determine the client size of the dialog, if the dialog style explicitly includes the %WS_CAPTION style. Otherwise, they are interpreted as the outer dimensions of the complete dialog.

 

Note: The location and size of a dialog are specified in Dialog Units or, optionally, Pixels.

 

See Also

Dynamic Dialog Tools (DDT)

Adding Controls to the Dialog

Modal vs. Modeless

Controls

Control Styles

Callbacks

Dialog Styles

Menus