![]() ![]() The hook is installed in a form module in the following fashion: SetHook App.ThreadID, Me.Text1.Public Class Hotkey # Region "Declarations - WinAPI, Hotkey constant and Modifier Enum" ''' ''' Declaration of winAPI function wrappers. GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam) Private Function GetMsgProc(ByVal uCode As Long _ HHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, 0, hThreadToHook) Public Sub SetHook(ByVal hThreadToHook As Long, hHwndFilter As Long) Private Declare Function UnhookWindowsHookEx Lib "user32" _ (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Private Declare Function SetWindowsHookEx Lib "user32" _ ![]() (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function CallNextHookEx Lib "user32" _ Private Const WM_RBUTTONDOWN As Long = &H204 Private Const WH_GETMESSAGE As Long = &H3 ![]() It works for me if I use it to sniff WM_RBUTTONDOWN messages to, say, TextBox control placed on a main form. Here is the code that should be placed in a standard module (as any other code that installs hooks). It's perfectly OK to declare 3rd parameter of filter function as ByRef lParam As MSG. Should return the value returned by CallNextHookEx.Īlthough CopyMemory should work (assuming you declare it correctly), I wouldn't bother with it here. Message to the CallNextHookEx function without further processing and If code is less than zero, the hook procedure must pass the If code is HC_ACTION, the hook procedure must process the Specifies whether the hook procedure must process the This is how GetMsgProc filter function should make a decision based on a value of its first argument: VB6 or C++ or whatever, it is a deadly practice to ignore MSDN specification for API. GetMsgProc is called with wParam = PM_REMOVE for messages that have been removed from queue. You probably wouldn't want to analyze messages that have been merely peeked from the queue, but not removed from it.Those applications will misbehave if you prevent their filter functions from being called. Maybe, there are none on a dev machine, but 'in the wild' there will be other applications that installed hooks. If you do this then other filter functions in the chain will not be called. Skipping the call to CallNextHookEx in GetMsgProc filter function is generally a bad idea. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |