關閉另一個程序

發表于:2007-07-14來源:作者:點擊數: 標簽:
你可以使用API函數FindWindow和PostMessage來尋找一個窗口并且關閉它。下面的范例演示如何關閉一個標題為Calculator的窗口。 Dim winHwnd As Long Dim RetVal As Long winHwnd = FindWindow( vb NullString, Calculator) De bug .Print winHwnd If winHwnd 0
你可以使用API函數FindWindow和PostMessage來尋找一個窗口并且關閉它。下面的范例演示如何關閉一個標題為"Calculator"的窗口。

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 = &H10

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97