Inno Setup界面拉伸

1、源起:

源于一个安装包的广告定制。广告客服提供的图片太大,inno setup默认尺寸容不下它,需要扩充,拉宽安装界面尺寸。

以inno setup所附带例子说事,其默认尺寸如下:

 

2、ScaleX

核心函数为ScaleX,其原型如下:

function ScaleX(X: Integer): Integer;

作用为适应DPI,给指定的X值在X方向上做缩放。同理有ScaleY,本例用不到。

 

3、实现代码

Inno Setup中,写自定义函数,横向缩放窗体及其所属控件,并分类调整控件位置及宽度,完成界面缩放。

[Code] 
//横向拉伸长度const EXPAND_VALUE = 128; //遍历控件改其宽度 procedure ExpandPageControl(AControl: TWinControl); var i: Integer; ctrl: TControl; wc: TWinControl; begin for i := 0 to AControl.ControlCount - 1 do begin ctrl := AControl.Controls[i]; if (ctrl is TBitmapImage) and (ctrl <> WizardForm.WizardSmallBitmapImage) then Continue; if (ctrl is TButton) or (ctrl is TBitmapImage)then ctrl.Left := ctrl.Left + ScaleX(EXPAND_VALUE) else ctrl.Width := ctrl.Width + ScaleX(EXPAND_VALUE); if ctrl is TWinControl then begin wc := ctrl as TWinControl; if wc.ControlCount <> 0 then ExpandPageControl(wc); end; end; end; procedure InitializeWizard(); begin with WizardForm do begin Width := Width + ScaleX(EXPAND_VALUE); end; ExpandPageControl(WizardForm); end;

如此就基于WizardForm对安装窗体做X轴上缩放。

 

4、效果

如图示: