What Are Hooks?
The Microsoft documentation defines hooks in this manner:
A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.
One more thing should be added to this definition. The addition I have made is in italics:
A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure, as well as after they are processed by the target window procedure.
The subroutine that is installed at a hook point is typically called a filter function. A filter function is analogous to a window procedure in that it can receive and process messages. When these filter functions are placed into the message stream at a hook point by using the SetWindowHookEx API function (which will be defined later in this chapter), it is called installing a hook. A hook point is a system-defined point in the message stream at which a filter function can be installed. These hook points cannot be changed.
Hooks are similar to subclassing in that both intercept messages, although this is where most of the similarities end. You might think of hooks as extensions to subclassing. If a problem cannot be solved with subclassing, look into using hooks to augment or even replace ...
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.