Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows INNO设置:如何获取主监视器&x27;谁的决议?_Windows_Inno Setup - Fatal编程技术网

Windows INNO设置:如何获取主监视器&x27;谁的决议?

Windows INNO设置:如何获取主监视器&x27;谁的决议?,windows,inno-setup,Windows,Inno Setup,我正在尝试使用INNO编写安装程序的脚本,但我遇到了一个难题,需要获取运行安装程序的计算机的屏幕分辨率,并使用该值在桌面上创建一个快捷方式,该分辨率作为参数之一。我知道如何创建快捷方式,但是我不知道如何提取屏幕分辨率以及如何传递该信息(可能存储在自定义变量中)以在桌面快捷方式中使用它 谢谢您的时间:) 编辑:我无法更改应用程序,因为我无权更改。因此,请不要建议这样做。您需要一些代码才能获得当前分辨率。然后,您可以将这些值添加到[Icon]条目中以创建快捷方式。以下是一些让您开始学习的代码: [S

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

谢谢您的时间:)


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

您需要一些代码才能获得当前分辨率。然后,您可以将这些值添加到[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;

改编自

的代码我的解决方案是使用可以在user32.dll中找到的GetSystemMetrics()。这段代码完全满足了我的需求,并在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。更改了代码以反映这一点。

我删除了我的答案,因为您已明确表示无法更改应用程序。我同情你。看来,在应用程序上工作的人拥有所有的权力,他们正在滥用这种权力。嗨,米切尔,谢谢你的回答。我今天应该可以测试一下。请不要介意我不能尽快验证它。我尝试了你的代码,它显示
当前分辨率为0x0,颜色深度为0
什么操作系统?我在Win7 x64上试用了它,它对我有效。你在其他机器上试过吗?我也在Win7 x64上试过。但是我使用User32.dll中的
GetSystemMetrics()
并使用索引SM\u CXFULLSCREEN和SM\u CYFULLSCREEN得到了结果。我对你的系统(可能)有一点不同;我的是双监视器设置。我不知道这是不是问题的根源。我的解决方案得到的代码要少得多。非常好的解决方案,非常感谢!在Win Srv Std 2012 x64上仍然有效:-)