【问题标题】:Inno Setup [Code] section variable to [Registry]Inno Setup [Code] 部分变量到 [Registry]
【发布时间】:2014-08-18 21:11:45
【问题描述】:

我的 Inno 设置有问题。

我在[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。

【问题讨论】:

  • 出于兴趣,为什么应用程序不能自己获取这些信息?毕竟,它可能会在应用程序运行时或之后的任何时间发生变化。

标签: inno-setup


【解决方案1】:

一种方法可以是为两个维度编写单个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;

【讨论】:

  • P.S.不要忘记卸载之前的设置实例,因为在您安装另一个实例时,条目中使用的设置不会覆盖注册表中的现有值。
猜你喜欢
  • 2014-05-06
  • 2016-10-16
  • 1970-01-01
  • 1970-01-01
  • 2021-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-17
相关资源
最近更新 更多