Feedback Search Top Backward Forward
EDM/2

The Codesmith's Library

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.

Errata

The OS/2 API Project is coming along nicely, with a fairly settled format, and more than 15 APIs on site, as well as over 75 #define's. Have a look, and if you have the time, chip in by writing up one or more APIs and sending them to me. The more people help out, the quicker this project will become very helpful. Currently we have an online version on the Web, a zipped HTML version, with an INF version coming very soon. Check out the guidelines for submission at:

http://www.iqpac.com/edm2/os2api/index.html

In case you don't know what this is all about, it is the project of, so far, four people who decided to start documenting the entire OS/2 API and distribute it as a free document, to help out people who can't afford the IBM documentation, or have something better to spend their money on. I figure it can only help the number of OS/2 programs out there if more people have access to this information.

OS/2 Warp Presentation Manager for Power Programmers

Here is a brand-new book which covers many advanced techniques, and has several interesting and challenging programs to demonstrate concepts with:

  1. Welcome to the Presentation Manager for Power Programmers
  2. Gaining Control: Mastering the Standard PM Control Windows
  3. Mastering the Keyboard Interface and Scrolling Functionality
  4. Building a Better Mousetrap: Taming the Mouse in PM
  5. SOS for PM Developers: Help Management through the Information Presentation Facility
  6. Getting More Power for Your Program: Using OS/2's Multithreading Capabilities
  7. She Sells Sea Shells: Programming the Workplace Shell
  8. Mastering Dialogs, Menus and Other PM Resources
  9. Communication Between Applications Using PM's Dynamic Data Exchange Protocol
  10. Getting to the Head of the Class: Understanding Subclassing
  11. Improving Your Control: Using the Advanced OS/2 Controls
  12. Containing Your Excitement: Making Use of the Container Control
  13. What's New with OS/2: Getting a Look at the Multimedia Controls
  14. PM, Your Kingdom Awaits: Creating Your Own Controls
  15. Win, Lose, or Draw: The Art of Drawing Bitmaps
  16. Getting It in Print: Mastering Fonts and Printing
  17. Captain Hook Lives: Mastering PM Hooks

The source code for this book is on Wiley's FTP site, but when I ran the installation program, only the directories were created, no files. The installation program returned RC=11, but claimed success? Finally, the program ended on a SYS3175 in PMMERGE.DLL. Perhaps FixPack 17 has something to do with this? Not a good start. Eventually, I unzipped each chapter into its own directory and all was well. Thank goodness for standard formats.

This is probably the first and the only book for which typing out the chapter headings took longer than writing the review [grin]. The first chapter is merely an introduction to the book, covering a few basics on the way. Such topics as PM initialization, messages, threads, queues, semaphores, memory, resources, windows, hangs, and debugging are touched on lightly here. Mostly, the purpose is just to introduce the later material, but also to ensure that you start out on the right foot with the right attitudes. The emphasis is just on correct design, and equally importantly, the comprehension of what PM can and cannot do, and how to use it best.

Chapter two introduces the BUTTONS utility as a helper to demonstrate a few points. The layout of this chapter is a little unusual in that concepts aren't introduced in some kind of easiest item first order, since the authors expect you to already know PM programming. Rather, things are introduced as is convenient for the sake of explaining the application. Since the basics are not covered, this may come across slightly chaotically, because the text seems to jump here and there. Eventually, the structure is very loose, but each separate tip has its own section. This book is almost more like a collection of powerful tips than a structured advanced programmer's book. Chapter two covers subjects related to what the authors call the "standard PM controls", which includes static text, buttons, entry fields, MLEs, list boxes, combo boxes, and spin buttons. Not all of these are covered here, but there are a lot of tips for buttons, some for creating windows, a bit on statics and listboxes, a section on starting other processes, manipulating icons in executables, using and removing frame controls, and setting title bars to more than 60 characters.

Chapter three introduces advanced concepts relating to both the keyboard, and maintaining a text buffer, both with an MLE, and also the hard way. A quick reintroduction to the way WM_CHARs are handled is given, and then some standard skeleton-type code for handling the different types of WM_CHAR flags, such as KC_SHIFT, KC_CTRL and so on. There are a number of different cursors attributes available to let you show the user exactly what you are up to, and to allow the user to choose according to their preferences. These include CURSOR_SOLID, CURSOR_FRAME, CURSOR and more. When you code for a client window and text, you need to create a cursor, and show it. Some interesting and efficient ways of updating a screen full of text are shown, using WinInvalidateRect, WinDrawText and other APIs. Then the focus shifts to covering scroll bars. Styles, notification messages, and how to use them effectively. Both maintaining the scroll bar thumb size correctly, and also how to actually scroll your text. There is a snippet here with a line of C code that I can only characterize as weird. The line is "sDLines = (-1) * sLinesPerPage;". Why the multiplication, rather than a negation? Hopefully an optimizing compiler would get rid of that one. Every once in a while I get the feeling that the code has been updated, and there are some funny inconsistencies here and there. Nothing serious or confusing, but just variable names that don't match the text and things like that. Hmm. Finally, processing the directional keys is described, along with painting the window.

In chapter four, the mouse is thoroughly discussed. It all starts out with an introduction, and quickly moves on to understanding the system values for the pointer, including the position, visibility, and so on. Changing this visibility is fairly easy, so the discussion moves on to capturing the mouse pointer. What does "capturing the pointer" mean? When you have captured the pointer, you will receive ALL the mouse messages, even outside of your own window. Showing the mouse pointer is as easy as hiding it, so we now move on to study how to obtain pointer information. This includes how to know where the pointer currently is. The WM_MOUSEMOVE message is studied through a simple drawing program, and customizing the pointer is touched upon. The chapter ends with a brief mention of how to place bitmaps into the clipboard.

Help is the subject of chapter five, but since most books on PM programming cover this topic, this chapter moves very quickly. Most of the standard topics are covered, as well as a very brief mention of multi-threading and help, and mutiple frame window considerations. Multi-threading is then covered in much more depth in chapter six. This is accomplished through a neat example which takes a typical single-threaded program and multi-threads it in a couple of different ways, getting progressively more complicated and more well done. Initially, the only addition to the program is a couple of lines which peek at the message queue. This is enough if you have a lengthy calculation which takes place in a tight loop. When other messages are waiting, they will be serviced soon enough. This really isn't multi- threading though, and the next step is to create a second thread. Finally, using an object window is demonstrated.

Workplace Shell programming is next on our agenda. Direct manipulation is briefly discussed and then drag-and- drop is covered in detail. The various structures needed are all taken apart here, after which string handles are explained. Following this, a real code example is given. This includes rendering the object, of course, after which Warp's new pickup-and-drop support is explained. After this, INI files surprisingly make their appearance in this chapter. They are used for storing WPS settings, granted, but they are so much more useful than just for this. In any case, they are given a through treatment here. Finally SOM and DSOM are explained, albeit without code.

Resouces are covered next, with an emphasis on dialogs and menus. All types of menus are explained here, including replacing the system menu. There is no code for bitmap menus, though. Accelerator keys are discussed briefly before diving into dialog programming. The standard file dialog is explained before moving on to regular dialogs. A brief treatment of tabstops and groups is given, after which sizing a dialog is explained. Due to the differences between regular windows and dialogs, this is accomplished in a different manner than usual, but it is quite easy. Finally, a common error in setting the focus is given a solution.

Dynamic Data Exchange (DDE) is the topic of chapter nine, and interestingly, the sample code handles DDE between a PM program and a Windows program. The whole chapter basically works its way through the various code needed to accomplish this. A chapter on subclassing follows. Subclassing is usually avoided by novice programmers as being too difficult and esoteric, but in reality it is very powerful and quite easy. The authors go about demonstrating this in their usual manner. Subclassing a container to put a background bitmap into it is the first example, followed by subclassing an entry field to allow numerical entry only. Creating a new class through subclassing is next and last.

Using the newer OS/2 controls gets its own chapter in this book. Notebooks are covered first, starting with a discussion of notebook styles. There are some small errors in the sample code here, with some mismatching procedure names, but nothing too confusing. Getting dialogs onto notebook pages is amply covered, after which we move onto value sets. Initialization, processing of input, direct manipulation, and owner draw varieties all have appearances. Then we move to the linear slider. This is quite a flexible tool, and should be used in place of scroll bars wherever possible. This includes RGB-type windows, progress indicators and so on. With the capability of turning off the slider button, this is probably one of the most diverse controls in OS/2. Circular sliders have also made their way into the standard Warp API, although they had their start in the MMOS2 world, as volume buttons and so on.

The container control now gets its own chapter. The various views and data structures are lengthily discussed. The data structures probably are some of the most elaborate in OS/2. Loading data and handling user input are both here. In chapter thirteen we take a look at some more multimedia controls. The graphic button includes animation features, which should yield some neat apps once people start using them. This control was originally created to handle the play button in the various multimedia players. These buttons change appearance when clicked and when held down. There are many more messages available for these buttons than for the normal pushbuttons. Secondary windows are now touched on, with examples included. Secondary windows are like a cross between dialogs and regular windows. This can be quite handy when you don't necessarily need a fancy window, but a dialog is too inflexible.

Chapter fourteen was surprisingly simple, after I had managed to raise my expectations too high. Creating your own controls from scratch is not nearly as difficult as it could have been, and I hope that lots of people buy this book and do exactly that. After you have declared the various message you will offer, there really isn't too much left, other than to code the control.

Handling bitmaps is a tricky area of PM programming, but the authors do their best to demystify this topic in chapter fifteen. There are some questionable examples near the start, but again, the errors are obvious and don't obscure the meaning. The new bitmap formats are mentioned in some detail. The sample application is presented after a cursory introduction to presentation spaces and bitblitting. It changes the desktop bitmap, yet another code sample which many people have attempted. Obtaining the screen resolution is also demonstrated, and requires a surprising amount of trickery.

Chapter sixteen is on printing, another one of the more often neglected aspects of programming for OS/2. Font selection and detection, text drawing, and some aspects of the GPI are discussed before launching into printing. In chapter seventeen, the last chapter, PM hooks are explained. Here is another one of the rarely used, but very powerful techniques available to the PM programmer. The sample program here is a rudimentary screen capture program, implemented with all the hook code in a DLL. One of the procedures is called DisableThreeFingerSalute, and I will leave the purpose of this function as an exercise for the reader. Many types of hooks are discussed here, including some that really are not intended to be used.

The appendix discusses how to obtain the code from the book from Wiley's FTP site. This is a neat idea that would eliminate the inclusion of diskettes in programming books, but for this to work right, you must be on the Internet. In the near future, this will be a non-issue.

Summary

While I wasn't crazy about the long chapter titles, I really can think of very little else to criticize, except for the installation routine, the occasional glitches, and perhaps the standard OS/2 tome's tendency to shut itself on you. O'Reilly-style binding, where art thou? I swear these people have been looking over my shoulder to write this book. The first sample program is similar to a program I have been working on from time to time. Lots of powerful techniques and helpful hints. Every graduate of OS/2 Presentation Manager Programming, The Art of OS/2 2.1/Warp C Programming, and Real World Programming for OS/2 2.1 (or 2.11) should continue with this book.

OS/2 Warp Presentation Manager for Power Programmers, Stern and Morrow

  • John Wiley & Sons, Inc., ISBN 0-471-05839-4 (pbk), $34.95US, $48.95CAN.
  • Intermediate and Advanced PM C 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.