Feedback Search Top Backward Forward
EDM/2

The Codesmith's Library

The Art of OS/2 Warp Programming

Written by Carsten Whimster

 

Introduction

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.

The Art of OS/2 Warp Programming

This month I am finally reviewing the followup to the popular book The Art of OS/2 2.1 C Programming by the same authors. This book adds a lot of new material, and revises some of the old. In fact, the book is about 50% thicker than the old one. Let's have a look at the chapter headings:


1.   Tools
2.   Memory Management
3.   Multitasking
4.   File I/O and Extended Attributes
5.   Interprocess Communication
6.   DLLs
7.   Exception Handling
8.   Interfacing with OS/2 Devices
9.   Introduction to Windows
10.  Window Management
11.  Window Messages and Queues
12.  Resources
13.  Dialog Boxes
14.  Menus
15.  List Boxes
16.  Buttons
17.  Entry Fields
18.  Multiline Edit Controls
19.  Other Window Classes
20.  Drag and Drop
21.  Value Set
22.  Notebook
23.  Containers
24.  Spin Buttons
25.  Sliders
26.  Font and File Dialogs
27.  Subclassing Windows
28.  Presentation Manager Printing
29.  Help Manager
30.  Multithreading in Presentation Manager Applications
Appendix A:  Window Messages
Appendix B:  References
Right off the top, I have to remark how pleased I am to see no-nonsense chapter headings. All to often the chapter names are too cryptic in an attempt to be funny. Sometimes they really are funny, but usually at a loss of comprehension of the content of the titles. Enough said.

The chapter on the Redmondians and the Armonkians is gone! I loved that chapter, but maybe others complained about it? Oh well, but I consider that a loss.

When I reviewed the older version of the book, I asked specifically for certain updates, so I am going to do a running comparison of this book to the old one, in addition to just giving the chapter descriptions.

Chapter one is just a short description of the Toolkit and again, only support for VAC++ has been listed, although there is a description of the compiler switches that are used, so that you can find the similar switches for your own compiler.

Chapter two covers memory management. It gives a brief description of the memory subsystem of OS/2, and then launches into allocating, sub-allocating, and sharing memory. The old "Gotcha!" sections are still here, and I love them as much as I did the first time. Pulling out important notes from the body text is a brilliant idea, as it draws attention to areas that you might otherwise glance over.

In the following chapter, we take a look at multi-tasking. You will have noticed that these first few chapters are not about PM programming at all, but cover basic OS/2 programming issues. This is a great way to lay out a book, I think. In books like Real World Programming for OS/2 2.11, an otherwise brilliant book, one is left to split out this type of information from the sample PM Programs, and this is not always easy. Having it separate is a great idea. Anyhow, multitasking... the various levels of task management in OS/2 are described, followed by scheduling information. Starting, stopping, creating, destroying, suspending, and changing the priority of threads are all explained, somewhat briefly. Another feature of this book is that all the way through the book you will find small reference sections related to the material currently at hand. In this fashion, you will find lists of valid window session types and so on, at the back of chapter three.

In chapter four, file I/O is examined. There is even some extended attribute examples here, unlike most books, as well as numerous clear diagrams. The chapter covers opening, closing, and getting the size of files, as well as other related information. The quality of the diagrams is much better in this book than in the first one. This was one of my specific criticisms originally, and I am glad it has been addressed for this version.

For chapter five, we look into interprocess communication with named pipes, and there is even an example of how to communicate with a DOS program with named pipes. Queues are also explained, and client-server programs given. These various client-server example programs are some of the potentially most powerful additions to this book, depending on what you need to do. I can't recall having seen them in other books, but I could be remembering wrong. Semaphores are also touched on. I believe that the next version of OS/2 will move to spin-locks instead, but for now this is all we have.

Chapter six is entirely new, and I had also requested the addition of this information with the old version. Dynamic link libraries are such a huge deal in OS/2, with most of the operating system itself sitting in various DLLs, so having this chapter is essential for any introductory OS/2 text, in my opinion. In general, the introductory paragraphs of each chapter are very helpful in describing the use of the features described in that same chapter, and this chapter is no exception. Surprisingly though, the chapter then goes on to detail both pure 32-bit DLLs, but also how to call 16-bit DLLs from 32-bit programs, and vice versa. There is a short section on how to load and unload DLLs, and finally a paragraph on optimizing performance.

Exception handling is also new, and a welcome addition. C has no exception handling built in, but OS/2 has provided an extensive system of recovering from various errors, and this is all too often neglected. How to signal and catch exceptions is described, with a guard-page example from memory management.

The third new addition is chapter eight, interfacing with OS/2 devices. A serial interface example is unfortunately the only example, but expecting more in a beginner book is clearly not reasonable, for such an advanced topic. See other EDM/2 articles for more information on this topic.

Window programming finally arrives in chapter nine. Brief descriptions of some of the basic kinds of windows lead us into this chapter, followed by a basic skeleton example. Some macros and parameter explanations ensue as we are introduced to the odd circumstances of window APIs. Of course, it is then necessary to also explain how main windows are created, what they need to exist, and how they are terminated, as well as the relationships between windows, ie. owners, parents, and so on. The coordinate space of windows is demonstrated, and a brief introduction to window painting is given, along with a brief introduction to string handling and windows. The special (and little understood) topic of the proper usage of window words is also touched upon, and the chapter finally wraps up with a word on presentation parameters. This chapter is one of the longer in the book, but I am glad to see that it appears tidier and shorter than in the first book. I had specifically mentioned how hard it was to make it through this chapter in the first book, but that has been addressed now.

Managing windows includes knowing how to make them appear, disappear, be visible or not, and enabling and disabling them. This and more is presented in chapter ten. The interesting technique of subclassing windows is introduced here as well as how to save and restore window positions with the given APIs.

Messages and message queues are introduced next. Much of this material was originally in the window chapter in the old book, and this was part of the reason that this chapter was so heavy before. The new organization allows the reader to absorb it in smaller chunks. The small penalty for this is that things that belong together are introduced apart, but this is a tradeoff well worth it.

Resources is an area that has long frustrated me. The tools in the toolkit for the creation and use of resources are so arcane and inadequate that it is a minor miracle that a riot hasn't broken out. Why don't we have resource tools like Visual Basic, VX-REXX, Vis-Pro REXX, or even VAC++, but for C? This is completely unacceptable to me. Along with this frustration goes the fact that despite the supposed device independence that PM (and Windows and so on) gives us, we still have to mess around with font sizes, and dialog sizes and control sizes and so on for each individual system that our program runs on. Why isn't this stuff automatic? Why is the device independence not device independence? Why do we have to mess around with this junk every time we write a program? When I create a new program, I want to concentrate my coding time on the design of the interface and the guts, not the implementation of the interface. This is one area in which the current paradigm has failed, in my mind. Perhaps this stuff has been sorted out in the display PostScript model of interfaces? Anyhow, this chapter shows you how to work with the current batch of tools.

Dialog boxes get their share of abuse from me too, as they fail in many of the same ways, but nonetheless, they are what we have to work with, and are explained in chapter thirteen. Chapter fourteen moves into an area which is handled somewhat better in PM: menus. The various types of menus are covered, the styles, the resource file, bitmaps in menus, and so on. List boxes are the first true PM control introduced, in chapter fifteen. Setting them up, selecting the first item, painting them, and more are all covered. In chapter sixteen we meet buttons, all five types. These are fairly easy to deal with, and the chapter is short. Chapter seventeen deals with entry fields, which are also fairly easy, and this chapter too is short.

MLEs are a control which are supposed to be a boon to anyone needing to write a program which accepts or displays many lines of data or text, but due to certain bugs and limitations, their use has severe compromises. Why is it that ever since OS/2 2.0 the MLE scrollbar has not been able to handle scrolling to the bottom of a document without shrinking the scrollbar thumb? The list goes on... Suffice it to say that all the serious programmer's editors have home-grown edit controls, or just hardwired code. None use MLEs due to the limitations. On the other hand, MLEs are quite good for simple text editors and other light-duty tasks.

Chapter nineteen covers various other window classes not mentioned so far, such as combo boxes, frames, scrollbars, and more. The treatment is quite cursory, and I would have liked to see more detail here.

Drag and drop is a very powerful, but big and hairy topic. The paradigm is easy to understand from the user perspective, but difficult and tricky to implement. Lots of structures have to be initialized, and lots of things happen when you get into programming drag and drop. The sample program is about ten pages! Much is skeleton code, of course, but that is still sizeable for an introduction. Another twelve page program elaborates a bit on some aspects, followed by a third long program. Make sure that you are sharp when you attempt this.

Value sets are a rarely used, but sometimes useful control. The particular implementation in PM leaves something to be desired, visually, so I suspect that often companies will develop their own. Notebooks, on the other hand, are used in almost every program, so potential PM programmers, pay attention to chapter twenty-two. Note that the new style of notebook tabs in Merlin are automatically used by PM only if certain types of options are chosen, so be careful not to end up with an old-style notebook tab because you chose certain options. This chapter is surprisingly in-depth, but then it is quite an important topic.

Containers are given 60 pages in chapter twenty-three! Given the multitude of options and inherent complexity this is probably necessary, but it is a touch surprising considering the leanness of other chapters, notably chapter nineteen.

Spin buttons are in chapter twenty-four, and sliders in chapter twenty-five, both fairly short, but with one decent example each. System font and file dialogs merit separate treatment, because they are not just other controls, but complete collections of controls, with APIs to handle them. Especially the file dialog has a lot of flexibility built in, and is one of the stronger areas of PM in some senses. The file dialog is a touch more standardized in its normal use, but also receives good depth of treatment.

Now the book changes pace, and moves into some power programmer techniques. Subclassing windows is a fascinating business, and is done for most of the controls, if you are very picky. There is just too much to be picky about, either in the visual aspect, or in missing or odd functionality, for most of the controls, so subclassing them gives you the opportunity to create the perfect control for your own purposes. Superclassing is also possible, but changing the behaviour of existing controls in other programs is a very dangerous business, and this should only be done by hardcore programmers who know what they are doing, and can achieve the effect needed by no other means.

Printing is something that ought to be a non-topic, but it again suffers a bit from a too-liberal PM vision of the relationships between what the screen shows, what memory holds, and what should be on paper. The options are seemingly endless, as you attempt to get the printer to show what is already in your application. This chapter should give you a solid look into this aspect of programming.

The help manager chapter makes its return in chapter twenty-nine, a bit later than the previous book, although it is the penultimate chapter this time, not the final chapter. Setting up help is carefully explained, including accounts of what can go wrong, which is helpful. A brief introduction to IPF is also included.

The final chapter of the book is about multi-threading in PM applications, and this chapter is entirely new. It shows how to set up a basic multi-threaded program, and how to tackle the various sticky issues involved in this. User feedback is also demonstrated, as well as how to synchronize threads. Finally, object windows are discussed.

The Appendices are short references to window messages and other works to read. Even EDM/2 has a reference in this appendix (!), although the location is old and out of date.

Summary

This book is very thorough and a solid introduction to the proficient C programmer who wants to learn PM. If you are not a strong programmer already, you may want to look at other easier books before deciding whether or not this book serves your needs, but if you already have some C experience, and want to learn PM, then this book is for you. It probably covers more than any other book in its genre, yet some of the chapters are surprisingly short. This book includes a disk with sample programs. Most of the issues I had mentioned regarding the first book have been addressed, and I have no hesitation in awarding this book a very solid A.

The Art of OS/2 Warp Programming, Panov, Salomon, Panov

  • John Wiley & Sons, ISBN 0-471-08633-9, $US 44.95, $CAN 62.95.
  • Intended audience: Beginning PM Programmers
  • Mark: A

Reviewed Books

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.