|
| DialogUnits To Pixels | 
|
|---|
| How to convert dialogs units in pixels | Product: Delphi all versions | Category: Shell API | Skill Level:
 | Scoring:  | Last Update: 06/06/2003 | Search Keys: delphi delphi3000 article borland vcl code-snippet dialogunits, DialogBaseUnit, PixelsPerInch | Times Scored: 2 | Visits: 2483 | Uploader: Jean Claude Servaye Company: | Reference: N/A | | | Question/Problem/Abstract:
How to convert dialogs units in pixels if the dialog do not use system font | Answer:
function DialogUnitsToPixels(DialogUnits: Integer; Canvas: TCanvas; Font: TFont):Integer;
var
A : Array[0..52] of char;
Z : Integer;
U : Word;
begin
// select the current font
SelectObject(Canvas.Handle,Font.Handle);
// Get DialogBaseUnit for system font
U := HiWord(GetDialogBaseUnits) div 4;
// compute mean width of characters in current font
// as recommended by Microsoft
A := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Z := (Canvas.TextWidth(A) Div 26 + 1) Div 2 ;
// Compute result and adjust for screen resolution
Result := DialogUnits * Z Div U * Screen.PixelsPerInch div 96;
end;
|
|
|
| |
Sign up to consume product discounts for Bronze memberships !
|
|
| |
Community Ad of R. Lefter |
|
| |
|
|
|