Description
The WH_MSGFILTER
hook intercepts only sent messages (and not posted messages)
that menus, dialog boxes, message boxes, and scrollbars produce. For
a more detailed discussion of sent messages versus posted messages,
see Chapter 9 and Chapter 11.
You can implement the WH_MSGFILTER
hook with
either thread-specific or system-wide scope. You can implement the
cousin of this hook, WH_SYSMSGFILTER
, only
with
system-wide scope.
You can use the WH_MSGFILTER
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
discusses this in detail.
You might be wondering why this hook intercepts a seemingly arbitrary set of messages. To understand why, we need to understand what a modal loop is and how it affects messages that you send and post to a thread.
The Modal Loop
Microsoft defines a modal loop as follows:
A message-processing loop during which the system retrieves and dispatches messages without allowing an application the opportunity to filter the messages in its main message loop.
In other words, when certain events occur in the system (e.g., a menu is opened, a window is moved/sized, a modal dialog is displayed, or a scrollbar is moved), the thread ...
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.