' 标准模块: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 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 ret As Long' SetWindowLong 的回调函数, 利用 Msg 拦截消息 Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Debug.Print MsgWindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam) End Function ' 窗体模块: Option Explicit 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 Const SYNCHRONIZE = &H100000Private Sub Command1_Click() Dim pid As Long GetWindowThreadProcessId Me.hwnd, pid OpenProcess SYNCHRONIZE, True, pid End SubPrivate Sub Form_Load() ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc) End SubPrivate Sub Form_Unload(Cancel As Integer) SetWindowLong Me.hwnd, GWL_WNDPROC, ret End Sub
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 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 ret As Long' SetWindowLong 的回调函数, 利用 Msg 拦截消息
Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print MsgWindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
End Function
' 窗体模块:
Option Explicit
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 Const SYNCHRONIZE = &H100000Private Sub Command1_Click()
Dim pid As Long
GetWindowThreadProcessId Me.hwnd, pid
OpenProcess SYNCHRONIZE, True, pid
End SubPrivate Sub Form_Load()
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hwnd, GWL_WNDPROC, ret
End Sub
然后拦截
用两个程序试试。
http://www.hosp.ncku.edu.tw/~cww/html/q00553.html
reading......