Scaling Controls - Project JEDI Wiki

Scaling Controls

From Project JEDI Wiki

Jump to: navigation, search

Contents


[edit] About scaling controls

Since Windows 95 (and maybe Windows 3.1), Microsoft provides information about device contexts. They can be retrieved by the GetDeviceCaps API. The LOGPIXELSX and LOGPIXELSY information are the number of pixel per inch for the given device context. The users of a computer have the power to changes the number of pixel per inch for the desktop, to avoid glitches because of rounding errors in arithmetic operations on integer operands; this setting is not automatically applied on controls. It is the programmer’s responsibility to read this information and to accordingly scale the dimensions and positions of the controls.


[edit] Scaling VCL controls

The VCL can handle most of the resizing operations. They are applied when the form is initialized from a stream (in most cases stored as DFM data). Each form can be configured to be scaled or not by setting its “Scaled” property.

If a form is not scaled, its dimensions will be equals (in pixel numbers) when they are displayed on users’ computer to its dimension on the development computer. This is the simplest case, but the application looks bad when the user sets a different pixel per inch up. There are two ways to prevent a form to be scaled: setting the “Scaled” property to “False” or storing its “Width” and “Height” properties.

If a form is scaled, its dimensions are adjusted at run-time by the ratio:

local pixel per inch/developer pixel per inch

There may be some problems because of rounding errors on integer operands (controls being too small to display all their content, controls being too close to another one…), the form has to be tested on a computer with large fonts to validate its ability to be scaled. For a scaled form, the properties being stored in the DFM file are different: the scaled property is not stored (because it defaults to “True”), the “PixelsPerInch” property contains the setting for the developer machine and its “ClientWidth” and “ClientHeight” dimensions are stored.


[edit] Converting a form to be scaled

That can be done using a text editor on the DFM file:

1. If they are stored, the “Width” and “Height” properties have to be converted to “ClientWidth” and “ClientHeight”

 ClientWidth = Width – 2 * BorderSize
 ClientHeight = Height – 2 * BorderSize – TitleBarSize
 BorderSize = SM_C?FIXEDFRAME (If BorderStyle is bsSingle, bsDialog, bsToolWindow)
 BorderSize = CM_C?SIZEFRAME (If BorderStyle is bsSizeable, bsSizeToolWin)  
 TitleBarSize = SM_CYCAPTION (If BorderStyle is bsSingle, bsSizeable, bsDialog)
 TitleBarSize = SM_CYSMCAPTION (If BorderStyle is bsToolWindow, bsSizeToolWin)

Windows type SM_C?FIXEDFRAME SM_C?SIZEFRAME SM_CYCAPTION SM_CYSMCAPTION
Windows XP themed 3 4 26 18
Windows XP not themed 3 4 19 16
Windows 98 3 4 19 16

2. The “Scaled” property has to be deleted or set to True.

3. The “PixelsPerInch” property has to be set to the local value (96 if the font size is 100%)

[edit] External links

Personal tools
Navigation
Project JEDI
Code Library
Visual Component Library
Version Control System
Math Library
Code Formatter