Compiling "OS/2 Presentation Manager Programming" Samples on 2016: Difference between revisions
mNo edit summary |
|||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
By [[User:Martini|Martin Iturbide]] | By [[User:Martini|Martin Iturbide]] | ||
==Introduction== | ==Introduction== | ||
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. | |||
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: | My goals are: | ||
* Try (as much as possible) to compile the samples with free / open source available tools. | * Try (as much as possible) to compile the samples with free / open source available tools. | ||
* Try | * Try the most simply way to install the development environment. | ||
* Try also the most simple ways to compile | * Try also the most simple ways to compile these samples. | ||
==Preparing the Development Environment== | ==Preparing the Development Environment== | ||
Line 17: | Line 14: | ||
The easiest way to prepare the environment is using Arca Noae Package Manager [http://www.os2world.com/wiki/index.php/Arca_Noae_Package_Manager] to remotely install the required tools and libraries. | The easiest way to prepare the environment is using Arca Noae Package Manager [http://www.os2world.com/wiki/index.php/Arca_Noae_Package_Manager] to remotely install the required tools and libraries. | ||
Arca Noae Package Manager has a simple WarpIn interface to install it, so it went easy. | 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: | 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 | ash which kbuild gcc gcc-wlink gettext-devel git os2tk45 pthread-devel libxml2-devel libxslt-devel | ||
openssl-devel libcurl-devel zlib-devel libpng-devel libqt4-devel libidl-devel libvncserver-devel | openssl-devel libcurl-devel zlib-devel libpng-devel libqt4-devel libidl-devel libvncserver-devel | ||
nasm libpoll-devel libaio-devel | nasm libpoll-devel libaio-devel | ||
Yes, some of those are not | 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== | ==Checking out the source code== | ||
The source code | The source code was downloaded from Charles' FTP site, or you can do a check-out from Github [https://github.com/OS2World/DEV-SAMPLES-PM-PM_Programing]. If you want to use github check out my other article "[[Using Git under eComStation]]". | ||
==Compiling Chapter 2== | ==Compiling Chapter 2== | ||
Since I don't know much about programming I got help to compile this program from the OS2World forum. | 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. | 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. | 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. | ||
Line 39: | Line 36: | ||
===W.C=== | ===W.C=== | ||
But we start with "W.EXE" it is a program that does not | But we start with "W.EXE" it is a program that does not use PM yet and does not do much. | ||
Look at "W.C" sample: | Look at "W.C" sample: | ||
<PRE> | <PRE> | ||
/*---------------------------------- | /*---------------------------------- | ||
W.C | W.C – A Do-Nothing Program | ||
© Charles Petzold, 1993 | |||
----------------------------------*/ | ----------------------------------*/ | ||
Line 54: | Line 51: | ||
</PRE> | </PRE> | ||
To compile this with the gcc compiler it is as simple as: | To compile this with the gcc compiler, it is as simple as: | ||
gcc -o w.exe w.c w.def | 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. | 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 | Now, just because I'm curious, I'm going to analyse that EXE with [[PMDLL]]. | ||
[[Image:PM-APP-001.png|400px]] | [[Image:PM-APP-001.png|400px]] | ||
Line 71: | Line 68: | ||
<PRE> | <PRE> | ||
/*--------------------------------------------------------- | /*--------------------------------------------------------- | ||
WELCOME.C | WELCOME.C – A Program that Writes to its Client Window | ||
© Charles Petzold, 1993 | |||
---------------------------------------------------------*/ | ---------------------------------------------------------*/ | ||
Line 157: | Line 154: | ||
</PRE> | </PRE> | ||
This program now loads a PM Window creating all the stuff that PM needs. | This program now loads a PM Window, creating all the stuff that PM needs. | ||
You can compile it with gcc by running: | You can compile it with gcc by running: | ||
Line 177: | Line 174: | ||
==Chapter 3== | ==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. | The samples of chapter 3 gets more interesting, since now the same WELCOME sample is modified to do more things with PM windows. | ||
===WELCOME 2=== | ===WELCOME 2=== | ||
Line 210: | Line 207: | ||
On chapter 4 there is the sysvals.exe sample. | 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 | On this sample, I found that I needed to change something to the source code for it to compile. | ||
You need to add: | You need to add inside the code: | ||
#define max(a,b) (((a) > (b)) ? (a) : (b)) | #define max(a,b) (((a) > (b)) ? (a) : (b)) | ||
#define min(a,b) (((a) < (b)) ? (a) : (b)) | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||
Line 220: | Line 217: | ||
You can compile it by: | You can compile it by: | ||
gcc -I. -Zomf -o sysvals.exe sysvals.c sysvals.def 2>&1 | tee out.txt | |||
gcc -I. -Zomf -o | [[image:SYSVALS-SAMPLE.png|400px]] | ||
==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 these samples. | |||
===AltWind=== | |||
You can compile it with: | |||
gcc -I. -Zomf -o altwind.exe altwind.c altwind.def 2>&1 | tee out.txt | |||
[[image:ALTWIND-SAMPLE.png|400px]] | |||
===Colors=== | |||
gcc -I. -Zomf -o colors.exe colors.c colors.def 2>&1 | tee out.txt | |||
[[Image:COLORS-SAMPLE.png|400px]] | |||
===DevCaps=== | |||
gcc -I. -Zomf -o devcaps.exe devcaps.c devcaps.def 2>&1 | tee out.txt | |||
[[Image:DEVCAPS-SAMPLE.PNG|400px]] | |||
[[Category:PM Articles]] | [[Category:PM Articles]] |
Latest revision as of 23:41, 29 July 2022
Introduction
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 these 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 os2tk45 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 was downloaded from Charles' FTP site, or you can do a check-out from Github [2]. 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.
W.C
But we start with "W.EXE" it is a program that does not use PM yet and does not do much. Look at "W.C" sample:
/*---------------------------------- W.C – A Do-Nothing Program © 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 analyse 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.
WELCOME.C
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 © Charles Petzold, 1993 ---------------------------------------------------------*/ #include <os2.h> MRESULT EXPENTRY ClientWndProc (HWND, ULONG, MPARAM, MPARAM) ; 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 ; } MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { 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.
WELCOME 2
You compile it the same way:
gcc -o welcome2.exe welcome2.c welcome2.def
Here it is how it looks like:
WELCOME 3
Also, very easy to compile:
gcc -o welcome3.exe welcome3.c welcome3.def
Here it is how it looks like:
WELCOME 4
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 compile.
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 these samples.
AltWind
You can compile it with:
gcc -I. -Zomf -o altwind.exe altwind.c altwind.def 2>&1 | tee out.txt
Colors
gcc -I. -Zomf -o colors.exe colors.c colors.def 2>&1 | tee out.txt
DevCaps
gcc -I. -Zomf -o devcaps.exe devcaps.c devcaps.def 2>&1 | tee out.txt