Four Quick Steps to Windows Applications Programming with FORTRAN

( For beginners, programmers under MS-DOS and mainframes )

Starting point - MS-DOS/mainframe/console application


!  ConsoleApp.f90 
!
!  FUNCTIONS:
!   ConsoleApp      - Entry point of console application.
!
!****************************************************************************
!  PROGRAM: ConsoleApp
!  PURPOSE:  Entry point for the console application.
!****************************************************************************

program ConsoleApp
integer*4 N
real*8    x0,x1,step_x,sum,xi
real*8    func
open(unit=1,file='results.txt')
open(unit=2,file='input_data.txt')
    read(2,*) N
    write(1,"('Number of nodes in mesh =',i3)") N
    read(2,*) x0,x1
    write(1,"('Interval [x0,x1] = [',g12.5,1x,',',g12.5,']')") x0,x1
    step_x = (x1-x0)/dfloat(N-1)
    NM = N - 1
    sum = 0.0d0
    do j=1,NM
        xi  = x0 + dfloat(j-1)*step_x
        sum = sum + func(xi)*step_x
    enddo
    write(1,"('Integral =',g12.5)") sum
close(2)
close(1)
stop
end program ConsoleApp
!****************************************************************************
!
!  function: func
!
!****************************************************************************
real*8 function func(xi)
real*8 xi
    func = 2.0d0*xi + 1.0d0
return
end

This program uses data from the file input_data.txt.
The results are stored in the file results.txt.

This trivial/simple program generates next "standard" output on your screen:

and you could download all necessary files ( complete project ) to check out this situation.


Step 1. First and trivial Windows application.

       Now I would like to suggest the first trivial approach to construction of your first (very simple) Windows application on
the base of previous console application. This application differs from the previous console program by that it already can
to utilize full memory of your computer like standard Windows application, so it is already application under Windows. 
This program does not produce any output on the screen, therefore, utilizing such approach, it will be difficult for you 
to understand, whether your program has completed calculations or not. In our particular case we know, that the program 
works very fast and can not have any problems because of complexity of selected algorithm (cycling etc.), therefore 
appearance of the file of results is the sufficient index that it was completed successfully.
      So, if your starting view 
changed, and now it looks like
then it means that your program has completed the work.
Subscribers ( ONLY ) could look at the sources of this trivial Windows application, in order
to understand how to modify initial console application for work as Windows
application. Also they could to download complete project of this application.
 All other readers could download the executable module of this sample.

Step 2. Inserting the notifications.

     After first step  you already know how to modify your initial console application into
the form of simplest Windows application. But the program, which keeps silence, looks like
not convenient choice for any programmer... Now we insert some notifications from the program
without big jump into the depths of Windows programming technology.
     Now, after the start of slightly modified program from step 1, you'll see the next window:
Its appearance helps you to understand the current state of your program and allows you to
make the choice.
If program has completed the calculations, then next window will appear:
It means that you could visit the directory with results for their analysis.
Subscribers ( ONLY ) could look at the sources of this simplest Windows application. 
Also they could to download complete project of this application.
 All other readers could download the executable module of this sample.

Step 3. Inserting the window into Windows application.

      Now you already have Windows application, which can use all available memory
of your computer. But it looks strange, because you don't see the operating system
"standard feature" - window... To be "traditional", we insert now the standard Windows
object - window - into our program. It doesn't look like small jump from step 2, because
it was necessary for us to introduce some new blocks into the program ( for window's
classes, for messages dispatching, for window function...). But the presence of your
initial code for integral calculation allows you to understand how the form and place of
your console application changed during its transformation into more adequate form
of Windows application.
Now, if you selected the "Run.." button, the next window will appear:
It means that you can visit your disk for results analysis, but it's not necessary
for you to leave the application - after the results analysis, you could to start it
again and again...
Subscribers ( ONLY ) could look at the sources of this simple Windows application. 
Also they could to download complete project of this application.
 All other readers could download the executable module of this sample.

Step 4. "I want to interact with my program" - inserting controls.

    Now we understand the principles of Windows application construction, but our
application (Steps 2,3) works in "semi-silent" mode - we can start it and can receive
the notification that calculations were accomplished. Now we want to improve our
program, to speed up the process of different variants collecting for different sets
of problem's parameters. Really, we need to have some dialog with application, which
will allow us to forget about the file with initial data. So  we're ready to insert controls 
( small child windows inside our main window ), where the input data will be available 
for browse/edit. Actually, we already inserted some controls ( namely, two buttons ),
but these ones served as management tools for application life control. Below you
could see the main window ( with some controls inside ) of our new program, which
works now without using of input file.


I inserted into this program some additional features, which perform some analysis
of input data and recommend you to correct the problem, if incorrect data appear.
You could see these features trying to insert the incorrect data into respective
field(s).
Now, if you selected the "Run.." button, the next window will appear:
It means that you can visit your disk for results analysis, but it's not necessary
for you to leave the application - after the results analysis, you could to start it
again and again...
Subscribers ( ONLY ) could look at the sources of this simple Windows application. 
Also they could to download complete project of this application.
 All other readers could download the executable module of this sample.

Next steps in GUI programming.

Your next steps in GUI programming depends on your fantasy only. Microsoft Windows
provide too many possibilities for cool design, so the only problem arises - how to understand
and to apply these treasures in your program. Some ideas/templates you could find in
"Downloads" section of my site, and other ideas will come to you with experience in
future with Microsoft Platform SDK.