怎样关闭一个正在运行的程序 技术文档->VB文档->系统控制 || Visual Basic 开发中心 立华软件园 打造最专业的 VB 开发社区
Dim winHwnd As LongDim 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 “置入消息错误!"
End If
Else
MsgBox “Calculator没有打开!"
End If
为了让以上的代码工作,你必须在模块文件中什么以下API函数:
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 = &H10