Compiling "OS/2 Presentation Manager Programming" Samples on 2016

From EDM2
Jump to: navigation, search

By Martin Iturbide


This is a quick article about compiling some samples from the OS/2 Presentation Manager Programming from Charles Petzold (1994), but giving the approach on how to compile that samples on eComStation (or OS/2 Warp 4.52) on the 2016 year.

My goals are:

  • Try (as much as possible) to compile the samples with free / open source available tools.
  • Try the most simply way to install the development environment.
  • Try also the most simple ways to compile this samples.

Preparing the Development Environment

On the book it talks about IBM C or Borland, both those programs are old and hard to find for OS/2 now. This is why I'm trying to compile the book PM Samples with free/open source tool that are available online.

The easiest way to prepare the environment is using Arca Noae Package Manager [1] to remotely install the required tools and libraries.

Arca Noae Package Manager has a simple WarpIn interface to install it, so it went easy. I followed the advice of the VirtualBox Port Wiki to install the required software for development on OS/2-eCS.

On Arca Noae Package Manager just select "YUM -> Install" and add the following:

ash which kbuild gcc gcc-wlink gettext-devel git pthread-devel libxml2-devel libxslt-devel 
openssl-devel libcurl-devel zlib-devel libpng-devel libqt4-devel libidl-devel libvncserver-devel 
nasm libpoll-devel libaio-devel 

Yes, some of those are not required for just this samples but I don't want to worry about it right now.

Checking out the source code

The source code can be downloaded from Charles's FTP site [2] (yes it is still there) or you can do a check out from Github [3]. If you want to use github check out my other article "Using Git under eComStation".

Compiling Chapter 2

Since I don't know much about programming I got help to compile this program from the OS2World forum.

Chapter 2 has the "WELCOME" sample that is divided in several steps, Charles named those steps W , WE, WEL, WELC, WELCO, WELCOM, WELCOME. It is the same program that goes evolving according as you go forward in Chapter 2.

WELCOME.EXE is just a PM window program that shows up with a message that says "Welcome to OS/2 2.0 Presentation Manager". That's all.


But we start with "W.EXE" it is a program that does not uses PM yet and does not do much. Look at "W.C" sample:

   W.C -- A Do-Nothing Program
          (c) Charles Petzold, 1993

int main (void)
         return 0 ;

To compile this with the gcc compiler it is as simple as:

gcc -o w.exe w.c w.def

It will work to create the w.exe the app will run, but it does not do anything.

Now, just because I'm curious, I'm going to analyze that EXE with PMDLL.


Look that this program shows that it loads (or requires) the LIBC and the GCC libraries. This obvious because I'm compiling it with GCC, but it is good to know if this is the first time you compile a program.


Now let's look at WELCOME.C, which is the final evolution of the Chapter 2 sample.

   WELCOME.C -- A Program that Writes to its Client Window
                (c) Charles Petzold, 1993

#include <os2.h>


int main (void)
     static CHAR  szClientClass [] = "Welcome1" ;
     static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
                                 FCF_SIZEBORDER    | FCF_MINMAX  |
                                 FCF_SHELLPOSITION | FCF_TASKLIST ;
     HAB          hab ;
     HMQ          hmq ;
     HWND         hwndFrame, hwndClient ;
     QMSG         qmsg ;

     hab = WinInitialize (0) ;
     hmq = WinCreateMsgQueue (hab, 0) ;

     WinRegisterClass (
                    hab,                // Anchor block handle
                    szClientClass,      // Name of class being registered
                    ClientWndProc,      // Window procedure for class
                    CS_SIZEREDRAW,      // Class style
                    0) ;                // Extra bytes to reserve

     hwndFrame = WinCreateStdWindow (
                    HWND_DESKTOP,       // Parent window handle
                    WS_VISIBLE,         // Style of frame window
                    &flFrameFlags,      // Pointer to control data
                    szClientClass,      // Client window class name
                    NULL,               // Title bar text
                    0L,                 // Style of client window
                    0,                  // Module handle for resources
                    0,                  // ID of resources
                    &hwndClient) ;      // Pointer to client window handle

     while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
          WinDispatchMsg (hab, &qmsg) ;

     WinDestroyWindow (hwndFrame) ;
     WinDestroyMsgQueue (hmq) ;
     WinTerminate (hab) ;
     return 0 ;

     static CHAR szText [] = "Welcome to the OS/2 2.0 Presentation Manager!" ;
     HPS         hps;
     RECTL       rcl ;

     switch (msg)
          case WM_CREATE:
               DosBeep (261, 100) ;
               DosBeep (330, 100) ;
               DosBeep (392, 100) ;
               DosBeep (523, 500) ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;

               WinQueryWindowRect (hwnd, &rcl) ;

               WinDrawText (hps, -1, szText, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
                            DT_CENTER | DT_VCENTER | DT_ERASERECT) ;

               WinEndPaint (hps) ;
               return 0 ;

          case WM_DESTROY:
               DosBeep (523, 100) ;
               DosBeep (392, 100) ;
               DosBeep (330, 100) ;
               DosBeep (261, 500) ;
               return 0 ;
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;

This program now loads a PM Window creating all the stuff that PM needs.

You can compile it with gcc by running:

gcc -o welcome.exe welcome.c welcome.def

Now let's check the WELCOME.EXE program with PMDLL.


DOSCALL1.DLL is now used because we are using on the program the DosBeep function and PMWIN.DLL because on this example we are now calling the PM functions which are the Win* ones.

Here is what WELCOME.EXE looks like when you run it.


Not much, right?

Chapter 3

The samples of chapter 3 gets more interesting since now the same WELCOME sample is modified to do more things with PM windows.


You compile it the same way:

gcc -o welcome2.exe welcome2.c welcome2.def

Here it is how it looks like:



Also, very easy to compile:

gcc -o welcome3.exe welcome3.c welcome3.def

Here it is how it looks like:



The same way to compile it:

gcc -o welcome4.exe welcome4.c welcome4.def

Here it is how it looks like:


Chapter 4

On chapter 4 there is the sysvals.exe sample.

On this sample I found that I needed to change something to the source code for it to complile.

You need to add inside the code:

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

Or you can also put the "param.h" file on the folder and included on your source code:

#include "param.h"

You can compile it by:

gcc -I. -Zomf -o sysvals.exe sysvals.c sysvals.def 2>&1 | tee out.txt


Chapter 5

I had checked how to compile each sample. On this case there was not needed to change the source code, but the compiler provides a warning on line 21 on this samples.


You can compile it with:

gcc -I. -Zomf -o altwind.exe altwind.c altwind.def 2>&1 | tee out.txt



gcc -I. -Zomf -o colors.exe colors.c colors.def 2>&1 | tee out.txt



gcc -I. -Zomf -o devcaps.exe devcaps.c devcaps.def 2>&1 | tee out.txt