4

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.

Community
  • 1
  • 1
RMD1010
  • 43
  • 1
  • 3
  • 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 Aug 19 '14 at 08:41

1 Answers1

4

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
TLama
  • 75,147
  • 17
  • 214
  • 392
  • P.S. don't forget to uninstall the previous instance of your setup since the settings used in your entries won't overwrite existing values in registry when you install another instance. – TLama Aug 18 '14 at 21:52