2017-02-11 61 views

回答

2

這是幾乎不可能使應用程序在需要的位置開始,除非應用程序明確支持它。所以一般

,你可以做的是看某些窗口出現,之後將其移動。您可以通過標題(FindWindowByWindowName)或類(FindWindowByClassName)標識該窗口。缺點是該窗口會短暫出現在其默認位置。

代碼使用InnoTools InnoCallback library

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

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


[Code] 

type 
    TTimerProc = procedure(HandleW, msg, idEvent, TimeSys: LongWord); 

function WrapTimerProc(Callback: TTimerProc; ParamCount: Integer): LongWord; 
    external '[email protected]:InnoCallback.dll stdcall delayload'; 
function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): LongWord; 
    external '[email protected] stdcall'; 
function KillTimer(hWnd, nIDEvent: LongWord): LongWord; 
    external '[email protected] stdcall'; 
function GetTickCount: DWord; external '[email protected] stdcall'; 
function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND; X: Integer; Y: Integer; 
    cx: Integer; cy: Integer; uFlags: UINT): BOOL; 
    external '[email protected] 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, WrapTimerProc(@MoveDirectXWindowProc, 4)); 
    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; 

Windows positions

+0

因爲窗口標題是不是'安裝Microsoft(R)的DirectX(R)','不過...... Instalando' - 你必須定位在'FindWindowByWindowName'字符串呼叫。 –

+0

或者使用更寬容的實現來代替使用部分匹配的FindWindowByWindowName(例如,僅限DirectX)。 –

+0

您可以減少SetTimer調用的時間間隔。但它已經只有100毫秒,我不認爲任何較低的值都可以被感知 - 我在日誌中沒有看到任何錯誤。 –