| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 528 人关注过本帖
标题:请高手帮忙修改下
只看楼主 加入收藏
lchl650610
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2009-5-17
结帖率:50%
收藏
 问题点数:0 回复次数:4 
请高手帮忙修改下
我是初学者,敬请高手指点。下面是我在网上抄的一段代码,运行时发生错误,请帮忙修改下,有注释更好。我只有10分,全部给了。

'需要的控件:Label、Timer(interval不为空)、Text

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Const PROCESS_VM_OPERATION = &H8&
Const PROCESS_VM_READ = &H10&
Const PROCESS_VM_WRITE = &H20&
Dim SetHp As Integer     ' 定义设定的体力值
Dim SetMp As Integer    ' 定义设定的魔法值
Dim NowHp As Long    ' 定义目前的体力值
Dim NowMp As Long    ' 定义目前的魔法值
Dim MaxHp As Long    ' 定义角色的最高体力值
Dim MaxMp As Long    ' 定义角色的最高魔法值
Dim DiZhi As Long       '定义内存地址函数
Private Function ncnr(lpADDress As Long) As Integer
   ' 声明一些需要的变量
   Dim hwnd As Long     ' 储存 FindWindow 函数返回的句柄
   Dim pid As Long    ' 储存进程标识符( Process Id )
   Dim pHandle As Long ' 储存进程句柄
   hwnd = FindWindow(vbNullString, "Element Client")
   ' 取得进程标识符
   GetWindowThreadProcessId hwnd, pid
   ' 使用进程标识符取得进程句柄
   pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
   ' 在内存地址中读取数据
   ReadProcessMemory pHandle, lpADDress, ByVal VarPtr(ncnr), 4, 0&
   ' 关闭进程句柄
   CloseHandle hProcess
End Function



Private Sub Form_Load()
'  这里替换你所搜索到的地址
   DiZhi = 985614
   Timer1.Enabled = True
   Timer2.Enabled = False
   Timer3.Enabled = False
End Sub

Private Sub Timer1_Timer()
   Dim hwnd As Long
   hwnd = FindWindow(vbNullString, "Element Client")
  
   If hwnd = 0 Then
Label12.Caption = "游戏未加载"
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Exit Sub
   End If

   Label12.Caption = "游戏已加载"
   SetHp = Text1.Text    ' 获取设定的体力值
   SetMp = Text2.Text    ' 获取设定的魔法值
   NowHp = ncnr(DiZhi)    ' 获取当前的体力值
   NowMp = ncnr(DiZhi + 12) ' 获取当前的魔法值
   MaxHp = ncnr(DiZhi + 260) ' 获取角色的最高体力值
   MaxMp = ncnr(DiZhi + 16) ' 获取角色的最高魔法值
   Label3.Caption = Str(NowHp) + "/" + Str(MaxHp)     ' 显示角色体力值状态
   Label4.Caption = Str(NowMp) + "/" + Str(MaxMp)     ' 显示角色魔法值状态

   If Check1.Value Then
Timer2.Enabled = True
   Else
Timer2.Enabled = False
   End If
   If Check2.Value Then
Timer3.Enabled = True
   Else
Timer3.Enabled = False
   End If
End Sub

Private Sub Timer2_Timer()
   ' 体力值小于设定值按下数字键1
   If (NowHp) < SetHp Then
SendKeys "1"
   End If
End Sub

Private Sub Timer3_Timer()
   ' 魔法值小于设定值按下数字键2
   If (NowMp) < SetMp Then
SendKeys "2"
   End If
End Sub
2009-10-27 12:54
lchl650610
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2009-5-17
收藏
得分:0 
注:游戏是武林外传
2009-10-27 12:56
lchl650610
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2009-5-17
收藏
得分:0 
没人理?
2009-11-05 19:28
msgj
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:190
专家分:914
注 册:2009-10-3
收藏
得分:0 
运行时发生什么错误了?
2009-11-05 20:37
lchl650610
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2009-5-17
收藏
得分:0 
不好意思,因为工作太忙,所以没时间学了,所以没上论坛.谢谢各位的指点.现在改学delphi,会常上论坛,还望大虾多多指教
2011-04-02 19:11
快速回复:请高手帮忙修改下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018354 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved