发布网友 发布时间:2022-09-10 08:06
共1个回答
热心网友 时间:2024-01-30 20:58
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const MK_LBUTTON = &H1 Sub 关闭弹出窗口() With CreateObject("internetexplorer.application") .Visible = True .Navigate "http://xxxxx/xxxxxxx/xxxx/xx.html" Do Until FindWindow(vbNullString, "Microsoft Internet Explorer") > 0 DoEvents Loop winHwnd = FindWindow(vbNullString, "Microsoft Internet Explorer") '获得消息窗口句柄 If winHwnd <> 0 Then '关闭“Microsoft Internet Explorer”消息窗口 btnHwnd = FindWindowEx(winHwnd, 0, "Button", "确定") '获得“确定”按钮句柄 SendMessage btnHwnd, WM_LBUTTONDOWN, 0, ByVal 0 '点击“确定”按钮(按下左键) SendMessage btnHwnd, WM_LBUTTONUP, 0, ByVal 0 '点击“确定”按钮(松开左键) End If End With End Sub 举报