vb hook, 教程 + 代码 。求助 。学学

越详细越好有资料的请发送到737428137@qq.com... 越详细越好
有资料 的请发送到 737428137@qq.com
展开
 我来答
匿名用户
2011-07-27
展开全部
'窗体代码
Private Sub Form_Load()
Dim hWnd As Long
Dim s As String
Me.Show
hWnd = GetWindow(Me.hWnd, GW_CHILD Or GW_HWNDFIRST)
Do While hWnd <> 0
s = String(256, Chr(0))
GetClassName hWnd, s, 255
s = Replace(s, Chr(0), "")
If s = "QVODPLAYERCLASS" Then '要匹配的窗口类名
OldWindowProc = GetWindowLong(hWnd, GWL_WNDPROC) ' 取得窗口函数的地址
' 用SubClass_WndMessage代替窗口函数处理消息,挂钩子
Call SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubClass_WndMessage)
Exit Do
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
End Sub

'模块代码
Option Explicit

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public Const WM_SETCURSOR = &H20
Public Const WM_MOUSEACTIVATE = &H21
Public Const WM_NCCALCSIZE = &H83
Public Const WM_PARENTNOTIFY = &H210

Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205

Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDFIRST = 0

Public Const GWL_WNDPROC = (-4)

Public OldWindowProc As Long ' 保存默认的窗口函数的地址

Public Function SubClass_WndMessage(ByVal hWnd As Long, ByVal Msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
' 如果消息不是WM_PASTE,就调用默认的窗口函数处理
Select Case Msg
Case WM_SETCURSOR
Debug.Print "光标感应";
Dim mMsg As Long
mMsg = lp And &HFFF0000
mMsg = mMsg \ &H10000
Select Case mMsg
Case WM_MOUSEMOVE
Debug.Print "移动"
Case WM_LBUTTONDOWN
Debug.Print "左键按下"
Case WM_LBUTTONUP
Debug.Print "左键弹起"
Case WM_RBUTTONDOWN
Debug.Print "右键按下"
Case WM_RBUTTONUP
Debug.Print "右键弹起"
End Select
Case WM_MOUSEACTIVATE
Debug.Print "鼠标活动"
Case WM_NCCALCSIZE
Debug.Print "消息"
Case WM_PARENTNOTIFY
Debug.Print "消息"

End Select
SubClass_WndMessage = CallWindowProc(OldWindowProc, hWnd, Msg, wp, lp)
Exit Function
End Function
另外,团IDC网上有许多产品团购,便宜有口碑
百度网友ba88284
2011-07-26 · TA获得超过1521个赞
知道大有可为答主
回答量:1822
采纳率:73%
帮助的人:561万
展开全部
你可以在百度知道搜索一下,其实已经有很多的相关问题,和详细的解答了!提问题前,希望你先进行一下搜索。谢谢合作
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zx001z7d53
2011-07-26 · TA获得超过2万个赞
知道大有可为答主
回答量:2.4万
采纳率:52%
帮助的人:5441万
展开全部
自己搜索吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式