问题描述
我在使用Inno Setup时遇到问题.
I have a problem with Inno Setup.
我在这里的[Code]
部分中使用分辨率检测脚本:
INNO设置:如何获取主显示器的分辨率?
I'm using resolution detection script in [Code]
section from here:
INNO Setup: How to get the primary monitor's resolution?
现在我想将xres
和yres
值放入安装程序的[Registry]
部分,如下所示.
And now I want to put xres
and yres
values to [Registry]
section of my installer which looks like this.
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"
我尝试了此方法如何在Inno Setup吗?,但是我无法正常工作.我尝试过多次自己解决问题,但我放弃了...
I tried this method How to use a Pascal variable in Inno Setup?, but I can't get it work. I tried to solve the problem by myself many times, but I give up...
有人可以帮我解释一下该怎么做吗?
我是Inno Setup的新手,尤其是Pascal.
Can someone help me and explain how to do that?
I'm newbie with Inno Setup, and especially with Pascal.
推荐答案
一种方法可以编写一个 scripted constant
函数,并通过传递的参数返回水平或垂直分辨率.其余的在Inno Setup引擎上:
One way can be writing a single scripted constant
function for both dimensions and by the passed parameter return either horizontal or vertical resolution. The rest is upon Inno Setup engine:
[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;
这篇关于Inno Setup的[Code]部分变量为[Registry]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!