Using Fortran AppWizards to Help Add Modal Dialog Box Coding
Any Fortran project type can use a modal dialog box. Thus, when you
create a project, you can use any of the Fortran Project
AppWizards to help you create a project that uses a modal dialog box.
To create a "Hello World" Fortran Console application
that uses a modal dialog box to display "Hello World!":
- Create a new project with the Fortran Console project type named
HelloDlg. After you create the project, the Fortran Console AppWizard appears.
Select the "A Hello World sample project" option. Your workspace and
source file (HelloDlg.f90) will be created for you.
- In the Insert menu, select Resource... and select Dialog. Create the box using
the dialog resource editor, as follows:
- Delete the Cancel button (click the Cancel button and press the Delete key).
- Add a new static text control to the dialog box.
- You can enlarge or resize the static text control if needed.
- Double click on the static text control to edit its properties. Change the Caption
to "Hello World!." Under the Styles tab, you might change the Align text option to Center.
- Dismiss the dialog box by clicking the x in the upper-right corner of the window.
- In the File menu, select Save As... and save the resources
to a file named
HelloDlg.rc
in the project directory.
- In the Project menu, select Add To Project -> Files.
Select
HelloDlg.rc
and click OK.
- Edit (double-click its name in the FileView ) the file
HelloDlg.f90
:
- After the
program HELLODLG
line, add the following line:
USE DFLOGM
- Replace the line:
print *, 'Hello World'
With the following lines:
include 'resource.fd'
type (DIALOG) dlg
logical lret
integer iret
lret = DlgInit(IDD_DIALOG1, dlg)
iret = DlgModal(dlg)
call DlgUninit(dlg)
In the code above:
- The
USE DFLOGM
line includes the DFLOGM module interfaces to the Dialog routines.
- The line
include 'resource.fd'
includes the .fd file.
- The function reference to DLGINIT
initializes the dialog box.
- The function reference to DLGMODAL displays the dialog box.
- The call to DLGUNINIT frees the dialog box resources.
- Build the Hellodlg Fortran Console project application. When you execute the application,
the dialog box you created appears in front of the Console window:
- Click OK to dismiss the dialog box.
For Visual Fortran applications using the Fortran Windows project type, you can use
the Fortran Windows Project AppWizard to help you add dialog coding for a
modeless dialog box.
For information about coding requirements for modal and modeless dialog boxes, see
Initializing and Activating the Dialog Box.