The Codesmith's Library
OS/2 Presentation Manager Programming
Written by Carsten Whimster
In The Codesmith's Library, I focus on development books and materials. I write this column from the point of view of an intermediate programmer. Pick up whichever book strikes your fancy, and join the growing group of people following our programming columns.
Please send me your comments and thoughts so that I can make this column what you want it to be. I read and respond to all mail.
I am still waiting for OS/2 Warp 3.0, and I can hardly contain myself (well...). I have heard much good about it, but also that it is less stable than OS/2 2.11. I'll just have to wait until it arrives before I judge. Meanwhile, I unfortunately sold my OS/2 2.1, so I am running on OS/2 Warp Beta II, which has had its down-sides. I purchased a Promise DC4030VL-2 with 2Mb of cache RAM, but due to driver bugs, I lost my Warp. Later on the card went AWOL, so I had to return it. When the replacement finally came, it was also broken, but I noticed that the packaging had been opened, so I am wondering whether it was the same card. Back to the store it goes, but this time I wrote down the serial number, so I can tell whether the supplier really is giving me a new one. Sigh.
The format I have been using so far in reviewing books requires that I read every line in the whole book, which is very time-consuming, and difficult, considering that I am not an expert in every field. It makes it very difficult for me to evaluate material with which I am not familiar, so I am going to change format slightly. I will concentrate a bit more on filling in the tables at the end of the review accurately, and slightly less on writing a detailed review of every section in every chapter. This lets me skim the material a little more, but still lets you find what you are looking for. Expect the tables to grow a fair amount, and perhaps even change format a bit from time to time.
OS/2 Presentation Manager Programming
OS/2 Presentation Manager Programming is a very thorough introductory PM programming book. Many programmers have been clamouring for this book for a long time, knowing that the author covers his material very well, and writes very lucidly. Well, it is finally here, and these are the chapters:
In addition to a brief history of OS/2, the first three chapters have the obligatory "this is a window, this is how you open it" introduction. What sets it apart from other books is the depth in which the WinCreateWindow call is treated. Many, if not all of the options to this API are listed and explained, which is unusual. The treatment is usually biased towards WinCreateStdWindow instead, so this change is refreshing and educational. By the way, Petzold seems to have made it a habit to pull out the constants when he describes a new call, and explain them as well, including the ones he doesn't actually use. This is a good thing in my opinion, and only some books do that, not all.
Section two describes some of the GPI calls commonly used to do fairly mundane tasks, and also gets into a bit of advanced GPI programming. Those of you who intend to write the next Doom (Copyright 1994 iD Software) should probably wait for the new version of OS/2 Presentation Manager GPI, Winn, or take a look at the new DIVE API, however. The basic lines, curves, and so on are described, and some of the more advanced calls like Bezier splines, paths, and transforms, but do not expect to be able to write the next graphing program after reading this section. Surprisingly, however, he does go into mathematics to explain the various functions, and this makes this advanced section a good GPI introduction for intermediate and advanced programmers. This is probably a section you'll want to come back to when you have mastered more of the rest of the book. Many of the compromises inherent to both raster (pixel) and vector (line) graphics are explained in detail, and you will learn a lot about the basics of graphics programming even you don't actually do any.
Fonts are treated in the GPI section as well, and they are explained in fairly good depth. You should be able to find a solution to most text problems here. The various shears, rotations, and so on are all explained patiently, with many little sample programs. In addition, many different types of shadows and fillings are demonstrated in quite a bit of detail, as is text justification.
Part three covers the keyboard and the mouse, and getting input from them. The keyboard is covered first, not surprisingly. A program called TYPEAWAY is used to demonstrate these concepts. It is basically a brain-damaged editor with a few crucial design flaws, so if you ever wanted to write a word-processor or an editor, this would be a good place to start. The flaws, by the way, are intended.
The mouse material is introduced with a neat program called WEB, which draws lines from the corner of the window to the current mouse position. It is a little gimmicky, but quite a fun little program. It is followed up by another neat little program called CHECKER1 (CHECKER2 for the keyboard enabled version). These programs are basic, but demonstrate how to use the mouse position and buttons to do various things in your client window. CHECKER3 then demonstrates how to use the divide and conquer strategy in your window, and divide the window into sections which each handle their own input. These are followed by programs which keep track of mouse movement, and do something at the same time, i.e. draw blocks the size of a click-and-drag area, and then by a sketching program which draws when you click-and-drag. These are all educational programs which really drive home the point of certain types of interaction.
The last chapter in the input section is the chapter on the timer. Petzold shows both how to set a repeating timer, how to get around the basic timer functionality to set one-time timers, and how to get around the 65.5 second maximum timer duration limit. The logic necessary to distinguish between the timers of cursor blinkers and clock and so on are also demonstrated. A little program which uses a timer to display free memory at fixed intervals is shown, and finally a plain digital clock and an analog clock are shown. The analog clock makes me think that he had a hand in the design of the OS/2 system clock :)
Chapter eleven seems a little out of place in the input section, but since many of the controls are aimed at getting input from the user, it isn't so odd after all. This chapter is fairly basic, and goes through a number of small programs which create buttons, sliders, text, and other small windows. It skips a detailed treatment of the MLE, as well as lists, drop-down lists, text-entry fields and others. Some of these are introduced along the way in the book, but not in any real depth. In fact, now that I look closer at the book, this is the only really serious short-coming of the book that isn't just a matter of opinion. Yes, many of these controls are shown in various examples here and there, but there is no real in-depth treatment anywhere. There really should be a good thick chapter on these things, and that chapter should have been chapter eleven, but isn't. This is the bread and butter type stuff that applications are made of. There is a large section on GPI that most people will never use, but no collection of controls? Hmm, well, onwards we go...
Part four is on using resources such as bitmaps, icons, accelerator keys and so on. It starts out by showing what the various resources are, and how they get into the EXE via the different stages of compilation. This entails explaining resource scripts, which is then promptly done. A couple of examples are given, but without much detail pertaining to the different options.
The next chapter is devoted to menus and accelerator keys. Regular menus, checked/unchecked items, enabled/disabled items, help menus, and accelerators are all demonstrated, but the first example shows how to add items to the system menu. This is called the poor person's menu :) The next example is a nice introductory pop-up menu. This is a nicely thought-out piece with a few items with more than one level to them. The third example has an amusing bitmap as the last item. This bitmap is a cheesy bitmap of a children's handwriting rendition of the word help :) A game called TAQUIN follows (more commonly known as PUZZLE). This game is a good demonstration of a combination of the techniques learned earlier in the book, as it combines menus, graphics, and mouse tracking programming techniques. Finally, a decent implementation of The Game of Life is given. These programs are both interesting and give good real-life examples of menu usage. This is how it should be done.
Chapter fourteen discusses dialog boxes. Dialog boxes aren't the most interesting of PM possibilities, but they are probably the most ubiquitous. There is probably at least one dialog box in almost every PM program ever written! This chapter gives a nice variety of the possible features of a dialog box.
The final section in the book consists of various topics which didn't fit the neat, boxed labels that the other chapters did. An introduction to the clipboard, dynamic link libraries, multi-threaded programs and printing can be found here. Given the importance of multi-threading, I would have liked to see a larger chapter on it, and perhaps the same goes for printing. Multi-threading is a topic which even an introductory volume should have, since it is the key area which differentiates PM from the more mundane Windows API. There is a nice section with a multi-tasking explanation, including the differences between Windows' and OS/2's way of doing things, however.
OS/2 Presentation Manager Programming is a very thorough beginners' book with a lot of emphasis on the comprehension of basic PM calls, and their parameters. It has a good introduction to almost every API call that you are likely to come across initially when learning to program PM, and in addition it has an introduction to some advanced techniques. The advanced material is frequently not covered in any real depth, but some examples are given for the usage of various APIs, and you will learn what type of problems you can solve with the different parts of the PM API. I especially like the little motivational sections given at the start of each chapter, and wished that he had done similarly for each subsection. They really help you understand why you are doing this, and the meat of the chapter then ensures that you really understand how the nuts and bolts work.
I like the fact that the book is divided into sections as well as chapters. It makes it easier to get a good overview, or to skip the heavier sections if you are getting bogged down in something you don't need. Overall, the book is very well organized indeed, and very easy to jump around in. The index is quite good if not perfect, but it is probably the best of any PM programming book I have seen, so guess I'll have to say that this is the mark for potential authors to aim for.
Many of the programs were a little mundane, but in a beginners' book that is inevitable, so I really can't fault it for that. The overriding impression of this book is that of lucid, accurate, and thorough coverage. It isn't as humorous as some, but not as dry as others. It is simply competent, as you would expect from a master of the trade.
The only things I could fault were the use of Windows graphics instead of PM graphics here and there in the figures of the book, and the numerous references to OS/2 2.0 instead of OS/2 2.1. This book is updated for OS/2 2.1, but sometimes you wouldn't know it. MINMAX3 didn't work for me, but that is probably attributable to Warp Beta II which has the occasional glitch in the graphics subsystem. Apart from that, only the lack of in-depth treatment of control windows and common dialog boxes keep it from being perfect.
Overall, this book is rock-solid, and a good start for anyone who hasn't seen or tried GUI programming before. I would rate this a solid A if it wasn't for the lack of depth in the above mentioned fields. Therefore it gets an A-.
OS/2 Presentation Manager Programming, Petzold
Our Bookstore has reviews and links to Amazon for all books we have reviewed in the past, as well as several books waiting to be reviewed, and others which we recommend.