Create the Open Dialog-Box Template

You need a dialog-box template in your resource script file to define the size and appearance of the Open dialog box. The DIALOG statement specifies the name and dimensions of a dialog box, as well as the controls the dialog box contains. Add the following statements:

1 Open DIALOG 10, 10, 148, 112

STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU

CAPTION “About FileOpen”

2 BEGIN

3 LTEXT “Open File &Name:”, IDC_FILENAME, 4, 4, 60, 10

4 EDITTEXT IDC_EDIT, 4, 16, 100, 12, ES_AUTOHSCROLL

LTEXT “&Files in”, IDC_FILES, 4, 40, 32, 10

5 LISTBOX, IDC_LISTBOX, 4, 52, 70, 56, WS_TABSTOP

6 LTEXT “”, IDC_PATH, 40, 40, 100, 10

7 DEFPUSHBUTTON “&Open”, IDOK, 87, 60, 50, 14

8 PUSHBUTTON “Cancel”, IDCANCEL, 87, 80, 50, 14

END

In this DIALOG statement:

1 The dialog box has a width and height (in dialog units) of 148 and 112, respectively. Dialog units are fractions of the default system-font character size and are used with dialog boxes to ensure that a dialog box has the same relative size, no matter which computer it is displayed on.
2 The BEGIN and END statements are required.
3 The first LTEXT statement creates a left-adjusted static control that contains the string, Open File &Name:. This string serves as the label to the list box. In some dialog boxes, all static controls have this same ID. Although the general rule is to have a unique ID for each control in a dialog box, it is acceptable to use –1 for static controls, as long as the dialog function does not need to distinguish between them (for example, as long as the dialog function does not attempt to change the static-control text or position).
4 The EDITTEXT statement adds an edit control to the dialog box and identifies it with IDC_EDIT. The ES_AUTOHSCROLL style is given so that the user can enter filenames that are longer than the control is wide.
5 The LISTBOX statement creates a list box. The ID of the list box is IDC_LISTBOX. The width and height (in dialog units) of the list box are 70 and 56, respectively. The WS_TABSTOP style is given so that the user can move the focus to the list box using the keyboard. Without this style, the user can get to the list box only by clicking it with the mouse.
6 The last LTEXT statement creates a left-adjusted static control used to display the current directory and drive. The control is initially empty; the pathname is added later. This control also has a unique control ID, IDC_PATH, to distinguish it from other static controls. This is important since you will use the DlgDirList function to fill the control.
7 The DEFPUSHBUTTON statement creates a default push button that is labeled &Open and has the control ID IDOK, a predefined ID found in the WINDOWS.H file. In modal dialog boxes, pressing ENTER generates a notification message that uses the same ID, so you can permit the user to click the button or press ENTER to open the selected file.
8 The PUSHBUTTON statement creates the Cancel push button. Its ID is IDCANCEL, a predefined ID found in the WINDOWS.H file. In modal dialog boxes, pressing ESC generates a notification message by using the same ID, so you can permit the user to click the button or press ESC to cancel the Open command.