以楓之谷為例:
表單:TextX2 TimerX1Private Sub Timer1_Timer()
If FindGame("MapleStory") = True Then
hwn顯示.Text = hwn
pid顯示.Text = pid
End If
End Sub 模組:
Public Declare Function FindWindow
Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal
lpWindowName As String) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId
As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Integer
Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal
hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As
Long, lpNumberOfBytesWritten As Long) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess
As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long,
lpNumberOfBytesWritten As Long) As Long
Public hwn As Long 'Handle Of Window 視窗鉤子
Public Phandle As Long 'Handle Of Process 程序鉤子
Public pid As Long 'Process ID 程序ID
Public Function FindGame(strGame As String) As Boolean
hwn = FindWindow(vbNullString, strGame) '尋找遊戲視窗
GetWindowThreadProcessId hwn, pid '取得程序ID
Phandle = OpenProcess(&H1F0FFF, False, pid) '取得遊戲進程
If hwn <> 0 Then FindGame = True '判斷並傳回是否取得進程
End Function
|