Calculate the Window Coordinates

┌──────────────────────────────────────────────────────────────────────┐
│To calculate the window coordinates of the runtime environment, use   │
│WinQuerySysValue and obtain the resolution of the display.            │
└──────────────────────────────────────────────────────────────────────┘

DBCS IBM OS/2 Warp supports various display resolutions as well as on SBCS IBM OS/2 Warp. To draw graphical objects on the display, an application needs to calculate the window coordinates for the current display.

The examples are shown below. The former shows how the display resolution is queried, and the latter shows how a window is placed in the center of the desktop window.
Querying display resolution (XPRMMAIN.C)

...
/* device information */
long lDevCaps[4];
...
/**********************************************************************/
/* queryDevCapabilities()                                             */
/*   Queries desk top resolution and system default font's size in    */
/*   pels.  The informations are stored in lDevCaps[]                 */
/**********************************************************************/
void queryDevCapabilities( HWND hwndFrame )
{
  HPS hps;
  FONTMETRICS fm;

  /* Query desktop window size in pel */

   lDevCaps[DISP_X] = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);

   lDevCaps[DISP_Y] = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  ...
}

Placing a window in the center of the desktop (XPRMMAIN.C)
/**********************************************************************/
/* putWindowToCenter()                                                */
/*   Places the window in the center of the desk top window.          */
/**********************************************************************/
void putWindowToCenter( HWND hwnd )
{
SWP swpPos;
LONG lPosX, lPosY;

   WinQueryWindowPos( hwnd, &swpPos );
   lPosX = (lDevCaps[DISP_X] - swpPos.cx)/2;
   lPosY = (lDevCaps[DISP_Y] - swpPos.cy)/2;
   WinSetWindowPos( hwnd, HWND_DESKTOP,
                    lPosX, lPosY, swpPos.cx, swpPos.cy,
                    SWP_SHOW | SWP_ACTIVATE | SWP_MOVE );
}


[Back: Preparing a Device-independent Window]
[Next: Few Things About Fonts]