INNO Setup: How to get the primary monitor's resolution?

后端 未结 2 2012
情话喂你
情话喂你 2021-01-15 05:13

I\'m trying to script an installer with INNO and I am stuck at a point where I need to get the screen resolution of the machine in which the setup is running and use that va

2条回答
  •  情深已故
    2021-01-15 05:30

    My solution to this was to use GetSystemMetrics(), which can be found in user32.dll. This piece of code gives me exactly what I want and has been tested on Windows7 Professional (64-bit) with a dual-monitor setup.

    [Code]
    function GetSystemMetrics (nIndex: Integer): Integer;
      external 'GetSystemMetrics@User32.dll stdcall setuponly';
    
    Const
        SM_CXSCREEN = 0; // The enum-value for getting the width of the cient area for a full-screen window on the primary display monitor, in pixels.
        SM_CYSCREEN = 1; // The enum-value for getting the height of the client area for a full-screen window on the primary display monitor, in pixels.
    
    function InitializeSetup(): Boolean;
      var 
          hDC: Integer;
          xres: Integer;
          yres: Integer;
    begin
        xres := GetSystemMetrics(SM_CXSCREEN);
        yres := GetSystemMetrics(SM_CYSCREEN); //vertical resolution
    
        MsgBox( 'Current resolution is ' + IntToStr(xres) +
            'x' + IntToStr(yres)
    , mbInformation, MB_OK );
    
        Result := true;
    end;
    

    EDIT: It seems the indices should've been SM_CXSCREEN and SM_CYSCREEN. Changed the code to reflect that.

提交回复
热议问题