2016-09-12 3 views
1

파스칼 스크립트에서 문자열의 너비와 높이를 얻을 수 있습니까?Inno Setup 파스칼 스크립트에서 문자열의 너비와 높이 가져 오기

예 : 여기

var 
    S: String; 

S := 'ThisIsMyStringToBeChecked' 

I는 현재의 폰트 크기와 폰트에 따른 높이 및 폭을 반환해야한다.

How to get TextWidth of string (without Canvas)?을 읽었지 만 Inno Setup Pascal 코드로 변환 할 수 없습니다.

나는 캡션의 문자열의 폭이 TLabel.Width을 초과 할 때이 측정 (폭과 높이) clRed'Too Long To Display' 같은 TLabel.Caption을 변경하고 싶습니다.

미리 감사드립니다. TNewStaticText (안 TLabel)에 대한

답변

1

다음 작품 :

type 
    TSize = record 
    cx, cy: Integer; 
    end; 

function GetTextExtentPoint32(hdc: THandle; s: string; c: Integer; 
    var Size: TSize): Boolean; 
    external '[email protected] stdcall'; 
function GetDC(hWnd: THandle): THandle; 
    external '[email protected] stdcall'; 
function SelectObject(hdc: THandle; hgdiobj: THandle): THandle; 
    external '[email protected] stdcall'; 

procedure SmartSetCaption(L: TNewStaticText; Caption: string); 
var 
    hdc: THandle; 
    Size: TSize; 
    OldFont: THandle; 
begin 
    hdc := GetDC(L.Handle); 
    OldFont := SelectObject(hdc, L.Font.Handle); 
    GetTextExtentPoint32(hdc, Caption, Length(Caption), Size); 
    SelectObject(hdc, OldFont); 

    if Size.cx > L.Width then 
    begin 
    L.Font.Color := clRed; 
    L.Caption := 'Too long to display'; 
    end 
    else 
    begin 
    L.ParentFont := True; 
    L.Caption := Caption; 
    end; 
end; 
+0

브릴리언트는 ......... 잘 작동합니다. 그러나 나는 왜 이것이 TLabel과 함께 작동하지 않을지 알고 싶습니다. – GTAVLover

+0

'TLabel'은'TWinControl'이 아니기 때문에'.Handle'을 가지고 있지 않습니다. TLabel의 코드는 다소 달라야합니다. 아마도, 대신에'WizardForm.Handle'을 사용할 수도 있고,'nil'을'GetDC'에 전달할 수도 있습니다. –

+0

다시 한번 감사드립니다 ....... ;-) – GTAVLover

관련 문제