Microsoft KB Archive/260154

= PRB: Dialogs For Ported Applications May Look Stretched =

Article ID: 260154

Article Last Modified on 12/27/2003

-

APPLIES TO


 * Microsoft Windows CE Platform Builder 2.12

-



This article was previously published under Q260154



SYMPTOMS
When running an application that was ported from Windows CE 2.11 or earlier to a more recent version of Windows CE, dialogs may appear to be stretched. That is, the layout will appear to have changed causing dialog windows to occupy a larger display area.



CAUSE
Beginning with Windows CE 2.12, GDI reports the size of fonts based on cached information contained in the font. Prior to version 2.12, GDI would calculate the font metrics based on a linear scale. In most cases this change in design would not make a difference in font metrics returned by GDI. But for some fonts, such as Arial 8, the tmHeight value of the TEXTMETRIC structure may differ by one or two units.

The layout of dialog windows and controls is based on the dialog's default font metrics. Because of the difference in calculations for font size, dialog layouts may appear to be stretched.



STATUS
This behavior is by design.



MORE INFORMATION
This may effect any program logic which relies on font metrics, but appears most noticably in dialog boxes because the size of a dialog box is based on the dialog's default font. The mapping from dialog units to device pixels is done by the MapDialogRect API function. The formula for the mapping is described in the Remarks section of the function description for MapDialogRect.

For example, if a dialog box is implemented using Arial 8 and uses MapDialogRect with a rect structure containing {0, 0, 100, 100}, the function will map these dialog units to {0, 0, 150, 150} on Windows CE 2.00. But the same program compiled for Windows CE 2.12 would map this same rectangle to {0, 0, 150, 175}, and would look stretched in the Y dimension.

This behavior is caused by a difference in GetTextMetrics implementation for Windows CE 2.12. The Windows CE 2.00 application will return a tmHeight value of 12 for Arial 8, but in a Windows CE 2.12 application the tmHeight member will be 14. Using the formula described in the documentation for MapDialogRect

Device Y = tmHeight/8 * Dialog Y

For Windows CE 2.0 we get

12/8 * 100 = 150

and for Windows CE 2.12 we get

14/8 * 100 = 175

It is important to note that for an application compiled for Windows CE 2.00, the PE Optional Header information of the EXE image will show a Subsystem version for 2.00. Windows CE 2.12, for backwards compatibility, will detect this version information and treat the font calculation as a linear scale, as it did with Windows CE 2.00. However, marking a 2.11 application as 2.00 to obtain the old dialog mapping behavior is not recommended. The suggested modification is to either use a different font or modify the dialog layout to give the appearance that is desired.

This change was made in the Windows CE 2.12 font algorithm to match the behavior of Windows NT more closely.

