Module1.bas
资源名称:cs8_gl3.rar [点击查看]
上传用户:hylsl0102
上传日期:2022-03-20
资源大小:3k
文件大小:3k
源码类别:
钩子与API截获
开发平台:
Visual Basic
- Attribute VB_Name = "Module1"
- Option Explicit
- 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 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 Const GWL_WNDPROC = -4&
- Public Const WM_MOUSEWHEEL = &H20A
- Public Const WM_MOUSEMOVE = &H200
- Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
- Public Type POINTAPI
- x As Long
- y As Long
- End Type
- Public OldWindowProc As Long '用来保存系统默认的窗口消息处理函数的地址
- Public hwndTextBox As Long '用来保存Text1控件的句柄
- Public hwndPict As Long
- Public OldWindowProc1 As Long
- '自定义的消息处理函数
- Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- On Error Resume Next
- If Msg = WM_MOUSEMOVE Then
- '下面得到鼠标位置处的对象的句柄
- Dim CurPoint As POINTAPI, hwndUnderCursor As Long
- GetCursorPos CurPoint
- hwndUnderCursor = WindowFromPoint(CurPoint.x, CurPoint.y)
- '如果鼠标位于Form1.Text1内部,则对鼠标滚轮事件进行处理
- If hwndUnderCursor = hwndTextBox Then
- Form1.Caption = "在text1内"
- ' If wParam = MK_LBUTTON Then
- '' Form1.Text1.SetFocus
- ' End If
- Else
- If hwndUnderCursor = hwndPict Then
- Form1.Caption = "在picture1内"
- Debug.Print Msg & " " & wParam & " " & lParam
- ' If wParam = MK_LBUTTON Then
- '' x = Int(LOWORD(lParam))
- '' y = Int(HIWORD(lParam))
- ' End If
- End If
- End If
- Else
- '调用Text1的默认窗口消息处理函数
- NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
- NewWindowProc = CallWindowProc(OldWindowProc1, hwnd, Msg, wParam, lParam)
- End If
- End Function
- Public Function HIWORD(LongIn As Long) As Integer
- ' 取出32位值的高16位
- HIWORD = (LongIn And &HFFFF0000) &H10000
- End Function
- Public Function LOWORD(LongIn As Long) As Integer
- ' 取出32位值的低16位
- LOWORD = LongIn And &HFFFF&
- End Function