4
votes

I have a problem with Inno Setup.

I'm using resolution detection script in [Code] section from here:
INNO Setup: How to get the primary monitor's resolution?

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"

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...

Can someone help me and explain how to do that?
I'm newbie with Inno Setup, and especially with Pascal.

1
Out of interest, why can't the application get this information itself? After all, it may change by the time the application is run, or at any time after that.Deanna

1 Answers

4
votes

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 '[email protected] 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;