簡體   English   中英

Inno Setup - 如何強制從 Inno Setup 啟動的程序在屏幕上的某個位置打開?

[英]Inno Setup - How to force programs started from Inno Setup to open on a certain place on the screen?

使用此代碼: 當進度條已滿並在主文件提取后暫停時,在 freearc 默認腳本中安裝 DirectX 和 VCRedist 我可以使用 Inno Setup 安裝 DirectX 和 VCRedist。 但是,是否可以將這些程序的安裝窗口強制到屏幕上的某個位置? 例如:

在此處輸入圖片說明

在此處輸入圖片說明

除非應用程序明確支持,否則很難讓應用程序在所需位置啟動。

所以一般來說,你可以做的是觀察某個窗口的出現並在之后移動它。 您可以通過標題 ( FindWindowByWindowName ) 或類 ( FindWindowByClassName ) 來識別窗口。 缺點是窗口會短暫出現在其默認位置。

[Files]
Source: "DXWebSetup.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall

[Run]
Filename: "{tmp}\DXWebSetup.exe"; StatusMsg: "Installing DirectX..."; \
  BeforeInstall: StartWaitingForDirectXWindow; \
  AfterInstall: StopWaitingForDirectXWindow


[Code]

function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): LongWord;
  external 'SetTimer@User32.dll stdcall';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord;
  external 'KillTimer@User32.dll stdcall';
function GetTickCount: DWord; external 'GetTickCount@kernel32 stdcall';
function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND; X: Integer; Y: Integer;
  cx: Integer; cy: Integer; uFlags: UINT): BOOL;
  external 'SetWindowPos@user32.dll stdcall'; 

const
  SWP_NOSIZE = $01;  
  SWP_NOZORDER = $04;

var
  WindowWaitTimer: LongWord;
  WindowWaitStarted: DWord;
  MoveWindowRunning: Boolean;

procedure MoveDirectXWindowProc(
  H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
var
  Retry: Boolean;
  Handle: HWND;
begin
  Handle := FindWindowByWindowName('Installing Microsoft(R) DirectX(R)');
  if Handle = 0 then
  begin
    if DWord(GetTickCount - WindowWaitStarted) < 5000 then
    begin
      Log('DirectX window not found, will try again shortly');
      Retry := True;
    end
     else
    begin
      Log('Giving up waiting for DirectX window');
      Retry := False;
    end
  end
    else
  begin
    Log('DirectX window found');

    SetWindowPos(
      Handle, 0, WizardForm.Left + ScaleX(150), WizardForm.Top + ScaleX(30),
      0, 0, SWP_NOSIZE or SWP_NOZORDER);
    Retry := False;
  end;

  if not Retry then
  begin
    Log('Stopping timer');
    KillTimer(0, WindowWaitTimer);
    WindowWaitTimer := 0;
  end;
end;

procedure StartWaitingForDirectXWindow;
begin
  Log('Starting waiting for DirectX window');
  WindowWaitTimer := SetTimer(0, 0, 100, CreateCallback(@MoveDirectXWindowProc));
  WindowWaitStarted := GetTickCount;
end;

procedure StopWaitingForDirectXWindow;
begin
  if WindowWaitTimer <> 0 then
  begin
    Log('DirectX installer finished, and we are still waiting for its window, stopping');
    KillTimer(0, WindowWaitTimer);
    WindowWaitTimer := 0;
  end
    else
  begin
    Log('DirectX installer finished, and we are no longer waiting for its window');
  end;
end;

對於CreateCallback功能,你需要創新安裝6.如果你被卡住Inno Setup的5,你可以使用WrapCallback功能從InnoTools InnoCallback庫。


窗口位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM