Coding Requirements for Fortran Windows Applications

This section contains the following topics:

General Coding Requirements: WinMain Function and USE Statements

Coding requirements for Fortran Windows applications include (in the following order):

  1. WinMain function declaration and interface

    The WinMain function declaration and interface are required for Windows Graphical User Interface (GUI) applications (typically use at least the GDI and USER32 Win32 routines). An interface block for the function declaration can be provided. On ia32 systems, the following function must be defined by the user:

          INTEGER(4) function WinMain ( hInstance, hPrevInstance, &
         &         lpszCmdLine, nCmdShow )
    !DEC$ ATTRIBUTES STDCALL, ALIAS:'_WinMain@16' :: WinMain
             INTEGER(4), INTENT(IN) :: hInstance, hPrevInstance
             INTEGER(4), INTENT(IN) :: lpszCmdLine
             INTEGER(4), INTENT(IN) :: nCmdShow
    

    In a program that includes a WinMain function, no program unit can be identified as the main program with the PROGRAM statement.

  2. The statement USE DFWIN or other appropriate USE statements

    The USE DFWIN statement makes all parameters and interfaces for nearly all Windows public routines available to your Visual Fortran program. Any program or subprogram that uses the Windows features must include the statement USE DFWIN, which must appear in each subprogram that makes graphics calls, before any declaration statements (such as IMPLICIT NONE or INTEGER) or any other modules containing declaration statements.

    If you want to limit the type of parameters and interfaces for Windows applications or if unresolved references occur when linking your Fortran Windows application, see Calling Win32 Routines.

  3. Data declarations for the WinMain function arguments.

  4. Application-dependent code (other USE statements, variable declarations, and then executable code).

For example, the first lines of the Visual Fortran Sample named Generic uses the following free-form source code and conditional ia32 and ia64 code:

 integer function WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
 !DEC$ IF DEFINED(_M_IX86)
 !DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain
 !DEC$ ELSE
 !DEC$ ATTRIBUTES STDCALL, ALIAS : 'WinMain' :: WinMain
 !DEC$ ENDIF
 use dfwin

 integer hInstance
 integer hPrevInstance
 integer nCmdShow
 integer lpszCmdLine
 .
 .
 .

This Sample uses the IF Directive Construct and a predefined preprocessor symbol _M_IX86 to generate portable conditional code. For a description of predefined preprocessor symbols (such as _M_IX86 and _M_IA64), see the /define compiler option.

DFWIN.F90 includes a Fortran version (a subset) of the Win32 WINDOWS.H header file (see Calling Win32 Routines).

Code Generation Options Using the Fortran Windows Application Wizard

When you create a project with the Fortran Windows Application project type, the Fortran Windows Application Wizard (AppWizard) appears, allowing you to select whether the new project being created will have source code, type of tutorial source code, and specify other options:

appwizard for fortran windows projects

If selected, you can specify whether the source file will contain template-like source statements typically used by one of the Fortran Windows applications subtypes:

If your application (SDI, MDI, or dialog-based) will use ActiveX controls in a dialog box, if you check the box labeled "This project will use ActiveX controls," the Fortran Windows AppWizard will add additional template code for supporting ActiveX controls in your dialog boxes.

To select project options that request that the project be linked against dynamic-link libraries (instead of static libraries), click the check box labeled "This project will be linking against one or more Fortran DLL Import libraries."

Single Document Interface (SDI) or Multiple Document Interface (MDI) Applications

Creating these applications requires advanced programming expertise and knowledge of the Win32 routines API. Such applications call certain library routines and requires the statement USE DFWIN and usually USE DFLIB. SDI applications display a single window, whereas MDI application can display multiple windows (a main frame window with one or more child windows that appear within the frame window).

For example, select the MDI option from the Fortran AppWizard screen. After you build and run the application (without changing the source files), the following screen might appear after you create two child window by clicking New from the File menu twice:

fortran appwizard mdi sample

If you selected the SDI option from the Fortran AppWizard screen and built and ran the application, you could not create child windows within the main window.

For more information:


Dialog-Based Applications

Dialog applications use a dialog box for the application's main window. Creating these applications requires some knowledge of the Win32 routines API, but considerably less than for a SDI or MDI application. These applications call certain Visual Fortran library routines and requires the statements USE DFWIN and USE DFLOGM. Dialog-based applications usually do not have menus.

For example, select the Dialog-based applications from the Fortran AppWizard screen. After you build and run the application (without changing the source files), the following dialog box appears:

fortran appwizard dialog-based sample

For more information: