home *** CD-ROM | disk | FTP | other *** search
- Fortran For the Windows 3.0 API
- Version 1.00. 04-Jan-1992.
- By Kevin B Black (L_KBB@UK.AC.NWL.VB).
-
- Introduction
- ============
-
- This is a brief startup guide to Windows 3.0 programming using Microsoft
- Fortran version 5.1. You may have found that the `QuickWin' interface is a bit
- of a disappointment, if you were hoping to develop true Windows 3.0 application
- in Fortran. Next, you read in the Advanced Topics manual, page 139, under
- Windows Programming that you can not call the Windows 3.0 applications
- interface directly Fortran (Buying Microsoft C and the SDK could prove
- expensive). Well this does not seem to be true, and this guide (with the
- accompanying files) shows you how to do it.
-
- While reading through these notes, you can think about using the FORTWIN and
- FWCLOCK sources as examples when building your own applications.
-
- Other things you will need
- ==========================
-
- Apart from the Microsoft Fortran version 5.1 compiler, you will also need some
- manuals describing the Windows 3.0 application interface. The manuals supplied
- with Microsoft's Software Development Kit (SDK) are excellent as reference
- manuals, and I believe can be purchased separately from the SDK.
-
- You will probably need some `tools', for example an Icon editor. A Dialogue
- editor is also useful for writing the more complicated applications; although
- creating text based dialogue files can give you more `precision' than a
- Dialogue Editor over the placement of Buttons and text etc. Such tools are
- provided with the SDK, but are also available as Shareware or in the Public
- Domain.
-
- Libraries
- =========
-
- If you have not created Windows libraries for use with Microsoft Fortran, then
- you should do this now. Run the SETUP program again, choose the `Load or build
- additional libraries' option and build libraries for `DOS and Windows'. You
- don't need to create C compatible libraries; unless you are planning on mixed
- language programming. After building the libraries you should find two new
- libraries :
-
- NOQWIN.LIB and LLIBFEW.LIB.
-
- There may be more additional libraries, depending on the options you chose
- during SETUP. I strongly recommend appending the letter C to Fortran libraries
- built for C compatibility. For example :
-
- Fortran C Compatible
- Libraries Libraries
-
- LLIBFEW.LIB LLIBFEWC.LIB
- LLIBFORE.LIB LLIBFEC.LIB
-
- Compiling
- =========
-
- To compile a program that you for use with Windows 3.0, the /Gw switch is
- required, the /MW switch should not be used. An example compilation command is :
-
- FL /c /AH /Zp /FPi /Gw WNDPROC.FOR
-
- Bear in mind that there is no `main' program in a Windows 3.0 application, so
- any code you placed in a main program is not going to get executed. Instead a
- Windows 3.0 application has a subroutine called `WinMain', which is called by
- the Windows 3.0 startup code for the application (this is found in the
- LLIBFEW.LIB library, and is included automatically when you link your program).
-
- If you have not installed the Windows SDK kit, then you will need to add the
- path d:\WINDEV\INCLUDE to your INCLUDE path (or include the path explicitly in
- your source programs). This is so the compiler can find the WINDOWS.FI and
- WINDOWS.FD files, which will have been copied to that directory.
-
- If you do not use IMPLICIT NONE in your program sources, then the /4Yd compiler
- switch is recommended, to force you to declare your variables.
-
- The more free DOS memory available when you are compiling the better, DOS 5.0
- is useful here. Using the `make' utility reduces the heap space available to
- the compiler. This can result in an F1002; Out of heap space compiler error
- during compilation.
-
- Linking
- =======
-
- Once you have compiled your program, and built any necessary resources, then
- you can link it. To do this you need to do several thing. Firstly, you need to
- create a .DEF file, use the FL.DEF (supplied with the Fortran Compiler) or
- FWCLOCK.DEF (supplied with this file) files as templates. Next you will need to
- extract the NOQWIN module from the NOQWIN library, for example :
-
- LIB d:\path_to_fortran_libs\NOQWIN.LIB *noqwin;
-
- You may need to do this before you can build the examples if they are not
- located on the same disk as your compiler, or you installed the compiler in a
- non standard directory. Alternatively you can edit their `make files'. You
- can, of course, place this command in the make or BAT file that you use to
- build your application.
-
- When linking your application, you need to specify the NOQWIN module to
- prevent the QuickWin environment from being loaded, and also the .DEF file to
- create a proper Windows executable. A simple link command would be as follows :
-
- LINK SMALLPRG NOQWIN ,,, /NOD LLIBFEW, SMALLPRG.DEF;
-
- For any non-trivial application a linker `response' file is recommended.
-
- Important Things to be aware of
- ===============================
-
- You need to DEFINE meta-command symbols to include the various Windows
- interface statements and parameters, contained in the WINDOWS.FI and WINDOWS.FD
- file, that you may use in a routine. The reason for this is that if all entries
- are enabled, then the compiler will usually run out of heap space while trying
- to compile your program. Thus it is important to remember to enable those
- functions you wish to use, and that you may not always get a compiler error if
- you forget (and the result is your application will not perform properly). This
- can still be a problem, especially when compiling using the `make' utility. It
- does tend to be caused by the Fortran interface and parameter declarations in
- the WINDOWS.FI and WINDOWS.FD files. Hopefully a future version of the compiler
- will remove this restriction. Failure to enable function declarations should
- show up if you use the IMPLICIT NONE statement, or compile your programs with
- the /4Yd switch. The following table shows which symbols need to be defined to
- enable specific types of Windows function or parameter specifications :
-
- GDICAPMASKS - CC_*, LC_*, PC_*, CP_*, TC_* and RC_
- VIRTUALKEYCODES - VK_*
- WINMESSAGES - WM_*, EM_*, LB_* and CB_*
- WINSTYLES - WS_*, CS_*, ES_*, LBS_*, SBS_* and CBS_*
- SYSMETRICS - SM_*
- MENUS - MF_*
- ICONS - IDI_*
- KEYSTATES - MK_*
- SYSCOMMANDS - SC_*
- RASTEROPS - Binary and Tertiary raster ops
- SHOWWINDOW - SW_*
- OEMRESOURCE - OEM Resource values
- ATOM - Atom Manager routines
- CLIPBOARD - Clipboard routines
- COLOR - Screen colours
- CTLMGR - Control and Dialogue routines
- DRAWTEXT - DrawText() and DT_*
- GDI - All GDI defines and routines
- KERNEL - All KERNEL defines and routines
- USER - All USER defines and routines
- MB - MB_* and MessageBox()
- MEMMGR - GMEM_*, LMEM_*, GHND, LHND, associated routines
- METAFILE - typedef METAFILEPICT
- MSG - typedef MSG and associated routines
- OPENFILE - OpenFile(), OemToAnsi, AnsiToOem and OF_*
- SCROLL - SB_* and scrolling routines
- SOUND - Sound driver routines
- TEXTMETRIC - typedef TEXTMETRIC and associated routines
- WH - SetWindowsHook and WH_*
- WINOFFSETS - GWL_*, GCL_* and associated routines
- COMM - COMM driver routines
- KANJI - Kanji support stuff.
- HELP - Help engine interface.
- PROFILER - Profiler interface.
- DEFERWINDOWPOS - DeferWindowPos routines
-
- ---
-
- One problem encountered during the initial stages of the investigation of
- Windows 3.0 API usage from Fortran was how to deal with the Windows internal
- resource descriptors and the passing of an address or NULL pointer to a Windows
- API function that can also take a user string. A number of ways to overcome
- this are possible, but the one chosen seems to be the most satisfactory way of
- doing it. This is to define two interfaces to the API function. The standard
- version takes a null terminated string. The second (which has _A appended to
- the function name) allows the programmer to specify the address, or an internal
- resource. Thus to load a user defined cursor, the LoadCursor function can be
- invoked as follows :
-
- hCursor=LoadCursor(NULL,'MyCursor'C)
-
- or, if you wanted,
-
- hCursor=LoasCursor_A(NULL,LOCFR('MyCursor'C))
-
- This allows an internal cursor to be load as follows :
-
- hCursor=LoadCursor_A(NULL,IDC_ARROW)
-
- The following functions and subroutines currently have an _A form for some of
- their arguments :
-
- SetDIBits GetDIBits InvalidateRect
- ValidateRect ScrollWindow ScrollDC
- SetProp GetProp LoadCursor
-
- ---
-
- Not all the interfaces currently contained in WINDOWS.FI have been fully
- tested, so if you are having difficulty with some function compare its
- description to one that you know works. Some functions may be missing. But
- examination of the interface statements in WINDOWS.FI and the declarations in
- WINDOWS.FD will show you how to write versions for any missing function.
-
- ---
-
- The names of two parameters clashed with function names (C is case sensitive
- and Fortran is not). These were ExtTextOut and StretchBlt. The parameters were
- renamed as EXT_TEXTOUT and STRETCH_BLT.
-
- ---
-
- The two include files WINDOWS.FI and WINDOWS.FD do not look very neat, they
- have been designed for compactness and speed (during compilation).
-
- ---
-
- There are two ways in which FARPROC parameters to the Windows 3.0 API
- functions are passed, sometime they are Fortran EXTERNAL functions, and some
- times they are the address. For an example, compare the interface statements
- for the MakeProcInstance and FreeProcInstance functions.
-
- ---
-
- You can only run a Fortran application once from the same Windows .EXE
- executable, you can copy the .EXE file to another name and run it again. The
- reason for this strange behaviour of Windows is not known. You would have
- though that it could make its own entirely separate process copy of the
- program, rather than telling you can not run the application more than once.
-
- ---
-
- Sometimes the Fortran errors F3606 and F3607 may occur during compilation
- depending on the usage made of certain Windows functions. These two errors are
- non-fatal, and may not indicate a problem (although this will depend, of
- course, on the code). The Fortran warning F4202 may also occur during
- compilation. For an example of the above, compile the ABOUT module of the
- FWCLOCK application.
-
- Sample Fortran applications
- ===========================
-
- FORTWIN.EXE
-
- FORTWIN.EXE is a Windows Generic application written entirely in Fortran, the
- source code to this is provided with the F4W3API1 kit.
-
- FWCLOCK.EXE
-
- FWCLOCK.EXE is a Windows Clock application written entirely in Fortran, the
- source code to this is provided with the F4W3API1 kit. The TimeZone feature
- has not been implemented; currently it demonstrates the grayed out menu item.
- The colours on the bit map, which is displayed in the `About Box', are not
- set; thus the picture (of me) may look a bit avant-garde.
-
- File list
- =========
-
- The following is a list of files provided in the F4W3API1 distribution kit :
-
- Directory of \WINDEV\FORTRAN
-
- F4W3API DOC 13717 | This file
- SUP FOR 1244 | Functions that cannot be written using `INTERFACE'
-
- Directory of \WINDEV\FORTRAN\FORTWIN
-
- FORTWIN 1202 | Make file for FORTWIN generic application
- FORTWIN CUR 326 | Example cursor image
- FORTWIN DEF 826 | Linker definitions
- FORTWIN EXE 29696 | Windows 3.0 Executable
- FORTWIN FD 153 | Fortran include file, definitions
- FORTWIN FI 828 | Fortran include file, interfaces
- FORTWIN FOR 12935 | Fortran source file
- FORTWIN H 57 | Resource compiler header file
- FORTWIN ICO 766 | Icon images
- FORTWIN RC 687 | Resource compiler source file
- FORTWIN RES 1517 | Resources file
- X BAT 15 | Build all
-
- Directory of C:\WINDEV\FORTRAN\FWCLOCK
-
- ABOUT FOR 2685 | Fortran source for part of FWCLOCK
- DIGIT FOR 10456 | Fortran source
- DOWNTOOL FOR 497 | Fortran source
- DRAWFACE FOR 4575 | Fortran source
- DRAWHOUR FOR 2620 | Fortran source
- DRAWHUB FOR 1201 | Fortran source
- DRAWMINU FOR 2430 | Fortran source
- DRAWSECO FOR 635 | Fortran source
- F BAT 42 | Compile procedure
- FWCLOCK 1453 | Make file for FWCLOCK application
- FWCLOCK BMP 4718 | Bitmap
- FWCLOCK DEF 317 | Linker definitions file
- FWCLOCK EXE 61952 | Windows 3.0 Executable
- FWCLOCK FD 4244 | Fortran include file, definitions
- FWCLOCK FI 460 | Fortran include file, interfaces
- FWCLOCK FOR 5257 | Fortran source
- FWCLOCK H 225 | Resource compiler header file
- FWCLOCK ICO 2038 | Icon images
- FWCLOCK LNK 151 | Linker response file
- FWCLOCK RC 972 | Resource compiler source file
- FWCLOCK RES 7261 | Resources file
- INITFWC FOR 1652 | Fortran source
- RESIZE FOR 1624 | Fortran source
- TOOLUP FOR 658 | Fortran source
- WNDPROC FOR 12991 | Fortran source
- X BAT 15 | Build all
-
- Directory of \WINDEV\INCLUDE
-
- WINDOWS FD 106831 | Windows 3.0 API Fortran definitions, parameters
- WINDOWS FI 70656 | Windows 3.0 API Fortran interface statements
- --------------------------------------------------------------------------------
-