Programming for the OS/2 PM in C:Introduction

Index -- Introduction Continues >>

(Note: I was unable to find the original English piece of this section. This is an translation using Google Translate)

Part I: Introduction
Given that a series of articles intended for OS/2 Presentation of the program, two things you need to mention at the outset.

The first is that the issues raised in the C language I use, because it is the most obvious of reasons. One that is very popular these days, and the IBM documentation issued by a large part of the C language refers. For its part, the Watcom 10.0 C/C++ compiler is chosen. In the shops you can buy a variety of development systems for OS/2, in which services, reservation in their hardware requirements differ. All agree, however, that comprise the basic OS/2 programming props (proper header files (header files) and libraries (library)).

I have chosen it to the Watcom because it supports multiple platforms, perhaps the most widely used OS/2 compiler generated code, provides integrated development interface, which greatly facilitates the initial compilation and debugging programs. Thus, the longer each sample program, the above code snippet compiler to apply, but that does not mean that the programs may not be used with any other system. However, try to avoid the Watcom-specific elements, but despite this, the compilation of problems, I am confident that the correction will not cause a big problem. (A typical example is the header file name: mem.h some systems, while others, such as VisualAge C++ - memory.h.)

The other thing is that I assume the part of the reader's familiarity with the C language, so I will not elaborate on step by step analysis of the code-only solution to the problem of OS/2 aspects.

Topics
I thought of a strike direction, which will follow hereinafter. I attempted to try to go beyond the simple subject towards the heavier. While the first topic (Presentation Manager Programming) might not be the easiest, but I think many people are interested in it and the other parts also fit well into this environment. Well, then, let's see, what will be discussed?


 * Presentation Manager Programming. The basic concepts, the explanations of each PM, followed by a complete stand-alone application preparation.
 * Control Programming. Direct access to the system, and includes a series of task management (queue and task management), the multi-threading technology (multithreading). There are two parts of a presentation program closes.
 * Other things. DLL handling, powerful multi-threaded programming in the PM application development different presentation (Guidelines, Sybil).

And what is missed:
 * WPS (SOM) programming.
 * Multimedia management.
 * Mixing 16 and 32 bit code.
 * IFS (Installable File System, the file system can be installed) and device driver preparation.

These topics do not write for two reasons: one is that most of them do not know in detail, and the other that they are very specific things that he wants to focus on something like this, you will learn from the article anyway.

Getting Started!
So as I mentioned in the introduction, start by programming the Presentation Manager. Maybe it would not hurt if I tell the OS/2 structure when the Desktop appears. In this case, in fact, the Workplace Shell (WPS, graphical interface) is running, which is closely based on the OS/2 Presentation Manager is part of the system.

The individual components are well-defined task. The breakdown is as follows: + --- + |       Workplace Shell              | | + - +  | | |         Presentation Manager  |   | | | + +  |   | | | |       OS/2 system        |  |   | +-+-+--+--+---+ The PM is a special DLL functions via (dynamic procedure library), through the PMMERGE.DLL available. It contains a graphical interface to access all the functions required. However, do not be afraid, do not need most of the time (and not even advisable) to contact directly. These functions are accessible via standard libraries, which are compiler program (linker) will then constructed. These features may be accessed, you first need to append (#include) the os2.h. It is a standard header file (header file), which is designed to be given before threading, which functions will be needed. This can be done in #define directive. The system is so configured as an OS/2 is very diverse in terms of programming, so that only the necessary parts are still in the magazine. The hierarchy is designed so that a directive may be necessary to specify other directives are activated, so you want to use the selected function automatically changes to provide the additional functionality required for threaded parts. In addition, the assistance of each function is given, which directive (sometimes directives) should be given to them. The IBM developers introduced a naming strategy, which at first glance can decide that some functions which category. One such category is the set of PM calls with names consistently WIN begins.

To get an IM application to work, the first step is somehow connected to the system, that is, certain steps need to know about the system presence. On the other hand, the application also needs a terminal through which the system can reach. This "terminal" is an anchor block. This process of registration of the application (registration) is called, to which the WinInitialize function must be used. Here you do not need to remember that we all wanted the PM called resource reference (handle) to identify which type is LONG. That this feature is available, you need to #define INCL_WINWINDOWMGR definition or os2.h header. The function receives one parameter, namely zero, and returns a reference to anchor block, which are subsequently used. If the registration fails for some reason, the function returns NULLHANDLE. When the program is complete, it is advisable to discontinue the relationship WinTerminate call, which was previously a reference parameter receives the return value is 1 if the connection has been successfully completed, 0 if an error occurs.

The following smart software does not do anything else than register yourself and then, if the operation was successful, terminate the connection (otherwise it would not be eliminated, as is coming up). FOAM foam; BOOL rc; void main (void) {        // Initiate registration Foam WinInitialize = (0); // Return Value Test if (NULLHANDLE Foam ==) { fprintf (stderr, "WinInitialize failed\n"); Else {} // Remove entry if (WinTerminate (Foam)) { fprintf (stderr, "WinTerminate failed\n"); }        } }
 * 1) define INCL_WINWINDOWMGR
 * 2) include
 * 1) Include

The next step before I make a little detour to the spiritual world of window systems in the direction of exploration. These systems (OS/2, Win3.x, WinNT, Win95) in common is that each of the participants (applications and windows) with each other and with the system called messages (message) to communicate. There is always some kind of centralized control, which manages and controls such messages. For example, using the keyboard or mouse are all in the form of a message to get to the applications. From these show that each application window even necessary that there be some entry point through which the messages to arrive. These entry points to the window procedure (window procedure) is called. These functions are generally of a "case" structure to respond to different messages. For ease of reference systems for each window is assigned standard function by default, so you only need the programmer to select another one if you want to implement a different default behaviour. This could occur when an input field is required, which accepts only numbers. At this point in the input field to implement this function is to change the window to capture all keyboard input and suppress those that do not arise from pushing down number keys, the default message to the rest of the function (because the system is given by the messaging functions can always be called).

So the next step is to somehow connect to the message system. This WinCreateMsgQueue call can be made. The function parameter of the WinInitialize call as a foam (anchor block references), and the maximum size of the queue. The return value is the message queue (message queue) reference, if an error occurred, the return value NULLHANDLE. To use this function you have to give the definition #define INCL_WINMESSAGEMGR. The maximum size of the array define how many messages you want to keep up the line. If set to zero, the default value 10 is used. The function call when it comes to the system, we need a line, which then forward the messages. This is because the system messages come and go rapidly enough to allow the majority of cases are not able to respond promptly to the event program (event). In such a case it is necessary that the messages are stored somewhere temporarily, from which they can be extracted in time and can be processed. Again, a small digression is needed: what is the line? Only very loosely: as a series of files, can read and write, in addition to the FIFO principle is used, so the data can be received in the same order to remove. The message that comes up is made, which makes the messages into the system, the application you are Extracts.

Now if we look at the previous enlargements of the above program: FOAM foam; BOOL rc; HMQ hmq; void main (void) {        // Initiate registration Foam WinInitialize = (0); // Return Value Test if (NULLHANDLE Foam ==) { fprintf (stderr, "WinInitialize failed\n"); exit (1); }        // Create Message hmq WinCreateMsgQueue = (foam, 0); if (== hmq NULLHANDLE) {                fprintf (stderr, "WinCreateMsgQueue failed\n"); }        // Remove entry if (WinTerminate (Foam)) { fprintf (stderr, "WinTerminate failed\n"); } }
 * 1) Define INCL_WINMESSAGEMGR /* Message Window Functions */
 * 2) Define INCL_WINWINDOWMGR /* Window Manager Functions */
 * 3) Include
 * 1) Include
 * 2) Include

As it turned out the code, you create a message queue do not have to be closed because the system automatically changes to the program established by the series ends.

Now, the program formed above the initial application, which contains all the necessary steps and can not be neglected, which is a start of the application to be PM.

When you run the program, nothing seems to happen, but this is natural because it does not set up any window. In the next section we move and create an application that has a main window that already shows up, so will the fruit of our work places.

Index -- Introduction Continues >>