vbs脚本调用ie浏览器,遇到ie8后,不能置顶ie窗口,请问是为什么
代码如下
MaxBrowserWindow("www.baidu.com")
Sub MaxBrowserWindow(URL)
With CreateObject("InternetExplorer.Application")
dim ws
set ws = CreateObject("Wscript.Shell")
ws.AppActivate "Internet Explorer"
.Navigate URL
While .Busy
wend
.Left = 0
.Top = 0
.Width = .document.parentWindow.screen.availWidth
.Height = .document.parentWindow.screen.availHeight
.Visible = True
End With
End Sub
“Devil组”引证GPT后的撰写:、
下面是一个示例代码,使用了Windows API函数:
MaxBrowserWindow("www.baidu.com")
Sub MaxBrowserWindow(URL)
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate URL
ie.Visible = True
' wait for the page to load
Do While ie.Busy Or Not ie.ReadyState = 4
WScript.Sleep 100
Loop
' set window position and size
ie.Left = 0
ie.Top = 0
ie.Width = ie.document.parentWindow.screen.availWidth
ie.Height = ie.document.parentWindow.screen.availHeight
' bring the window to the foreground and set it as topmost
Dim hwnd
hwnd = ie.HWND
SetForegroundWindow hwnd
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
' Windows API declarations
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
此代码需要在管理员权限下运行才能使用Windows API函数。