|
再找了一段API的程序 却不知道怎么样应用 如: 我要关闭 WORD.EXE 怎么调用下面的程序
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1
''用于结束外部进程,hCloseWnd 是要结束的程序的主窗口的 HWND
Public Function TernamiteProcessByHWND(ByVal hCloseWnd As Long) As Boolean
Dim hProcessID As Long
Dim hProcess As Long
On Error GoTo PROC_EXIT
If hCloseWnd = 0 Then GoTo PROC_EXIT
If GetWindowThreadProcessId(hCloseWnd, hProcessID) = 0 Then GoTo PROC_EXIT
hProcess = OpenProcess(PROCESS_TERMINATE, False, hProcessID)
If hProcess = 0 Then GoTo PROC_EXIT
If TerminateProcess(hProcess, 0&) = 0 Then GoTo PROC_EXIT
TernamiteProcessByHWND = True
PROC_EXIT:
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
End If
End Function [em06] |
|