' FindWindow函数声明
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
' PostMessage函数声明
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
'关闭程序需要的常量
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim winHwnd As Long
Dim lngRetVal As Long
'查找ie的句柄,注:这里如果要关闭特定ie窗口,在逗号之后输入vbnullstring,在逗号之后输入IE窗口的确切名字
winHwnd = FindWindow("IEFrame", vbNullString)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "关闭IE出错!"
End If
Else
MsgBox "IE没有运行。"
End If
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
' PostMessage函数声明
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
'关闭程序需要的常量
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim winHwnd As Long
Dim lngRetVal As Long
'查找ie的句柄,注:这里如果要关闭特定ie窗口,在逗号之后输入vbnullstring,在逗号之后输入IE窗口的确切名字
winHwnd = FindWindow("IEFrame", vbNullString)
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "关闭IE出错!"
End If
Else
MsgBox "IE没有运行。"
End If
End Sub
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |