Intel® Fortran Compiler with Windows-Based Applications

ID 757211
Date 6/30/2025
Public
Document Table of Contents

Understand Code Requirements for Fortran Windowing Applications

General Coding Requirements: WinMain Function and USE Statements

Coding requirements for Fortran Windowing applications include:

  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 Windows Application Programming Interface (API) routines). An interface block for the function declaration can be provided. You must define the following function, with:

    INTEGER(DWORD) function WinMain (hInstance, hPrevInstance, & & lpszCmdLine, nCmdShow)
    use IFWIN
    !DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:”WinMain”  :: WinMain INTEGER(HANDLE), INTENT(IN) :: hInstance, hPrevInstance
    INTEGER(LPVOID), INTENT(IN) :: lpszCmdLine
    INTEGER(DWORD), 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 IFWIN or other appropriate USE statements

    The USE IFWIN statement makes available declarations of constants, derived types and procedure interfaces for much of the Windows API routines, also referred to as the Windows API. The Intel® Fortran Compiler also provides individual modules for the various libraries that make up the Windows API, such as KERNEL32 and USER32. Any Fortran program or subprogram that references declarations from the Windows API must include a USE statement for either IFWIN, which collects all the available modules, or the appropriate subset modules for the Windows API libraries that are used.

    If you want to limit the type of parameters and interfaces for Windows applications or if unresolved references occur when linking your Fortran Windowing application, see the Intel® Fortran Compiler Developer Guide and Reference for information on calling Windows API routines.

  3. Data declarations for the WinMain function arguments.

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

For example, consider the first lines of this sample, which uses free-form source code:

INTEGER(DWORD) function WinMain (hInstance, hPrevInstance, &
& lpszCmdLine, nCmdShow) 
use IFWIN
!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:”WinMain”  :: WinMain
INTEGER(HANDLE), INTENT(IN) :: hInstance, hPrevInstance
INTEGER(LPVOID), INTENT(IN) :: lpszCmdLine
INTEGER(DWORD), INTENT(IN) :: nCmdShow  
 .
 .
 .

IFWIN.F90 includes a Fortran version (a subset) of the Windows WINDOWS.H header file.

Code Generation Options Using the Fortran Windowing Application Wizard

When you choose the Fortran Windowing Application project type, you will need to select the type of project.

The following choices are available:

  • Empty project

  • Single Document Interface (SDI) sample code

  • Multiple Document Interface (MDI) sample code

  • Dialog-based sample code

  • SDI ActiveX* sample code

  • MDI ActiveX sample code

  • Dialog-based ActiveX sample code

The ActiveX AppWizards will add additional template code for supporting ActiveX controls in your dialog boxes.

Single Document Interface or Multiple Document Interface Sample Code

Creating these types of application requires advanced programming expertise and knowledge of the Windows routines API. Such applications call certain library routines and require the statement USE IFWIN. 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), a screen might appear after you create two child windows by clicking New from the File menu twice.

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 Sample Code

Dialog applications use a dialog box for the application's main window. Creating these applications requires some knowledge of the Windows routines API, but considerably less than for a SDI or MDI application. These applications call certain Intel® Fortran library routines and require the statement USE IFLOGM. 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), a dialog box appears.

You can use dialogs in any project type. Dialogs do not require the use of a windowing application if you are using the module IFLOGM.