Inno Setup [Code]部分变量到[Registry]

时间:2014-08-18 21:11:46

标签: inno-setup

我对Inno Setup有疑问。

我在[Code]部分使用分辨率检测脚本:
INNO Setup: How to get the primary monitor's resolution?

现在我想将xresyres值添加到我的安装程序的[Registry]部分,看起来像这样。

Root: HKCU; Subkey: "Software\MyApp\Settings"; Flags: uninsdeletekey; ValueType: dword; \
    ValueName: "ScreenWidth"; ValueData: "XRES"
Root: HKCU; Subkey: "Software\MyApp\Settings"; Flags: uninsdeletekey; ValueType: dword; \
    ValueName: "ScreenHeight"; ValueData: "YRES"

我尝试了这种方法How to use a Pascal variable in Inno Setup?,但我无法让它发挥作用。我试图自己多次解决这个问题,但我放弃了......

有人可以帮助我并解释如何做到这一点吗? 我是Inno Setup的新手,尤其是Pascal。

1 个答案:

答案 0 :(得分:3)

一种方法是为两个维度编写单个scripted constant函数,并通过传递的参数返回水平或垂直分辨率。剩下的就是Inno Setup引擎:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Registry]
; the GetResolution function used in the following {code:...} scripted constants
; takes as parameter X to retrieve horizontal resolution, Y to retrieve vertical
Root: HKCU; Subkey: "Software\MyApp\Settings"; Flags: uninsdeletekey; ValueType: dword; \
   ValueName: "ScreenWidth"; ValueData: "{code:GetResolution|X}"
Root: HKCU; Subkey: "Software\MyApp\Settings"; Flags: uninsdeletekey; ValueType: dword; \
    ValueName: "ScreenHeight"; ValueData: "{code:GetResolution|Y}"
[Code]
function GetSystemMetrics(nIndex: Integer): Integer;
  external 'GetSystemMetrics@user32.dll stdcall';

const
  SM_CXSCREEN = 0;
  SM_CYSCREEN = 1;

function GetResolution(Param: string): string;
begin
  // in the {code:...} constant function call we are passing either
  // X or Y char to its parameter (here it is the Param parameter),
  // so let's decide which dimension we return by the Param's first
  // char (uppercased to allow passing even small x and y)
  case UpperCase(Param[1]) of
    'X': Result := IntToStr(GetSystemMetrics(SM_CXSCREEN));
    'Y': Result := IntToStr(GetSystemMetrics(SM_CYSCREEN));
  end;
end;