“Devil组”引证GPT后的撰写:、
- 在IE8浏览器中,应该无法通过调用WSH的AppActivate方法使IE窗口成为活动窗口。这可能是由于IE8中的安全限制或Windows用户账户控制(UAC)的设置引起的。
用Windows API函数SetForegroundWindow来使IE窗口成为前台窗口,并调用SetWindowPos函数来将IE窗口置顶。
下面是一个示例代码,使用了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函数。