说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB如何关闭其他程序

HTML文档下载 WORD文档下载 PDF文档下载
VB如何关闭其他程序

如果你知道窗口的标题,就可以使用FindWindow 和函数PostMessage 来关闭窗口
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "Error posting message."
End If
Else
MsgBox "The Calculator is not open."
End If
For this code to work, you must have declared the API functions in a module in your project. You must put the following in the declarations section of the module.
Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Const WM_CLOSE = &H1
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘