![]() |
#2
顾海洋凡2016-07-28 15:24
回复 楼主 顾海洋凡
|
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function writeprocessmemory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberofbyteswritten As Long) As Long
Private Declare Function readprocessmomory Lib "kernel32" (ByVal hprocess As Long, ByVal ipbaseaddress As Any, ByVal ipbuffer As Any, ByVal nsize As Long, ipnumberifbyteswritten As Long) As Long
Private Declare Function closehandle Lib "kernel32" (ByVal hobject As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "QQ") '得到窗口句柄
Label3.Caption = hwnd
If hwnd = 0 Then
Label1.Caption = "程序未运行" '验证是否得到有效窗口句柄
Else
Label1.Caption = "程序已运行"
End If
Dim pid As Long
Dim pHandle As Long
GetWindowThreadProcessId hwnd, pid '得到进程标识符
Label2.Caption = pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '通过进程标识符获得进程句柄
If pHandle = 0 Then
MsgBox "couldn 't get a process handle!"
Else
Label4.Caption = pHandle
End If
End Sub
[此贴子已经被作者于2016-7-28 15:23编辑过]