VB游戏外挂编程入门(取得窗口的句柄.类.名称等)

建立三个label1/label2/lebel3/
名称分别为窗口句柄/类/标题/
建立一个text窗口
建立二个command按钮,一为开始抓取。一为退出

声明:
Private Type POINTAPI
 x As Long
 y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Sub Command1_Click()
If Command1.Caption = "开始抓取(&S)" Then
Timer1.Enabled = True
Command1.Caption = "停止抓取(&S)"
Else
Timer1.Enabled = False
Command1.Caption = "开始抓取(&S)"
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2 '使窗体位于最顶端
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
Dim tPoint As POINTAPI
Dim hWin As Long
Dim str As String * 255
Dim Abc As String * 64000
Dim Txt(64000) As Byte
GetCursorPos tPoint '获得当前鼠标位置
hWin = WindowFromPoint(tPoint.x, tPoint.y) '获得窗口名柄
If hWin = Me.hwnd Or hWin = Command1.hwnd Or hWin = Command2.hwnd Or hWin = Text1.hwnd Then Exit Sub '确定窗口不在 Form1 中
GetClassName hWin, str, 255 '获得窗口类
SendMessage hWin, &HD, 64000, Txt(0) '获得窗口标题(也可使用 API 函数:GetWindowText,但效果不佳)
Label1.Caption = "窗口名柄: " & hWin
Label2.Caption = "窗口类: " & str
Text1.Text = StrConv(Txt, vbUnicode)
End Sub

转载于:https://www.cnblogs.com/xxaxx/archive/2010/01/24/1655471.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值