2017-02-11 62 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毫秒,我不认为任何较低的值都可以被感知 - 我在日志中没有看到任何错误。 –