Using the Resource Editor to Design a Dialog

You design the appearance of the dialog box, choose and name the dialog controls within it, and set other control properties with the Dialog Editor.

The Dialog Editor is one of the Resource Editors provided by the visual development environment (Developer Studio). Developer Studio contains other resource editors for editing icons, bitmaps, menus, and so on. For information on the other resource editors, see "Resource Editors" section in the Visual C++ User's Guide .

A program's resources are defined in a resource file (typically with a .rc extension). A Developer Studio project typically contains a single resource file. The contents of the resource file are displayed in the ResourceView. The resource file can be created by one of the following:

If you create the resource file from the resource editors, be sure to add the resource file to your project. After you do this, the resources will be displayed in the ResourceView. It is possible to include additional resource files in a project (see Including Resources Using Multiple Resource Files).

This section describes the steps needed to design a dialog box, and uses as an example a dialog box that converts temperatures between Celsius and Fahrenheit. The code in the example is explained as you read through this chapter.

In this section, we include the dialog box in a Fortran Console project. You can use the completed Visual Fortran sample in the ...\Samples\Dialog\Temp directory or you can create your own application.

To create a Fortran Console application:

To open the dialog resource editor:

  1. From the Insert menu, choose Resource.
  2. From the list of possible resources, choose Dialog.
  3. Click the New button. The dialog editor (one of the resource editors) appears on the screen as shown below.

Dialog Editor Sample 1

initial screen, dialog editor

A blank dialog box appears at the left and a toolbar of available controls appears on the right. If the Controls toolbar does not appear:

  1. Click Customize in the Tools menu
  2. Click the Toolbars tab
  3. Select (check) Controls

If you place the cursor over a control on the toolbar, the name of the control appears. The Controls toolbar items that are supported by Visual Fortran follow:

Button   Check box  
Combo box  
(such as a drop-down list box)
Group box  
Edit box   List box  
Picture   Progress bar  
Radio button   Scroll bar, horizontal  
Scroll bar, vertical   Slider  
Spin control   Static text  
Tab control    

You can also add ActiveX controls to your dialog box (see Using ActiveX Controls).

To add controls to the dialog box:

  1. Point at one of the available controls on the Control toolbar, hold down the left mouse button and drag the control to the dialog box.
  2. Place the dialog control where you want it to be on the dialog box and release the mouse button. You can delete controls by selecting them with the mouse, then pressing the Delete (or DEL) key.

The following figure shows the dialog box after adding two Static text lines (currently say Static), two Edit boxes (currently say Edit), a Horizontal Scroll bar, and a Group box. The Group box is the outlined rectangular area in the dialog box that encloses the other related controls.

The OK and CANCEL buttons were added for you by the Resource Editor. You can delete (select the control and press DEL key), move (drag the control), resize (drag one of the anchor points), rename the OK and CANCEL buttons or any of the controls that you add.

Dialog Editor Sample 2

dialog box after adding controls

To specify the names and properties of the added controls:

  1. Double-click one of the controls in your dialog box with the left mouse button. A Properties box appears showing the default name and properties for that control.

    The following figure shows the Properties box for the Horizontal Scroll bar with the default values.

    Dialog Editor Sample 3

    screen after double-clicking on the horizontal scroll bar

  2. Change the control name by typing over the default name (IDC_SCROLLBAR1 in the following figure).
  3. Check or uncheck the available options to change the control's properties. (The Visible option in the following figure is checked by default.)
  4. Click the left mouse button in the upper-right corner of the window Properties box to save the control's properties and to close the box.

    Repeat the same process for each control and for the dialog box itself.

To use the controls from within a program, you need symbolic names for each of them. In this example, the Horizontal Scroll bar symbolic name is changed in the Properties box to IDC_SCROLLBAR_TEMPERATURE. This is how the control will be referred to in your program; for example, when you get the slide position:

 INTEGER slide_position
 retlog = DLGGET (dlg, IDC_SCROLLBAR_TEMPERATURE,            &
                 slide_position, DLG_POSITION)

The controls are renamed as follows:

The resulting dialog box is shown in the following figure:

Dialog Editor Sample 4

completed dialog box

To save the dialog box as a resource file:

  1. From the File menu, choose Save As.

  2. Enter a resource filename for your file.

    In this example, the resource file is given the name TEMP.RC. The visual development environment saves the resource file and creates an include file with the name RESOURCE.FD. Typically, only one resource file is used with each Visual Fortran project (see Including Resources Using Multiple Resource Files).

  3. Add the TEMP.RC file to your project:
    1. In the Project menu, select Add to Project and click Files... from the submenu.
    2. The Insert Files into Project dialog box appears. Use this dialog box to select the TEMP.RC file to be added to the project.

To open an existing dialog box in the resource editor:

  1. From the File menu, open the project workspace.
  2. Click the ResourceView tab.
  3. Click the plus sign (+) next to project-name Resources.
  4. Click the plus sign (+) next to Dialog.
  5. Double-click the appropriate dialog name, such as IDD_DIALOG1.
  6. Use the Resource Editor to add a new control or modify an existing control. To modify an existing control, use the Tab key to select the appropriate control. Double-click the selected control to view or modify its properties.

At this point the appearance of the dialog box is finished and the controls are named, but the box cannot function on its own. An application must be created to run it.

Not all the controls on the Resource Editor Controls toolbar are supported by Visual Fortran dialog routines. The supported dialog controls are:

You can also add ActiveX controls to your dialog box. For information, see Using ActiveX Controls.

For further information on resources and control properties, see:

For information on creating an application for your dialog box, see Writing a Dialog Application.

For more information about using the Resource Dialog editor, see Using Resource Editors in the Visual C++ User's Guide (for Visual Fortran), located in the HTML Help folder Developer Studio 98.