Caveats

The main thing to remember when using this hook is that it captures only messages that are sent using the SendMessage function. It will not capture messages that you post to the message queue using the PostMessage function. For the case of posted messages, you should use the WH_GETMESSAGE hook, which is discussed in Chapter 11.

You should take care when using any hook, as performance can be seriously degraded. Using a thread-specific hook can degrade performance for a single thread because it operates from within that thread only. A system-wide hook resides in a DLL that is injected into all running processes. Therefore, if the hook’s filter function code puts undue strain on the system, every thread in the system can slow to a crawl. This causes the entire system to act sluggishly. When writing filter functions for hooks of either scope, you should exit the code as soon as possible. By this I mean that if the hook intercepts messages that are of no interest, you should exit the filter function immediately. As we saw earlier, windows are constantly being bombarded with messages. Spending time processing a few of those messages most likely will not put a strain on the system. However, spending time processing all messages will certainly place a strain on the system.

There is a bug using this hook on the Windows 95 operating system. This bug is described in article Q149862. In short, when this hook is installed as a system-wide hook and the user presses the ALT-ESC key combination, ...

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.