 |
Anyu的意见:
' 声明一些需要的变量
Dim hwnd As Long ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim pHandle As Long ' 储存进程句柄
Dim hProcess As Long
' 首先取得目标窗口的句柄
Dim str4 As String * 4 ' 存储显示文本
Dim str2 As String * 2
Dim str1 As String * 1
If Trim(m_GameWindowsName) = "" Then
tmrWrite.Enabled = False
txtNewValue.Text = "请设置窗口名称!"
SelectAllText txtNewValue
Exit Sub
End If
hwnd = FindWindow(vbNullString, m_GameWindowsName)
If (hwnd = 0) Then
tmrWrite.Enabled = False
txtNewValue.Text = "游戏窗口没有运行或指定的窗口名称不正确!"
SelectAllText txtNewValue
Exit Sub
End If
' 取得进程标识符
GetWindowThreadProcessId hwnd, pid
' 使用进程标识符取得进程句柄
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle = 0) Then
txtNewValue.Text = "打开窗口进程失败!"
SelectAllText txtNewValue
Exit Sub
End If
Dim vBuffer As String
Dim lAddress As Long
Call HexStringToNumber(txtAddress, lAddress)
'Debug.Print "txtAddress="; Hex(lAddress)
Dim wPM As Long, sByteString As String
sByteString = "ABCd"
wPM = WriteProcessMemory(pHandle, lAddress, sByteString, 4, 0&)
If wPM = 0 Then
txtNewValue.Text = "写内存出错!"
SelectAllText txtNewValue
End If
' 关闭进程句柄
CloseHandle hProcess
此问题由Anyu回答。
附加关键字:编程, 源程序, programming, source code, Visual Basic, VB, Windows API, win32, api, windows api, gdi32, kernel。
|