2017-03-17 22 views
-1

我做了兩個文件(a.au3b.au3)。兩者都包含相同的代碼:在兩個不同的窗口中打開兩個具有相同代碼的文件

#include <IE.au3> 
#include <MsgBoxConstants.au3> 

Global $myUrl = "https://www.autoitscript.com" 
RegWrite('HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main','SessionMerging','REG_DWORD','00000000') 
ShellExecute ("iexplore.exe", " -nosessionmerging about:blank") 
WinWait ("Blank Page") 
Global $oIE = _IEAttach ("about:blank", "url") 
_IELoadWait ($oIE) 
_IENavigate ($oIE, $myUrl) 

當我在同一時間推出這兩個文件,兩個空白的Internet Explorer窗口打開。

我想要的是每個窗口導航到鏈接。但是會發生什麼情況是第一個和第二個文件將URL導航到同一個窗口。所以第二個窗口停留在about:blank。我認爲這是因爲我試圖在兩個窗口中打開相同的URL。

所以我需要一種方式從兩個不同的窗口導航到相同的URL。我不想使用_IECreate(),因爲我已經使用ShellExecute()解決了the problem of session merging between windows。使用_IEAttach()(未經測試,沒有錯誤檢查)當由手柄代替標題文本

回答

0

目標窗口:

#include <WinAPIProc.au3> 
#include <IE.au3> 

Global $g_aUrl[2] 
     $g_aUrl[0] = 'https://stackoverflow.com/' 
     $g_aUrl[1] = 'https://www.autoitscript.com/' 
Global $g_aIE[UBound($g_aUrl, 1)] 

For $i1 = 0 To UBound($g_aUrl, 1) -1  
    _IECreateSession($g_aIE[$i1], $g_aUrl[$i1])  
Next 

Func _IECreateSession(ByRef $oIE, Const $sUrl) 
    Local Const $iPID = ShellExecute('iexplore.exe', '-nosessionmerging about:blank') 
    Local  $aWnd 

    WinWait('Blank Page') 

    $aWnd = _WinAPI_EnumProcessWindows($iPID, True) 
    $oIE = _IEAttach($aWnd[1][1], 'hwnd') 

    _IELoadWait($oIE) 
    _IENavigate($oIE, $sUrl) 

    Return $iPID  
EndFunc 

檢索從指定的進程(最新IE實例)的主窗口處理。 Related

相關問題