[ Next ]  [ Previous ]   Chapter 9 - III
[ Contents ]  [ Chapter 8: Interfacing with OS/2 Devices ]  [ Chapter 10:  Window Management ]

Window Words

Window words is a fairly simple concept that is fairly easy to implement, but it got a bad rap because it was poorly documented. Every window has a pointer to some memory that contains quite a bit of very interesting information. Such things as window ID, frame flags, window style, and much more are available through window words. Table 9.9 presents three sets of functions that are used to set and query the information.
 
Table 9.9 Data Type Returned From Window Word Functions
Function Data Type Returned
WinQueryWindowUShort USHORT
WinSetWindowUShort  USHORT
WinQueryWindowULong  ULONG
WinSetWindowULong  ULONG
WinQueryWindowPtr  PVOID
WinSetWindowPtr  PVOID

Four bytes of space are reserved in the window word for the programmer. These four bytes can contain any data type that will fit in the space. If more space is needed, the programmer should create his or her own structure and pass a pointer to the structure in the window word.
Specific information from the window word is obtained using QWL_*,. QWS_*, and QWP_* values. These. values are constants that represent the offset into the window word. The L, S. and P indicate the data type that resides at that offset. The programmer-defined data space resides at offset QWL_USER. One note here: The following control windows contain the programmer-defined data area:

The following example modifies the WINDOW program to use a window word to save the window handles and prevent multiple window enumerations in the WM_PAINT processing.
WINWORD.C
WINWORD.MAK
WINWORD.DEF
The structure that contains the window information is defined as follows.

typedef struct   _WININFO
{
   ULONG            ulStructSize;
   BOOL             bStructInit;
   SHORT            sNumWindows;
   HWND             ahwndWindows[10];

} WININFO,*PWININFO;

The first element a window word structure is the size of the structure. The operating system uses this first element if running under OS/2 2.1 or lower. The windowing functions in these versions are 16-bit, and the operating system must 'thunk" the 32-bit memory pointers so the 16-bit parts of the operating system can understand the address. The operating system uses the ulStructSize to see if the memory chunk is placed into 64K boundary. If a boundary is straddled, the memory chunk is placed into a new 64K segment. This requirement goes away in OS/2 Warp, but programmers must be careful if their code will run  on prior OS/2 versions.

Most of the functions in this program should look familiar. The first difference to emerge is WinRegisterClass.

   WinRegisterClass(habAnchor,
                    CLS_CLIENT,
                    ClientWndProc,
                    CS_SIZEREDRAW,
                    sizeof(PVOID));

The last parameter specifics the amount of space to set aside in the user-defined window word each time a window of this class is created. In most cases, the programmer will want o allocate a pointer to a structure that contains all the information to be carried around with the window.

Some initialization is necessary in order to utilize this space, and the best place  for initialization is in the WM_CREATE message. This is the first message that will be sent to a window.

      case  WM_CREATE :
         {
            pWinInfo = (PWININFO)calloc(1,
                                        sizeof(WININFO));
            if (pWinInfo)
               WinSetWindowPtr(hwndWnd,
                               QWL_USER,
                               pWinInfo);
            else
               DisplayError("No memory allocated for pWinInfo");
            break;
         }

The memory for the WININFO structure is allocated, and WinSetWindowPtr   places the pWinInfo pointer at the window word location QWL_USER (otherwise known as offset 0).

            pWinInfo = (PWININFO)WinQueryWindowPtr(hwndWnd,
                                                   QWL_USER);

Instead of enumerating all the windows each time we receive a WM PAINT message, we perform this action only the first time through and set the Boolean initialized flag, bStructInit in the WININFO structure, to TRUE. The next time a WM_PAINT message is received, this flag is checked; if it indicates that the initialization been performed already, the array of window handles in the WININFO structure are used.

Control Windows

At the heart of data input in a Presentation Manager program are many different styles of reusable controls. A control window is a window within a window designed to perform some useful behavior in a consistent manner. The controls available are listed on page 125.

Presentation Parameters

Presentation Manager provides pretty fancy ways to set the color and font of a window-descriptors are called presentation parameters. WinSetPresParam  and WinQueryPresParams  are used to set and query the presentation parameters respectively.

BOOL WinSetPresParam(HWND hwnd,
                     ULONG id,
                     ULONG cbParam,
                     PVOID pbParam);

hwnd is the window for which to set the presentation parameters. id is a constant used to indicate which presentation parameter to set. These values are listed below. cbParam is the size of the presentation parameter data, and pbParam is the actual  presentation parameter data. For examples setting presentation parameters  see Chapter 25, Sliders, and Chapter 26, Font and File Dialogs.

BOOL WinQueryPresParam(HWND hwnd,
                       ULONG id1,
                       ULONG id2,
                       PULONG pulId,
                       ULONG cbBuf,
                       PVOID pbBuf,
                       ULONG fs);

Again, hwnd is the window for which to query the presentation parameters. id1 is the first of the presentation parameter attribute to be queried. id2 is the second of the presentation parameter attribute to be queried. If a window contains both presentation parameter attributes, only the data for id1 is returned. pulId is used on output to indicate which presentation parameter attribute was found. cbBuf is the size of the buffer used to hold the presentation parameter data, and pbBuf is the actual buffer itself. fs is a collection of possible query options which are OR'ed together. Table 9.10 lists the possible values.
 
 
Table 9.10 Options For Presentation Parameter Attribute Queries
Value Description
QPF_NOINHERIT  Presentation parameters are not inherited from the owner of window hwnd. By default, the presentation parameters are inherited.
QPF_ID1CQLORINDEX Indicates id1 is a color index presentation parameter attribute, which needs to be converted to RGB before being passed back in pbBuf.
QPF_ID2CQLORINDEX Indicates id2 is a color index presentation parameter attribute, which needs to be converted to RGB before being passed back in pbBuf.
QPF_PURERGBCOLOR Specifies that either or both id1 and id2 reference an RGB color, and that these must be pure colors.

For an example using WinQueryPresParam,   see Chapter 26.

BOOL WinRemovePresParam(HWND hwnd, ULONG id);

WinRemovePresParam  is used to remove a presentation parameter attribute. hwnd is the window to remove the presentation parameter attribute from. id is the id of the  presentation parameter to remove. The function returns TRUE upon successful completion.
Presentation parameters can also be passed through WinCreateWindow A presentation parameter has an attribute type (PP_*) and a value for the specified attribute. Table 9.11 presents valid attribute types.
 
Table 9.11 Attribute Types
Attribute Type  Description Data Type Value
PP_FOREGROUNDCOLOR Foreground window color  RGB 1L
PP_FOREGROUNDCOLORINDEX Foreground window color  COLOR (LONG) 2L
PP_BACKGROUNDCOLOR Background window color  RGB 3L
PP_BACKGROUNDCOLORINDEX Background window color  COLOR (LONG) 4L
PP_HILITEFOREGROUNDCOLOR Highlighted foreground window  RGB 5L
PP_HILITEFOREGROUNDCOLORINDEX Highlighted foreground window  COLOR (LONG) 6L
PP_HILITEBACKGROUNDCOLOR Highlighted background window color RGB 7L
PP_HILITEBACKGROUNDCOLORINDEX Highlighted background window color COLOR (LONG) 8L
PP_DISABLEDFOREGROUNDCOLOR Disabled foreground window color RGB 9L
PP_DISABLEDFOREGROUNDCOLORINDEX Disabled foreground window color COLOR (LONG) 10L
PP_DISABLEDBACKGROUNDCOLOR Disabled background window color  RGB 11L
PP_DISABLEDBACKGROUNDCOLORINDEX Disabled background window color  COLOR (LONG) 12L
PP_BORDERCOLOR Window border color  RGB 13L
PP_BORDERCOLORINDEX Window border color  COLOR (LONG) 14L
PP_FONTNAMESIZE Window font name and point size PSZ 15L
PP_FONTHANDLE Font handle attribute
16L
PP_RESERVED Reserved attribute
17L
PP_ACTIVECOLOR Active frame window title bar color RGB 18L
PP_ACTIVECOLORINDEX Active frame window title bar color COLOR (LONG) 19L
PP_INACTIVECOLOR Inactive frame window title bar color RGB 20L
PP_INACTIVECOLORINDEX Inactive frame window title bar color COLOR (LONG) 21L
PP_ACTIVETEXTFGNDCOLOR Active text foreground color RGB 22L
PP_ACTIVETEXTFGNDCOLORINDEX Active text foreground color  COLOR (LONG) 23L
PP_ACTIVETEXTBGNDCOLOR Active text background color RGB 24L
PP_ACTIVETEXTBGNDCOLORINDEX Active text background color COLOR (LONG) 25L
PP_INACTIVETEXTFGNDCOLOR Inactive text foreground color RGB 26L
PP_INACTIVETEXTFGNDCOLORINDEX Inactive text foreground color COLOR (LONG) 27L
PP_INACTIVETEXTBGNDCOLOR Inactive text background color RGB 28L
PP_INACTIVETEXTBGNDCOLORINDEX Inactive text background color COLOR (LONG) 29L
PP_SHADOW Color used for drop shadows on certain controls COLOR (LONG) 30L
PP_MENUFOREGROUNDCOLOR Menu foreground color RGB 31L
PP_MENUFOREGROUNDCOLORINDEX Menu foreground color COLOR (LONG) 32L
PP_MENUBACKGROUNDCOLOR Menu background color RGB 33L
PP_MENUBACKGROUNDCOLORINDEX Menu background color COLOR (LONG) 34L
PP_MENUHILITEFGNDCOLOR Menu highlighted foreground color RGB 35L
PP_MENUHILITEFGNDCOLORINDEX Menu highlighted foreground color COLOR (LONG) 36L
PP_MENUHILITEBGNDCOLOR Menu highlighted background color RGB 37L
PP_MENUHILITEBGNDCOLORINDEX Menu highlighted background color COLOR (LONG) 38L
PP_MENUDISABLEDFGNDCOLOR Menu disabled foreground color RGB 39L
PP_MENUDISABLEDFGNDCOLORINDEX Menu disabled foreground color COLOR (LONG) 40L
PP_MENUDISABLEDBGNDCOLOR Menu disabled background color RGB 41L
PP_MENUDISABLEDBGNDCOLORINDEX Menu disabled background color COLOR (LONG) 42L
PP_SHADOWTEXTCOLOR Shadow text color RGB 43L
PP_SHADOWTEXTCOLORINDEX Shadow text color COLOR (LONG) 44L
PP_SHADOWHILITEFGNDCOLOR Shadow highlighted foreground color RGB 45L
PP_SHADOWHILITEFGNDCOLORINDEX Shadow highlighted foreground color COLOR (LONG) 46L
PP_SHADOWHILITEBGNDCOLOR Shadow highlighted background color RGB 47L
PP_SHADOWHILITEBGNDCOLORINDEX Shadow highlighted background color COLOR (LONG) 48L
PP_ICONTEXTBACKGROUNDCOLOR Icon text background color RGB 49L
PP_ICONTEXTBACKGROUNDCOLORINDEX Icon text background color COLOR (LONG) 50L
PP_BORDERLIGHTCOLOR Border light color
51L
PP_BORDERDARKCOLOR Border dark color
52L
PP_BORDER2COLOR Second border color
53L
PP_BORDER2LIGHTCOLOR Second border light color
54L
PP_BORDER2DARKCOLOR Second border dark color
55L
PP_BORDERDEFAULTCOLOR Border default color
56L
PP_FIELDBACKGROUNDCOLOR Field background color
57L
PP_BUTTONBACKGROUNDCOLOR Button background color
58L
PP_BUTTONBORDERLIGHTCOLOR Button border light color
59L
PP_BUTTONBORDERDARKCOLOR Button border dark color
60L
PP_ARROWCOLOR Arrow color
61L
PP_ARROWBORDERLIGHTCOLOR Arrow border light color
62L
PP_ARROWBORDERDARKCOLOR Arrow border dark color
63L
PP_ARROWDISABLEDCOLOR Arrow disabled color
64L
PP_CHECKLIGHTCOLOR Check light color
65L
PP_CHECKMIDDLECOLOR Check middle color
66L
PP_CHECKDARKCOLOR Check dark color
67L
PP_PAGEFOREGROUNDCOLOR Page foreground color
68L
PP_PAGEBACKGROUNDCOLOR Page background color
69L
PP_MAJORTABFOREGROUNDCOLOR Major tab foreground color
70L
PP_MAJORTABBACKGROUNDCOLOR Major tab background color
71L
PP_MINORTABFOREGROUNDCOLOR Minor tab foreground color
72L
PP_MINORTABBACKGROUNDCOLOR Minor tab background color
73L
PP_ values 0x100 - 0x012F are reserved for bidirectional language support
PP_BIDI_FIRST

 0x0100L
PP_BIDI_LAST

0x012FL
PP_USER This is a user-defined presentation parameter. 
0x8000L


[ Next ] [ Previous ]   Chapter 9 - III
[ Contents ]  [ Chapter 8: Interfacing with OS/2 Devices ]  [ Chapter 10: Window Management ]