Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Win App example in CVF - A Guide to Creating Windows Apps. 1

Status
Not open for further replies.

TommyCee

Civil/Environmental
Nov 6, 2009
13
This is my first post to Eng-Tips.

I'm trying to come up to speed in creating simple Windows apps associated w/ Fortran routines and am using Compaq Visual Fortran v6.6.

I am using the book:
Compaq Visual Fortran - A Guide to Creating Windows Applications by Norman Lawrence (2002).

In Chapter 6 (Creating Win32 API Applications) ) are instructions for creating a simple app that displays "Hello Win". This is a Fortran Windows App. using the Single Document Interface (SDI).

Initially, the instruction is to load CVF, then do File|New and choose Fortran Windows Application, then SDI. The rudimentary project gets created and compiles/builds fine to display the About box on execution.

Then we want to add code to HelloWin.f90 to create a simple message that will be displayed on the screen. The only declarations listed (to be added to MainWndProc) are these:

Code:
integer(4) hDC
integer(2) nDrawX
integer(2) nDrawY
type (T_PAINTSTRUCT) ps
type (T_RECT) rc
character (256) FileBuf

Then, this case is to be added immediately (after Select Case (mesg):
Code:
[b]case (WM_PAINT)[/b]
  ! Get pixel dimensions of Client Area
  ret = GetClientRect(hWnd, rc)
  ! Set up a display context to begin painting
  hDC = BeginPaint (hWnd, ps)
  FileBuf = "Hello from Win32!"C
  ret = DrawText(hdc, FileBuf, lstrlen(FileBuf), rc, DT_CENTER)
  FileBuf = "And Again Hello World from Win32!"C
  nDrawY = rc%bottom/2 ! pixels to vertical center
  nDrawX = rc%right/2 ! pixels to horizontal center
  ! Set coordinates of TextOut to be center of text string
  ret = SetTextAlign(hDC, TA_Center)
  ret = TextOut (hDC, nDrawX, nDrawY, FileBuf,lstrlen(FileBuf))
  ! end painting and release hDC
  ret = EndPaint( hWnd,ps)


When I attempt to compile, 3 error messages trigger:
This name does not have a type, and must have an explicit type.

The messages apply, respectively, to these variables:
lstrlen; SetTextAlign; TextOut

I presumed that these 3 items were "standard" Windows functions. Yet from the the error messages, it appears that these are vars. that need to be declared. (If this is so, it seems strange that this was not directed in the instructions.)

I added this line to the declaration section for MainWndProc:

integer(4) lstrlen, SetTextAlign, TextOut

The good news is that it complied fine. The bad news is that, during Build, several more errors triggered:

error LNK2001: unresolved external symbol _LSTRLEN@8
error LNK2001: unresolved external symbol _SETTEXTALIGN@8
error LNK2001: unresolved external symbol _TEXTOUT@24

These errors again point to the 3 offending variables and it's surprising that the author never addressed this issue in his instructions (and, sadly, there's no way to get a hold of Norman Lawrence, a prof. at the Australian Maritime College).

Any help is appreciated.
 
Replies continue below

Recommended for you

Those are Windows GDI routines. You need to add gdi32.lib to the linker list.
 
Thanks XWB - you were right on. I added:

use kernel32
use gdi32


to function MainWndProc and everything went fine.

I wonder why the author omitted this show-stopping piece.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor