The information below is taken from the Pro Fortran for Windows User Guide.

Windows Programming

This page covers the broad topic of programming for Microsoft Windows using both MRWE and the Win32 API. It covers additional topics of interest such as interfacing with other languages. Where appropriate, sample programs in the C:\Absoft\Examples and C:\Absoft\Examples\Mrwe directories are referenced.

USING MRWE

The MRWE application framework is a special feature of Pro Fortran which can automatically give your program a Microsoft Windows interface with menus, a text window, and a graphics window. Usually, when you want to create applications with windows and menus, you need to know how to use the Win32 API and the Microsoft user-interface guidelines. When you create an application using MRWE, your program will automatically exhibit these features without the need for intensive Windows programming. MRWE is convenient and flexible to use, and can be easily modified to suit your needs.

MRWE is a collection of pre-compiled FORTRAN routines contained in the library file mrwe.lib that you can link with your program. Applications generated by an Absoft compiler are linked with this library when you select MRWE Application as shown in the dialog box below. The FORTRAN source code for MRWE is in the Examples\Mrwe folder and can be used as an example of how to call Win32 API routines.

The Absoft Developer Tools Interface allows you to select the format of the executable file. A Target Type setting of MRWE Application will cause your program to be built as a stand-alone, double-clickable application with MRWE providing a window and menus interface. If your FORTRAN code includes its own Windows message loop and Win32 API calls, you should disable MRWE by choosing Console Application for the Target Type of the executable file.

IDE Screenshot

Absoft compiler dialog box

Examine the Readme file in the Mrwe folder for information regarding file organization and how to build a new MRWE library. The MRWE source code is an excellent example of programming Windows using the Win32 API. It shows how to use multiple windows, scroll bars, menus, text, graphics, the mouse, dialog boxes, and message handling; how to print and save files; and everything else needed in a standard Windows application. The main.f program provided in the MRWE folder shows how to use all of MRWE capabilities; type amake makefile.dev from a command prompt to build it. Feel free to use portions of the MRWE source code in applications of your own that are compiled with Absoft Pro Fortran.

The MRWE Window

When you start a program that has been linked with the MRWE library, you will see a blank window on the screen and, above it, a menu bar, as shown below. This window is where MRWE displays standard output from FORTRAN programs and is where all standard input is typed. It looks like a terminal display, but allows you to see text that has scrolled off the screen.

MRWE Screenshot

The MRWE Application Framework

Standard input and output are preconnected to the FORTRAN I/O units 5, 6, 9 and *. Any of these except * may be connected instead to a file by specifying the unit in an OPEN statement. After closing the file on that unit, the unit will be reconnected to standard input and output.

How Your Program And MRWE Work Together

When your program is started, control is first passed to MRWE, which sets up a Windows environment with menus and a window. After the text window appears, the application begins executing your FORTRAN program. By default, you cannot pull down menus, save the output window, or terminate the application until an I/O statement occurs. Your application is completely dedicated to executing your FORTRAN program at maximum speed.

During any input and output statements (i.e. READ, WRITE, ENCODE, etc.), you can use the menus and their commands. When the program is waiting for you to type standard input, you also have complete control of the menus and normal mouse actions. If you want the ability to save the output window or terminate your application while it is calculating, select the MRWE Events check box (the -N9 compiler option) before compiling the program.

The -N9 compiler option turns on the timer interval feature. Your program will be interrupted at timed intervals to check for Windows messages such as menu selections and mouse activities. The default interval is one-tenth second, which can be changed as described later in this chapter in the Modifying MRWE section. Without the Timer Interval option activated, checking for Windows messages will still occur, but only during FORTRAN input and output statements.

If you did not include the -N9 compiler option when compiling, and your program is executing lengthy calculations that you want to stop, you can regain control by typing the Ctrl, Alt, and Delete keys simultaneously. You will be given an opportunity to close the program. [Caution: Data in files that were open may be lost during this procedure.]

Working With Text in MRWE

An MRWE application is an MDI (Multiple Document Interface) type of application. This means that there is application frame window which can support multiple document windows within that frame. MRWE currently supports two document windows-a text window and a graphics window. The application frame window that appears is named after the FORTRAN application. The text window is initially titled Input/Output, but changes when the text is saved to a file.

You can only type into the window when a READ statement is currently active for standard input (i.e. one of the preconnected units), and only on the last line of the window. Any text that was already in the window when the READ statement began cannot be modified. You can, however, copy any text in the window to the clipboard. Also, when using the extended keyboard, the Home, End, Page Up, and Page Down keys can be used for scrolling. Tab characters (ASCII 9) are expanded into spaces, modulo 8.

The MRWE window has a text limit of 262144 characters in 32768 lines. See the Modifying MRWE section for information changing these parameters.

Working With Graphics in MRWE

By default, the graphics window is not displayed when an MRWE application begins. You must explicitly open the graphics window by referencing the mrwe_Opengraphics function if you wish to use it. The argument list for the mrwe_Opengraphics function is:

logical function mrwe_Opengraphics(x, y, title, mode, draw)

where: x is an integer expression specifying the initial width of the window. If x = 0, the default is 600.
y is an integer expression specifying the initial height of the window. If y = 0, the default is 300.
title is a character expression specifying the title of the window. If title consists of only spaces, the window title is set to "Graphics".
mode is an integer expression specifying the mapping mode to be used in the Device Context (see below). If mode = 0, the mapping mode is set to MM_TEXT.
draw is the name of the subroutine that will be called when MRWE receives an MM_PAINT message (see below). If draw = 0, your program will not respond to MM_PAINT messages.

A Windows Device Context provides a device independent graphics context for your program to draw in. When you draw into a device context, your program does need to be concerned with whether that device is a monitor, a printer, or a plotter ­ the device context handles the necessary transformations.

The mapping mode controls the conversion of logical units to device units (pixels on a monitor, "dots" on a printer). The origin is the upper left corner of the device and positive x is to the right ­ the direction of positive y depends on the mapping mode. The following logical unit mapping modes are available:

MM_TEXT one logical unit is equal to one device unit; positive y is down.
MM_HIENGLISH one logical unit is equal to 0.001 inch; positive y is up.
MM_LOENGLISH one logical unit is equal to 0.01 inch; positive y is up.
MM_HIMETRIC one logical unit is equal to 0.01 millimeter; positive y is up.
MM_LOMETRIC one logical unit is equal to 0.1 millimeter; positive y is up.
MM_TWIPS one logical unit is equal to one twentieth of a printer's point (1/1440 inch); positive y is up.
MM_ANISOTROPIC logical units are mapped to arbitrary units with arbitrary scaled axes. Use SetWindowExtEx and SetViewportExtEx to specify units, scaling, and orientation.
MM_ISOTROPIC logical units are mapped to arbitrary units with equally scaled axes. Use SetWindowExtEx and SetViewportExtEx to specify units, scaling, and orientation.

In Windows, you normally perform your drawing operations in response to a WM_PAINT message (for more information on Windows messages, see Program Organization: FORTRAN vs. Windows). The WM_PAINT message is issued to your program whenever an event transpires that requires your window to be redrawn, such as resizing it or uncovering it. To have your program respond to WM_PAINT messages, register your drawing subroutine with MRWE as the last argument in the reference to mrwe_Opengraphics:

external OnDraw

logical function mrwe_Opengraphics(0, 0, "", MM_HIENGLISH, OnDraw)

Begin your OnDraw function as follows:

subroutine OnDraw(dc)

integer dc

When the MRWE message loop receives a WM_PAINT message, it will perform the necessary drawing initialization and call your subroutine with the handle of the device context. Your subroutine can begin drawing immediately. For example:

integer x, y
record /POINT/ point
 
call MoveToEx(val(dc), val(x), val(y), point)
call LineTo(val(dc), val(x), val(y))

Adding Menu Commands to MRWE

MRWE provides a number of functions for easily adding menu commands, providing routines that respond to user menu selections, and modifying menu items. New menus and menu commands are added to the MRWE default menu (described later).

mrwe_InsertMenu function

Use this function insert a new menu on the menu bar or insert a menu command in an existing menu:

logical function mrwe_InsertMenu(menu,item,flags,title,routine)

where: menu is an integer expression specifying the id of the menu. Menu ids are numbered from 1 on the far left. If item (described next) is 0, indicating a new menu is to be inserted, then menu indicates the id where the new menu will be inserted.
item is an integer expression specifying the insertion point of the command in the menu identified by menu. The first menu command is 1. If item is 0, the mrwe_InsertMenu function will insert a new menu at the position indicated in menu.
flags is an integer expression specifying any special characteristics initially associated with the menu command. See below for a description of the possible values that may be used.
title is a character expression that specifies the title of the new menu or menu command.
routine is the name of the subroutine that will be called when this menu command is chosen.

flags may be any of the following:

MF_CHECKED Places a check mark next to the menu item.
MF_UNCHECKED Does not place a check mark next to the menu item. (default)
MF_ENABLED Enables the menu item so that it can be selected. (default)
MF_DISABLED Disables the menu item so that it cannot be selected, but does not gray it.
MF_GRAYED Disables the menu item so that it cannot be selected and grays it.
MF_SEPARATOR Draws a horizontal dividing line.

mrwe_AppendMenu function

To append a new command to the end of an existing menu, use the function:

logical function mrwe_AppendMenu(menu, flags, title, routine)

where: menu is an integer expression specifying the id of the menu. Menu ids are numbered from 1 on the far left.
flags is an integer expression specifying any special characteristics initially associated with the menu command. See the mrwe_InsertMenu Function section for a description of the possible values that may be used.
title is a character expression that specifies the title of the new menu or menu command.
routine is the name of the subroutine that will be called when this menu command is chosen.

mrwe_CheckMenuItem subroutine

The mrwe_CheckMenuItem subroutine can be used to set or clear a check. The calling sequence is:

subroutine mrwe_CheckMenuItem (menu, item, flags)

where: menu is an integer expression specifying the id of the menu. Menu ids are numbered from 1 on the far left.
item is an integer expression specifying the command in the menu identified by menu. The menu itself is identified with a 0 and the first menu command is 1.
flags is an integer expression specifying either MF_CHECKED or MF_UNCHECKED See the mrwe_InsertMenu Function section for a description of the possible values that may be used

mrwe_EnableMenuItem subroutine

The mrwe_EnableMenuItem subroutine can be used to enable or disable a command. The calling sequence is:

subroutine mrwe_EnableMenuItem (menu, item, flags)

where: menu is an integer expression specifying the id of the menu. Menu ids are numbered from 1 on the far left.
item is an integer expression specifying the command in the menu identified by menu. The menu itself is identified with a 0 and the first menu command is 1.
flags is an integer expression specifying any special characteristics to be associated with the menu command. See the mrwe_InsertMenu Function section for a description of the possible values that may be used.

mrwe_DeleteMenu function

The mrwe_DeleteMenu function can be used to delete an entire menu or a single menu command. The function reference arguments are:

logical function mrwe_DeleteMenu(menu, item)

where: menu is an integer expression specifying the id of the menu. Menu ids are numbered from 1 on the far left.
item is an integer expression specifying the command in the menu identified by menu. The menu itself is identified with a 0 and the first menu command is 1.

Using Timer Functions in MRWE

Timers allow you to execute sections of your program at timed intervals. With timers, you can animate your program, you can save important data to files at regular intervals, and so on. Timers work by sending a WM_TIMER message to the message handler in MRWE. Since MRWE receives all of the messages, your program must be compiled with -N9 compiler option to allow the message loop to be entered periodically.

To install a timer, use the mrwe_SetTimer function:

logical function mrwe_SetTimer(id, timeout, routine)

where: id is an integer expression specifying the id of the timer. This value is also used with mrwe_KillTimer to remove the timer.
timeout is an integer expression specifying the number of milliseconds between timer messages.
routine is the name of the subroutine in your program that will be called when the timeout interval has elapsed.

To remove a time, use the subroutine:

subroutine mrwe_KillTimer(id)

where: id is an integer expression specifying the id of the timer. This must the same value used with mrwe_SetTimer to install the timer.

Using The MRWE Default Menus

An MRWE application automatically has several menus built-in. Following is a description of the commands performed by each item within these default menus.

File Menu

The File menu contains commands for saving the text in the Input/Output window to a file, choosing printers and printer options, printing the text, and exiting the application. Menu Graphic

Save

This command saves the MRWE Input/Output window to a text file. The first time the text is saved, the window title is changed to the file name.

Save As...

This command saves the MRWE Input/Output window to a text file. It displays a standard file dialog prompting for a file name in which to save the text. If the file already exists, you will be prompted to overwrite it. After the text is saved, the window title is changed to the file name.

Print...

To print the contents of the window to the printer, use this menu item. A dialog box is displayed allowing you to choose the printer and set various other print options.

About...

This dialog box displays various parameters of the program execution environment including page size, minimum and maximum memory addresses, and CPU type.

Exit

This command is used to exit the application.

Edit Menu

The Edit menu contains the standard editing commands for cutting, pasting, and copying text. Menu Graphic

Undo (Ctrl+Z)

This command is not used by MRWE and is always disabled (grayed).

Cut (Ctrl+X)

This command removes the selected text from the window and places it on the Clipboard. Text in the Clipboard may be pasted into other applications. Like other editing commands, this command is only available during a READ statement unless the program was compiled with -N9 option.

Copy (Ctrl+C)

The Copy command places the selected text from the window onto the Clipboard and leaves the text of the window unchanged. Text on the Clipboard may be pasted into other applications. Like other editing commands, this command is only available during a READ statement unless the program was compiled with -N9 option.

Paste (Ctrl+V)

This command replaces the selected text in the window with text from the Clipboard. If no text is selected in the window, the Clipboard text is inserted at the insertion point. Like other editing commands, this command is only available during a READ statement unless the program was compiled with -N9 option.

Delete

This command clears the selected text.

 

Window Menu

The Window menu contains the standard editing commands for cutting, pasting, and copying text.

Menu Graphic

Cascade (Shift+F5)

The Cascade command is used to arrange multiple open windows in a overlapped or cascaded manner.

Tile (Shift+F6)

Use this command to tile multiple windows within the MRWE frame.

Arrange Icons

Use the Arrange Icons command to order minimized MRWE window icons.

Modifying MRWE

MRWE is written entirely in FORTRAN and the source code is provided in the directory: C:\Absoft\Examples\Mrwe. There is also a readme file and a makefile supplied to assist you in rebuilding the library if you choose to modify it. To change the maximum number of characters or lines that MRWE can accommodate, edit the mrwe.inc include file and change the PARAMETER statements for the two symbolic constants MAX_CHARS and MAX_LINES. Then rebuild the library with the amake command.

A program linked with the MRWE library normally only checks for Windows messages during Input/Output statements. If you compile your program with the -N9 option (the MRWE Events check box in the compiler graphical interface), the compiler inserts code throughout your program to check if a timer has gone off. If the timer has gone off, a Windows message loop is entered to process any pending messages and then control is returned to your program. You can fine tune the timer for your specific application by including the following COMMON block declaration in your program:

INTEGER mrwe_flag ! check for messages flag
INTEGER mrwe_delay ! delay in milliseconds between checks
INTEGER mrwe_resolution ! resolution of the timer

COMMON /call_mrwe_timer/ mrwe_flag, mrwe_delay, mrwe_resolution

The flag is usually set by the timer interrupt routine, but you can force a check of the message queue by setting mrwe_flag to 1. The default delay is 1/10 of a second (100 milliseconds) and can be changed with the mrwe_delay variable. mrwe_resolution controls the resolution of the interrupt timer.