INNO设置:如何获得主显示器的分辨率?

时间:2011-03-28 15:54:34

标签: windows inno-setup

我正在尝试使用INNO编写安装程序脚本,我遇到了需要获取运行安装程序的机器的屏幕分辨率的点,并使用该值在桌面上创建一个快捷方式决议作为其中一个论点。我知道如何创建快捷方式,但是我不知道如何提取屏幕分辨率以及如何传递该信息(可能存储在自定义变量中)以在桌面快捷方式中使用它。

感谢您的时间:)

编辑:我无法更改应用程序,因为我无权执行此操作。所以请不要建议这样做。

2 个答案:

答案 0 :(得分:6)

我的解决方案是使用GetSystemMetrics(),可以在user32.dll中找到。这段代码完全符合我的要求,并且已经在Windows7 Professional(64位)上进行了双显示器设置的测试。

[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;

编辑:索引似乎应该是SM_CXSCREEN和SM_CYSCREEN。更改了代码以反映该内容。

答案 1 :(得分:0)

您需要一些代码才能获得当前分辨率。然后,您可以将这些值添加到[Icon]条目以创建快捷方式。这里有一些代码可以帮助您入门:

[Setup]
AppName=DisplayResoltution
AppVerName=DisplayResoltution
DefaultDirName=DisplayResoltution
DisableStartupPrompt=true
Uninstallable=false

[Files]
Source: "C:\util\innosetup\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"; Parameters: {code:GetParams}


[Code]
// Functions to get BPP & resolution

function DeleteDC (hDC: Integer): Integer;
 external 'DeleteDC@GDI32 stdcall';

function CreateDC (lpDriverName, lpDeviceName, lpOutput: String; lpInitData: Integer): Integer;
 external 'CreateDCA@GDI32 stdcall';

function GetDeviceCaps (hDC, nIndex: Integer): Integer;
 external 'GetDeviceCaps@GDI32 stdcall';

Const
    HORZRES = 8;    //horizontal resolution
    VERTRES = 10;   //vertical resolution
    BITSPIXEL = 12; //bits per pixel
    PLANES = 14;    //number of planes (color depth=bits_per_pixel*number_of_planes)
var
xres, yres, bpp, pl, tmp: Integer;

function InitializeSetup(): Boolean;
  var 
      hDC: Integer;
begin

    //get resolution & BPP
    hDC := CreateDC('DISPLAY', '', '', 0);
    pl := GetDeviceCaps(hDC, PLANES);
    bpp := GetDeviceCaps(hDC, BITSPIXEL);
    xres := GetDeviceCaps(hDC, HORZRES); //horizontal resolution
    yres := GetDeviceCaps(hDC, VERTRES); //vertical resolution
    tmp := DeleteDC(hDC);
    bpp := pl * bpp;   //color depth

    MsgBox( 'Current resolution is ' + IntToStr(xres) +
        'x' + IntToStr(yres) +
        ' and color depth is ' + IntToStr( bpp )
        , mbInformation, MB_OK );

    Result := true;
end;

function GetParams(def: string): string;
var
sTemp : string;
begin
  sTemp := 'xres=' + IntToStr(xres) + ' yres=' +IntToStr(yres);
  result := sTemp;
end;

代码改编自http://www.vincenzo.net/isxkb/index.php?title=Detect_current_display_resolution_and_color_depth