┌──────────────────────────────────────────────────────────────────────┐ │To calculate the window coordinate of your execution environment, use │ │WinQuerySysValue and obtain a resolution of the display. │ └──────────────────────────────────────────────────────────────────────┘
DBCS OS/2 supports various display resolutions just like on SBCS OS/2. To draw graphical objects on PS/55 the way they are shown on PS/2, you need to calculates the window coordinate for PS/55. For this purpose, you need to know the display resolution of the run-time environment. Use WinQuerySysValue to obtain its value.
┌──────────────────────────────────────────────────────────────────────┐ │Use GpiQueryFontMetrics to find the font size at the runtime │ │environment. │ └──────────────────────────────────────────────────────────────────────┘
To calculate how many characters you can present in a PM control such as
a list-box, you need to know the width and the height of the current font.
This can be obtained by using GpiQueryFontMetrics.
Calculating a window size (source: MISCMAIN.C)
...
static LONG desk_cx, desk_cy;
...
GetFontSize( hpsMain, &lAveWidth, &lFontHeight );
hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
desk_cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
desk_cy = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
/* set window width to show MAIN_WIN_WIDTH SBCS characters */
cx = (lAveWidth*MAIN_WIN_WIDTH>desk_cx) ? desk_cx : lAveWidth*MAIN_WIN_WIDTH;
/* set window height large enough to show a string pointed to by sText.*/
cy = (((strlen(sText)/MAIN_WIN_WIDTH)+10)*lFontHeight>desk_cy) ?
desk_cy : ((strlen(sText)/MAIN_WIN_WIDTH) + 10)*lFontHeight;
x = (cx<desk_cx) ? (desk_cx-cx)/2 : 0;
y = (cy<desk_cy) ? (desk_cy-cy)/2 : 0;
WinSetWindowPos(hwndFrame,
HWND_BOTTOM,
x, y, cx, cy,
SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);
...
/************************************************/
/* GetFontSize: */
/* Get the following system value from PM APIs. */
/* Average character width */
/* Character height */
/************************************************/
void GetFontSize(HPS hps, LONG *lWidth, LONG *lHeight)
{
FONTMETRICS fm;
GpiQueryFontMetrics(hps, (LONG)sizeof(FONTMETRICS), &fm);
*lWidth = fm.lAveCharWidth;
*lHeight = fm.lMaxBaselineExt + fm.lExternalLeading;
}