# Re: 请问要如何利用VB将其它正在执行的程式关闭?

Posted by Jan Yeh on November 27, 1999 at 02:27:34:

In Reply to: 请问要如何利用VB将其它正在执行的程式关闭? posted by 小龙 on November 26, 1999 at 22:12:24:

: 请问要如何利用VB将其它正在执行的程式关闭?
以下转载别人的一段程式码，其中必须要指定你想关闭之程式的TITLE（就是FORM上端蓝底白字的那一串字，要一模一样喔）
' #VBIDEUtils#********************************************************
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail : waty.thierry@usa.net
' * Date : 23/04/99
' * Time : 14:45
' *******************************************************************
' * Comments : Can I close an application
' *
' *
' *******************************************************************

' You can always use the FindWindow-function and the PostMessage-function
' to find the wanted application, and then send it a message that it has
to close itself.
' One disadvantage: you'll need the exact caption of this application.

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Form_Load()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
If winHwnd <> 0 Then
PostMessage winHwnd, WM_CLOSE, 0&, 0&
Else
MsgBox "The Calculator is not open."
End If

End Sub

如果你不确定那一行的字会是什么，你可以利用CWW网页http://www.hosp.ncku.edu.tw/~cww/htmapi76.htm的方式，一个一个找看看你要的程式在不在，再利用上述方式就可以啰...
参考看看吧！

Follow Ups: