VB中如何根据窗口的句柄结束他的进程?

2024-12-03 22:32:33
推荐回答(2个)
回答1:

通过窗口句柄获得该窗口的进程ID,然后通过openprocess获得该进程的句柄,然后
通过获得的进程句柄通过EnumProcessModules函数获得该进程的模块,然后通过
GetModuleFileNameEx函数,可以获得当前进程的程序文件名(全路径)
GetModuleBaseName这个函数好象可以获得程序的文件名

回答2:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CLOSE = &H10

Private Sub Timer1_Timer()
Dim hwnd As Long
If FindWindow(vbNullString, "QQ2009") <> 0 Then
hwnd = FindWindow(vbNullString, "QQ2009")
SendMessage hwnd, WM_CLOSE, 0&, 0&
End If
End Sub