How WH_GETMESSAGE Works
You use the WH_GETMESSAGE
hook to intercept
only posted (and not sent) messages. Using
this hook, you also can modify a message before the window procedure
processes it. These are the two main differences between this hook
and the WH_CALLWNDPROC
and
WH_CALLWNDPROCRET
hooks. The
WH_CALLWNDPROC
and
WH_CALLWNDPROCRET
hooks only intercept sent
messages and cannot modify the messages they intercept.
You can use this hook as a thread-specific hook, or you can place it in a dynamic link library (DLL) and use it as a system-wide hook. A thread-specific hook intercepts all messages within the thread in which it is installed. When you install a hook as a system-wide hook, you must place it in a DLL. This DLL is injected into every process so that the hook can operate on all messages in the system.Chapter 3 provides a thorough discussion of this concept.
Before explaining how this hook operates, I need to discuss both the GetMessage and the PeekMessage functions. GetMessage retrieves a single message from the message queue of the thread in which this function was called. This function is used mostly in a message loop for an application. GetMessage is defined as follows:
Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" _ (lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, _ ByVal wMsgFilterMax As Long) As Long
GetMessage has the following parameters:
-
lpMsg
A Long pointer to an
MSG
structure that receives the message.-
hwnd
The handle of the ...
Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.