2017-08-24 27 views
3

使用AutoIt v3啓動火狐,下面的腳本應該啓動Firefox網頁瀏覽器窗口:如何使用的AutoIt類進行匹配

Opt("WinTitleMatchMode", 4) 
$winMatchFirefox = "[CLASS:MozillaWindowClass]" 

If WinExists($winMatchFirefox) Then 
    Local $hWnd = WinActivate($winMatchFirefox) 
    If 0 = $hWnd Then 
     ToolTip("Firefox could not be activated", 100, 100, "Notice", 1) 
    Else 
     ToolTip("Firefox activated", 100, 100, "Notice", 1) 
    EndIf 
Else 
    ToolTip("Firefox is not running", 100, 100, "Notice", 1) 
EndIf 
Sleep(3000) 

上述腳本似乎工作。當Firefox運行時,輸出甚至讀取「Firefox激活」,但Firefox實際上並未激活。

在這些交換的前兩行,按預期工作一切恍然大悟:

Opt("WinTitleMatchMode", 2) 
$winMatchFirefox = " - Mozilla Firefox" 

使用的AutoIt窗口信息工具,它似乎基本窗口信息被填充,但基本控制信息是空的:

window info

是否有一個原因CLASS屬性不起作用?下面的代碼片段,甚至出現在FireFox AutoIt library - FF.au3 (v0.6.0.1b-15)

Local $WINTITLE_MATCH_MODE = AutoItSetOption("WinTitleMatchMode", 4) 
WinWaitActive("[CLASS:MozillaWindowClass]") 
Sleep(500) 
WinSetState("[CLASS:MozillaWindowClass]", "", @SW_MINIMIZE) 
BlockInput(0) 
AutoItSetOption("WinTitleMatchMode", $WINTITLE_MATCH_MODE) 

這到底是怎麼回事?通常寧願使用CLASS屬性而不是Window標題來控制窗口。這不可能嗎?

使用AutoIt v3.3.10.2和Firefox 52.0(32位)。

+0

Opt("WinTitleMatchMode", 4) $winMatchFirefox = "[CLASS:MozillaWindowClass]" Local $hWnd = WinActivate($winMatchFirefox) MsgBox(0,"", WinGetProcess("[ACTIVE]", "")) 

對我來說,這將是過程注意到,Mozilla Thunderbird中有'MozillaWindowClass'屬性,也缺乏基本控制信息:

你可以檢查一下。 –

回答

4

Here是一個例子,如何通過窗口列表使用類來做到這一點:

#include <WinAPI.au3> 
#include <Constants.au3> 
#include <WindowsConstants.au3> 
Local $hFireFoxWin=0,$aWinList=WinList("[REGEXPCLASS:Mozilla(UI)?WindowClass]") 
For $i=1 To $aWinList[0][0] 
    If BitAND(_WinAPI_GetWindowLong($aWinList[$i][1],$GWL_STYLE),$WS_POPUP)=0 Then 
     $hFireFoxWin=$aWinList[$i][1] 
     ExitLoop 
    EndIf 
Next 
If $hFireFoxWin Then WinActivate($hFireFoxWin) 

你也可以閱讀有關Advanced Window Descriptions

你的嘗試失敗,因爲Mozilla的一個實例可以有多個進程 mozilla_process 和基本WinActivate([CLASS:MozillaWindowClass])請求會影響Mozilla的隱藏(默認)窗口。具有PID 10128.

+0

這非常解釋!對高級Windows描述已經非常熟悉,並且無法弄清楚Firefox和其他Mozilla產品的不同之處。多個進程和隱藏的窗口! –

相關問題