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 LongGetMessage has the following parameters:
-
lpMsg A Long pointer to an
MSGstructure that receives the message.-
hwnd The handle of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access