The system font is used in window components, such as title bars and menus. This font is also used as the default font for graphics text output with several WIN and GPI calls. The following shows the actual sizes of the system fonts of the DBCS PM and the SBCS PM.
This difference of the system font will affect the amount of text which can be displayed in a window. To understand the problem caused by the difference, consider the entry field control as an example. Suppose you want to create an entry field in the client area of a standard window. For example:
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, (PULONG)&flCreate, "MyWindow", "", 0L, NULL, ID_WINDOW, (PHWND)&hwndClient ); /* Setting the window control data of the entry field */ efdata.cb = sizeof( ENTRYFDATA); efdata.cchEditLimit = 20; efdata.ichMinSel = 0; efdata.ichMaxSel = 0; hwndEntry = WinCreateWindow( hwndClient, WC_ENTRYFIELD, (PSZ)NULL, WS_VISIBLE | ES_MARGIN, 200,200, 200,16, /* Size of the entry field */ hwndClient, HWND_TOP, ID_ENTRY, &efdata, NULL);
If you execute this program under the SBCS PM with VGA, the entry field can correctly display the text string in it. The entry field of the same size, however, cannot display the text string correctly under the DBCS PM. The height of the entry field, 16 pels, is not enough to accommodate characters from the system font of the DBCS PM. The upper part of those characters is clipped away. You may modify the above program to avoid this problem as follows:
hwndEntry = WinCreateWindow( hwndClient, WC_ENTRYFIELD, (PSZ)NULL, WS_VISIBLE | ES_MARGIN, 200,200, 200,24, /* Size of the entry field */ hwndClient, HWND_TOP, ID_ENTRY, &efdata, NULL);
This is the easiest way to cope with the above problem. But it is not a good one because 24 pels in height may be a little bit too large for the system font of the SBCS PM. The best way is to dynamically change the size of the entry field. In the following example, the size of the entry field is calculated according to the information given by the DevQueryCaps call.
HDC hdc; ULONG devcaps[2]; hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, (PULONG)&flCreate, "MyWindow", "", 0L, NULL, ID_WINDOW, (PHWND)&hwndClient ); hdc = WinOpenWindowDC( hwndClient); DevQueryCaps( hdc, CAPS_GRAPHICS_CHAR_WIDTH, 2L, devcaps); /* Setting the window control data of the entry field */ efdata.cb = sizeof( ENTRYFDATA); efdata.cchEditLimit = 20; efdata.ichMinSel = 0; efdata.ichMaxSel = 0; hwndEntry = WinCreateWindow( hwndClient, WC_ENTRYFIELD, (PSZ)NULL, WS_VISIBLE | ES_MARGIN, 200,200, devcaps[0] * efdata.cchEditLimit, devcaps[1], hwndClient, HWND_TOP, ID_ENTRY, &efdata, NULL);
In the above example, the first and second elements of the array devcaps contain the default graphics character box width and height in pels respectively. You may consider these values as the width and height of a character in the system font. The actual values of these two elements are the same as the values shown at the beginning of this section. The height of the entry field is calculated according to the height of the character box. In the above example, the width of the entry field is also defined so as to accommodate the maximum number of characters without scrolling.
Besides the entry field control, you must be aware of this difference whenever you use a system-provided control with some text in the client area of a standard window.
When you directly draw some text in a client window, you also have to take into account the difference of the system font size. For example, suppose you draw a couple of strings with the GpiCharStringAt call:
#define STRINGLENGTH 20 CHAR sz1[STRINGLENGTH]; CHAR sz2[STRINGLENGTH]; switch( msg ) { case WM_CREATE: WinLoadString( hab, NULL, IDS_1, STRINGLENGTH, sz1); WinLoadString( hab, NULL, IDS_2, STRINGLENGTH, sz2); hps = WinGetPS(hwnd); GpiQueryFontMetrics( hps, sizeof(FONTMETRICS), &fm); WinReleasePS(hps); break; case WM_PAINT: hps = WinBeginPaint( hwnd, NULL, &rc ); GpiSetColor( hps, SYSCLR_WINDOWTEXT ); GpiSetBackColor( hps, SYSCLR_WINDOW ); GpiSetBackMix( hps, BM_OVERPAINT ); pt.x = 50; pt.y = 100; GpiCharStringAt( hps, &pt, (LONG)strlen( sz1), sz1); pt.y -= fm.lMaxBaselineExt; GpiCharStringAt( hps, &pt, (LONG)strlen( sz2), sz2); WinEndPaint( hps ); break; . . .