WINDOWS ROAD MAP
~~~~~~~~~~~~~~~~
The major problem facing experienced programmers who come from the DOS
environment into Windows is the apparent complexity of the startup code.

This is mainly due to the difference between operating systems. When you
start a program in DOS, you own the whole screen and can print to it in
text mode or draw on it in graphics mode with almost no limitations except
those imposed by the operating system which is limited memory and limited
speed.

The 640k limit of application memory and the speed limits of DOS 16 bit
segmented architecture drove the development of more powerful operating
systems into the 32 bit architecture that we have today.

With the changes in hardware where high speed processors and large
quantities of memory are available at only a fraction of the cost of just
a few years ago, running a DOS program often meant using only a small
percentage of the computer's power but with the same set of limitations.

The additional capacity of Windows is mainly what makes the startup code
more complex. Multitasking means applications must live together while
running at the same time so the operating system controls the computer
while providing access to its functions.

A normal window created by the operating system for an application can be
resized, can run multiple copies of itself, can have child windows that
can be opened and closed and can have many different types of facilities
added to it at very little increase in size and overhead. Writing this
type of code in DOS is a nightmare and the performance is nowhere as good
as the capacity of a 32 bit multitasking operating system.

HOW ITS DONE
~~~~~~~~~~~~
When you use a compiler, various things are done in code at low level
before you get to see any code of your own. What follows is the type of
code that sets up the conditions for a normal programming language
compiler. This code fragment (written in MASM) shows how the startup code
is done and how the normal WinMain function entry is created.

        start:
        invoke GetModuleHandle, NULL    ; get module handle and
        mov    hInstance,eax            ; put it into a variable

        invoke GetCommandLine           ; get address of command line
        mov    CommandLine,eax          ; and put it into a variable

        invoke WinMain,hInstance,       ; the instance handle
                       NULL,            ; unused 16 bit win parameter
                       CommandLine,     ; command line address
                       SW_SHOWDEFAULT   ; constant for window size.

        invoke ExitProcess,eax          ; exit process with WinMain
                                        ; return value

PowerBASIC actually does more than this because it provides the dynamic
allocation for basic strings but the logic is still the same, the startup
code for a compiled program is a WinMain function called by the assembler
startup code.

Where you start as a programmer using a compiler is by writing a WinMain
function and the necessary supporting functions to get your application
going.

The advantage of using a basic compiler is not just that it is easier to
write code for, the dynamic allocation which takes about 4k of overhead
gives PowerBASIC an unusual advantage over other traditional languages
such as C, C++ and Pascal.

While some programmers from the other traditional languages have tried to
be patronising about the performance of basic, most of them have not seen
a dialect of basic sinse the days of ROM basic on an IBM PC and they forget
just how bad the old C and Pascal compilers were.

Mention alocating strings on the fly, converting them to numeric values,
formatting them for currency and reconverting them back to string data and
they do not know what you are talking about, their languages have great
difficulty doing the type of work that is routine for basic programmers.

The dialect of basic in pbdll50 has a very broad capacity in that it can
use any of the internal windows function (APIs), it has a complete and
powerful dialect of basic and it has a very advanced inline assembler
capacity where the assembler can be mixed with normal basic code on a line
by line basis. 

Gone are the days when you had to write a loop with code such as,

x& = x& + 1

just use,

! inc x&

its faster and takes less typing. If you need to increment a counter in a
loop by a larger number, instead of,

x& = x& + 5

you just use

! add x&, 5

There are many little tricks that make you code easier and faster to write
when the language you use has a lot of power.

Open up the basic source code in the file called GENERIC.BAS and you will
find a generic windows WinMain() function with the necessary support
functions such as the message handling procedure called WndProc().

The minimum operating system requirements are commented to explain what
they do and the experienced DOS programmer will find that the coding to
write a basic windows program is actually simpler than trying to write
anything like the same capacity in DOS. 
---------------------------------------------------------------------------
Steve Hutchesson < hutch@pbq.com.au>
Sydney
Australia
