What this tutorial is all about
This Win32 tutorial is intended to present to you the basics (and common extras) of writing programs using the Win32 API. The language used is Modula-2, in particular we have also used the several language extensions available in StonyBrook Modula-2.
This tutorial will not teach you the Modula-2 language, nor will it tell you how to run your particular compiler (StonyBrook, XDS, etc...).
If you don't know what a MODULE or a RECORD is, or how a
Sometimes throughout the text I will indicate certain things are IMPORANT to read. Because they screw up so many people, if you don't read it, you'll likely get caught too. The first one is this:
The source provided in the example ZIP file is not optional! I don't include all the code in the text itself, only that which is relevant to whatever I'm currently discussing. In order to see how this code fits in with the rest of the program, you must take a look at the source provided in the ZIP file.
And here's the second one:
Read the whole thing! If you have a question during one section of the tutorial just have a little patience and it might just be answered later on. If you just can't stand the thought of not knowing, at least skim or search (yes computers can do that) the rest of the document before asking in newsgroups or by email.
Another thing to remember is that a question you might have about subject A might end up being answered in a discussion of B or C, or maybe L. So just look around a little.
Ok I think that's all the ranting I have to do for the moment, lets try some actual code.
The simplest Win32 program
If you are a complete beginner lets make sure you are capable of compiling a basic windows application. Slap the following code into your compiler and if all goes well you should get one of the lamest programs ever written.
MODULE test; FROM WINUSER IMPORT MessageBox,MB_OK,MB_ICONEXCLAMATION; VAR res : INTEGER; BEGIN res:=MessageBox(NIL, "Narf!", "Pinky says...", MB_OK BOR MB_ICONEXCLAMATION); END test.
If that doesn't work, your first step is to read whatever errors you get and if you don't understand them, look them up in the help or whatever documents accompany your compiler. Make sure you have specified a Win32 (NOT "Console") project, whatever applies to your compiler. Unfortunately I can't help much with this part either, as errors and how to fix them vary from compiler to compiler (and person to person).
When you succeed in compiling and running this example, we are ready to start.
Copyright © 1998-2011, Brook Miles. All rights reserved. Adapted for Modula-2 by Frank Schoonjans, with permission.