Description of Hooks
You can use the WH_MOUSE
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, it has to
be placed 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.
The WH_MOUSE
hook allows us to only watch or
discard mouse messages. You can use this hook to intercept messages
for a single thread or for all running threads. This hook provides a
large amount of control over the mouse and the way the user is able
to use the mouse.
The second mouse hook, WH_MOUSE_LL
, was introduced
with Windows NT Service Pack 3 and higher. This hook is similar to
the WH_MOUSE
hook, except that it intercepts
messages at a much earlier point in the Windows messaging system.
This provides extra information about mouse messages that is not
available through the WH_MOUSE
hook. Table 13-1 describes the information that you can obtain
from each type of mouse hook.
Table 13-1. Information Provided by WH_MOUSE and WH_MOUSE_LL Hooks
WH_MOUSE |
WH_MOUSE_LL |
---|---|
Cursor coordinates (x,y) |
Cursor coordinates (x,y) |
Extra information |
Extra information |
Message ID |
Message ID |
|
|
Window hwnd |
N/A |
Hit-test value |
N/A |
N/A |
Mouse wheel delta |
N/A |
Which |
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.