【发布时间】:2019-01-06 06:11:35
【问题描述】:
代码:
Local $iPID=ShellExecute("C:\Program Files\Mozilla Firefox\firefox.exe", "","","", @SW_MINIMIZE);
如何以折叠形式打开浏览器?
【问题讨论】:
标签: autoit
代码:
Local $iPID=ShellExecute("C:\Program Files\Mozilla Firefox\firefox.exe", "","","", @SW_MINIMIZE);
如何以折叠形式打开浏览器?
【问题讨论】:
标签: autoit
; Optional debugging feature.
Opt('TrayIconDebug', True)
; Run Firefox if not running.
If Not ProcessExists('firefox.exe') Then
ShellExecute('"C:\Program Files\Mozilla Firefox\firefox.exe"')
EndIf
; Wait for a window to match the class.
WinWait('[CLASS:MozillaWindowClass]')
$hFirefox = 0
$iAbort = 5
Do
Sleep(1000)
; Get all class windows into an array.
$aWList = WinList('[CLASS:MozillaWindowClass]')
For $i1 = 1 To UBound($aWList) -1
; Get the visible window from the window handle.
If BitAND(WinGetState($aWList[$i1][1]), 2) Then
$hFirefox = $aWList[$i1][1]
_WinState($aWList[$i1][1], $aWList[$i1][0], True)
ExitLoop 2
Else
_WinState($aWList[$i1][1], $aWList[$i1][0], False)
EndIf
Next
$iAbort -= 1
Until Not WinExists('[CLASS:MozillaWindowClass]') Or $iAbort = 0
; Minimize the visible window.
If WinSetState($hFirefox, '', @SW_MINIMIZE) Then
ConsoleWrite('A Firefox window has been minimized.' & @CRLF)
EndIf
Exit
Func _WinState($hWinHandle, $sWinTitle, $bWinVisible = False)
; Debug output for visible state of a window.
Local $sWinVisible = $bWinVisible ? 'True' : 'False'
ConsoleWrite(StringFormat('Handle: %s Visible: %-5s Title: %s', $hWinHandle, $sWinVisible, $sWinTitle) & @CRLF)
EndFunc
即使您设置了 Firefox 快捷方式以最小化并使用它
要启动 Firefox,Firefox 可能不会在启动时最小化。
这就是为什么 @SW_MINIMIZE 的显示标志为
ShellExecute 功能可能不起作用。
存在 -tray 参数,但我无法让它作为
在Command Line Options中提到。
要在启动时最小化,提供的代码可能会有所帮助。
它将找到班级可见的第一个窗口
MozillaWindowClass,并将尝试将其最小化。
变量$hFirefox 可能包含
在Do之后可以使用可见的Firefox窗口
循环已完成。
有些代码是可选的,即_WinState()用于输出
调试信息到控制台以了解窗口搜索是否
可见窗口工作正常。
【讨论】: