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:
A simple project
and click Finish To open the dialog resource 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:
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:
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
To specify the names and properties of the added controls:
The following figure shows the Properties box for the Horizontal Scroll bar with the default values.
Dialog Editor Sample 3
IDC_SCROLLBAR1
in the following figure). 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:
IDC_EDIT_CELSIUS
. The Static text next
to it is named IDC_TEXT_CELSIUS
and set to the left-aligned text "Celsius".IDC_EDIT_FAHRENHEIT
, and the Static text next to it
is named IDC_TEXT_FAHRENHEIT
and set to the left-aligned text "Fahrenheit".IDC_BOX_TEMPERATURE
, and its caption is set to Temperature.IDD_TEMP
and its caption is set to Temperature Conversion.The resulting dialog box is shown in the following figure:
Dialog Editor Sample 4
To save the dialog box as a resource 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).
TEMP.RC
file to your project:
TEMP.RC
file to be added to the project. To open an existing dialog box in the resource editor:
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.