[此贴子已经被作者于2007-3-23 3:32:48编辑过]
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '寻找窗口列表中第一个符合指定条件的顶级窗口的API调用
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal lpdw As Long, lpdwProcessId As Long) As Long '获取与指定窗口关联在一起的一个进程和线程标识符的API调用
Private Function ncnr(lpADDress As Long) As Integer ' 声明一些需要的变量
Dim lpdw As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim pHandle As Long ' 储存进程句柄
lpdw = FindWindow(vbNullString, "程序名") ' 取得进程标识符
GetWindowThreadProcessId hwnd, pid ' 使用进程标识符取得进程句柄
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) ' 在内存地址中读取数据
ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0& ' 关闭进程句柄
CloseHandle hProcess
End Function
Private Sub Timer1_Timer()
Dim lpdw As Long
lpdw = FindWindow(vbNullString, "程序名")
If lpdw = 0 Then
Label1.Caption = "程序未加载"
Exit Sub
End If
Label1.Caption = "程序已加载"
End If
End Sub
这样写为什么不行啊!!错在哪里啊!谢谢高手指点