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网上有许多产品团购,便宜有口碑
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网上有许多产品团购,便宜有口碑
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询