Завершение работы другой программы
другое приложение из своей порграммы.
Подскажите, пожалуйста, как закрыть
другое приложение из своей порграммы.
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10
...
x = PostMessage(hwnd, WM_CLOSE, 0, 0)
hwnd — window handle окна, которое надо закрыть.
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const WM_CLOSE As Long = &H10
...
x = PostMessage(hwnd, WM_CLOSE, 0, 0)
hwnd — window handle окна, которое надо закрыть.
Если после закрытия программа всё еще работает, как MSN Messenger, то делай так:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject 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 Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
................
Dim Hndlr As Long
Hndlr = FindWindow("WindowClassName if you know or vbNullString", "Exact Window Capture you MUST know")
If Hndlr <> 0 Then
Dim lngReturnValue As Long
DoEvents
Dim hProc As Long
Dim lRes As Long
lRes = GetWindowThreadProcessId(Hndlr, hProc)
hProc = OpenProcess(SYNCHRONIZE Or PROCESS_TERMINATE, False, hProc)
lngReturnValue = TerminateProcess(hProc, 1)
DoEvents
lRes = CloseHandle(hProc)
End If
gensik, спасибо!
Незачто. Тут только одна проблема: Icon не убирается из SysTray. Кто бы подсказал, как его Refresh?