Detect Inno Setup WizardForm Caption font, font size and font color, and center the WizardForm header

I need to find what it Font.Coloris Font.Sizeand Font.NameInno Setup WizardForm.Captionto get it (It String) using GetTextExtentPoint32.

Please let me know how I can find the above WizardForm properties. (Not system font properties). I want to get the current WizardForm font information according to the .cjstyles Skin I'm using.

And I also like to know how to center the title of the wizard window using Pascal Script, knowing the font information.

Thanks at Advance.

+1
source share
2 answers

, .

ISSkin. Windows , Windows API.

ISSkin - .

+2

WizardForm ISSkin.DLL Visual Styles Skin. , " ", " " , :

- Segoe UI 10

ISSKin.DLL Visual, .INI , LoadSkin, , .

procedure LoadSkin(lpszPath: String; lpszIniFileName: String);

.INI, , , Skin , Bitmpas, Skin File.


WizardForm Caption, .

:

Resource Hacker, (Caption) .

1. (.cjstyles .msstyles). Resource Hacker TEXTFILE.

2. .INI , ISSkin.dll. , 100% ( ), . .INI , NORMAL , :

, Elegance.cjstyles,.INI NORMALELEGANCE_INI - , NORMAL.

3. .INI Resource Hacker Window.Caption, :

enter image description here

4. , ContentAlignment Center. , Center.

ISSkin.DLL.

. , , .


Pascal Script [Code]:

WizardForm Caption, ( ).

, , , .

[Code]
Type
  TSize = Record
    cx, cy: Integer;
end;

function GetTextExtentPoint32(hdc: THandle; s: string; c: Integer; var Size: TSize): Boolean;
    external 'GetTextExtentPoint32W@Gdi32.dll stdcall';
function GetDC(hWnd: THandle): THandle;
    external 'GetDC@User32.dll stdcall';
function SelectObject(hdc: THandle; hgdiobj: THandle): THandle;
    external 'SelectObject@Gdi32.dll stdcall';

function AlignStringToCenter(S: String; const FontName: String; const MaxWidth, FontSize: Integer): String;
var
  SWidth, SX, NSWidth: Integer;
  SFont, SHandle: THandle;
  StringModifier: TNewStaticText;
  StringDimensions: TSize;
  SHandleEx: TForm;
begin
  if S = '' then
    RaiseException('The specified Caption is an empty String')
  else begin
    Try
      SHandleEx := TForm.Create(nil);
      StringModifier := TNewStaticText.Create(SHandleEx);
      StringModifier.Font.Name := FontName;
      StringModifier.Font.Size := FontSize;
      StringModifier.Parent := SHandleEx;
      SX := 0;
      StringModifier.Caption := S;
      SHandle := GetDC(StringModifier.Handle);
      SFont := SelectObject(SHandle, StringModifier.Font.Handle);
      GetTextExtentPoint32(SHandle, StringModifier.Caption, Length(StringModifier.Caption), StringDimensions);
      SelectObject(SHandle, SFont);
      SWidth := StringDimensions.cx;
      Repeat
        Insert(' ', S, SX);
        StringModifier.Caption := S;
        Result := S;
        SHandle := GetDC(StringModifier.Handle);
        SFont := SelectObject(SHandle, StringModifier.Font.Handle);
        GetTextExtentPoint32(SHandle, StringModifier.Caption, Length(StringModifier.Caption), StringDimensions);
        SelectObject(SHandle, SFont);
        NSWidth := StringDimensions.cx;
        SX := SX + 1;
      Until (NSWidth - SWidth) >= (MaxWidth - NSWidth);
    Finally
      StringModifier.Caption := '';
      StringModifier.Free;
      SHandleEx.Free;
      SHandleEx.Close;
    end;
  end;
end;

, , , , , .

. MaxWidth , String. , , , . , , .

:

, :

Visual Ctyles Skin:

[Code]
Const
  SM_CYSIZEFRAME = 33;
  SM_CXSMICON = 49;

function GetSystemMetrics(nIndex : Integer): Integer;  
  external 'GetSystemMetrics@User32 stdcall';

procedure InitializeWizard;
begin
  { MaxWidth = WizardForm.Width - 2 * (WizardForm.FrameWidth + WizardForm.SmallIconWidth + WizardForm.CaptionLeft + WizardForm.CaptionRight) }
  WizardForm.Caption := AlignStringToCenter(WizardForm.Caption, 'Segoe UI', WizardForm.Width - (2 * (GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CXSMICON) + 10 + 10)), 9);
end;

Visual Styles:

[Code]
Const
  SM_CYSIZEFRAME = 33;
  SM_CXSMICON = 49;

function GetSystemMetrics(nIndex : Integer): Integer;  
  external 'GetSystemMetrics@User32 stdcall';

procedure InitializeWizard;
begin
  { MaxWidth = WizardForm.Width - 2 * (WizardForm.FrameWidth + WizardForm.SmallIconWidth + WizardForm.CaptionLeft + WizardForm.CaptionRight) }
  WizardForm.Caption := AlignStringToCenter('Setup - {#MyAppName}', 'Window Title Font Name of your Visual Styles Skin', WizardForm.Width - (2 * (GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CXSMICON) + 10 + 10)), Window Title Font Size of your Visual Styles Skin);
end;

:

enter image description here

( ) Windows:

enter image description here

. WizardForm.CaptionLeft CaptionRight , .

+1

Source: https://habr.com/ru/post/1651384/


All Articles