Subclassing & Hooking with Visual Basic offers developers a unique way to customize Windows behavior.
Windows is a message-based system. Every action you request creates one or more messages to carry out the action. These messages are passed between objects and carry with them information that gives the recipient more detail on how to interpret and act upon the message.
With Subclassing and the Windows hooking mechanism ("hooks"), you can manipulate, modify, or even discard messages bound for other objects within the operating system, in the process changing the way the system behaves. What kinds of results can you achieve using the power of subclassing and hooking? Here are just a few of the possibilities:
Determine when a window is being activated or deactivated and respond to this change.
Display descriptions of menu items as the mouse moves across them.
Disallow a user to move or resize a window.
Determine where the mouse cursor is and respond accordingly.
Determine when the display resolution has been changed.
Monitor the system for a low system resource condition.
Modify or disallow keystrokes sent to a window or a control.
Create an automated testing application.
Determine when an application is idle.
Along with this power comes responsibility; Windows is very unforgiving if subclassing and hooking are used incorrectly. Subclassing & Hooking with Visual Basic demonstrates the various techniques for intercepting messages bound for one or more windows or controls: the intercepted message can be left in its original state or modified; afterwards, the message can be sent to its original destination or discarded.
For both VB 6 and VB.NET developers, Subclassing & Hooking with Visual Basic opens up a wealth of possibilities that ordinarily would be completely unavailable, or at least not easy to implement.
Introducing Subclassing and Hooking
Chapter 1 Introduction
Subclassing
The Window Hooking Mechanism
Tools to Aid Us in Our Efforts
A Word of Warning
Chapter 2 Windows System-Specific Information
Inside a Windows Application
Inside the Windows Messaging System
Performance Considerations
Chapter 3 The Basics of Subclassing and Hooks
What Is Subclassing?
What Are Hooks?
Subclassing and Superclassing
Chapter 4 Subclassing
The AddressOf Operator
Some Subclassing Tips
Instance Subclassing: An Example
Global Subclassing
Summary of Key Points in Subclassing
Chapter 5 Subclassing the Windows Common Dialog Boxes
How Common Dialog BoxSubclassing Works
Using the Resource
Creating the Subclassing Application
Subclassing Common Dialog Boxes Other Than Open and Save As
Problems Subclassing the Find and Replace Common Dialogs
Chapter 6 ActiveX Controls and Subclassing
Subclassing a Third-PartyActiveX Control
Subclassing an ActiveX ControlCreated in VB
Subclassing a UserControl from Within a VB-Created ActiveX Control
Creating an ActiveX Control That Subclasses Other Windows
Chapter 7 Superclassing
What Is Superclassing?
How the Superclassing Example Works
Peering into the Superclassing Application with Spy++
Chapter 8 Debugging Techniques for Subclassing
Where to Start
Microsoft Tools
NuMega’s SmartCheck
Hooking
Chapter 9 WH_CALLWNDPROC
How WH_CALLWNDPROC Works
A Thread-Specific Example
Caveats
Chapter 10 WH_CALLWNDPROCRET
How WH_CALLWNDPROCRET Works
A Thread-Specific Example
Caveats
Chapter 11 WH_GETMESSAGE
How WH_GETMESSAGE Works
A Thread-Specific Example
Caveats
Chapter 12 WH_KEYBOARD and WH_KEYBOARD_LL
How Keyboard Messaging Operates
Description of Hooks
A Thread-Specific Example
A System-Wide Example
A Low-Level Hook Example
Caveats
Chapter 13 WH_MOUSE and WH_MOUSE_LL
How Mouse Messaging Operates
Description of Hooks
Location of This Hook in the System
A Single-Thread Example
A System-Wide Hook Example
Caveats
Chapter 14 WH_FOREGROUNDIDLE
Description
Location of This Hook in the System
Background Processing Example
Caveats
Chapter 15 WH_MSGFILTER
Description
A Thread-Specific Example
Caveats
Chapter 16 WH_SYSMSGFILTER
Description
A System-Wide Example
Caveats
Chapter 17 WH_SHELL
Description
Location of This Hook in the System
A Thread-Specific Example
Caveats
Chapter 18 WH_CBT
Description
A Thread-Specific Example
Caveats
Chapter 19 WH_JOURNALRECORD
Description
The Macro Recorder Example
Caveats
Chapter 20 WH_JOURNALPLAYBACK
Description
The Macro Recorder/Playback Example
Caveats
Chapter 21 WH_DEBUG
Description
A Thread-Specific Example
Some WH_DEBUG Scenarios
Caveats
The .NET Platform
Chapter 22 Subclassing .NET WinForms
What Is a WinForm?
Instance Subclassing
Subclassing a Control
Superclassing
Superclassing a Control
Intercepting Keystrokes in a WinForm
Behind the Scenes with Spy++
Chapter 23 Implementing Hooks in VB.NET
Hooks and VB.NET
Delegates
Implementing the WH_KEYBOARD Hook
Implementing the WH_MOUSE Hook
Appendixes
Appendix Messages
Window Messages
Button Control-Specific Messages
Combo Box-Specific Messages
Edit Control-Specific Messages
Listbox-Specific Messages
Scroll Bar-Specific Messages
Messages Specific to the CommonDialog Boxes
Messages Specific to the Font Common Dialog Box
Messages Specific to the Page Setup Common Dialog Box
Stephen Teilhet earned a degree in electrical engineering but soon afterwards began writing software for the Windows platform. For the last eight years, he has worked for several consulting firms on a wide range of projects, specializing in Visual Basic, Visual C++, MTS, COM, MSMQ, and SQL Server. Stephen currently works for Compuware Numega Labs in Nashua, New Hampshire, where he is immersed in the Microsoft .NET technologies.
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animals on the cover of Subclassing and Hooking with Visual Basic are common brushtail possums (Trichosurus vulpecula). These small Australian marsupials are about one-sixth the size of a housecat. They have big ears, long whiskers, and a pointy snout tipped with a pink nose; their fur color ranges from light gray to dark brown. A brushtail possum pregnancy lasts only about 17 days, but, after birth, the single infant spends up to 5 months in his mother's pouch and then is dependent on mom for another 1 to 2 months longer.
Ordinarily, brushtail possums are tree-dwellers; their long, prehensile tails and opposable digits are ideal for grasping tree branches. They dine on leaves, fruits, and flowers and were once common all over Australia. But now they're largely absent from the interior of the country, and they can too often be found living in the eaves and attics of suburban houses, raiding trash cans for their dinners. Introduced to New Zealand in 1840, they're a major pest species in that country as well, and population control efforts include attempts to popularize possum-fur garments. Leanne Soylemez and Matt Hutchinson were the production editors forSubclassing and Hooking with Visual Basic. Leanne Soylemez was the proofreader. Audrey Doyle was the copyeditor. Linley Dolby provided quality control. Johnna VanHoose Dinse and Brenda Miller wrote the index. Ellie Volckhausen designed the cover of this book, based on a series design by Edie Freedman. The cover image is from The Illustrated Natural History: Mammalia. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe's ITC Garamond font. David Futato designed the interior layout based on a series design by Nancy Priest. Anne-Marie Vaduva converted the files from Microsoft Word to FrameMaker 5.5.6 using tools created by Mike Sierra. The text and heading fonts are ITC Garamond Light and Garamond Book; the code font is Constant Willison. The illustrations that appear in the book were produced by Robert Romano and Jessamyn Read using Macromedia FreeHand 9 and Adobe Photoshop 6. This colophon was written by Leanne Soylemez.
Comments about oreilly Subclassing and Hooking with Visual Basic:
Dot Net Stuff simply does not work.
Examples do not compile.
References in example code are no where to be found.
To be fair I already knew how to Subclass in VB6 and was looking for a guide to migrating to VB.NET
Only considered chapters that were specific to dot net. Seems like the concepts are OK but example code does not work. Thus my opinion is that this is mostly words without substance because the author does not prove them with working examples in VB. No mention in the errata about these glaring errors.
If you are like me and have mounds of existing subclassing code for VB6, have mastered the techniques involved, and are looking for some samples to get you started in VB .NET, this book is NOT for you.
Look elsewhere.
12/19/2002
3.0
Subclassing & Hooking with Visual Basic Review
By Matt
from Undisclosed
Comments about oreilly Subclassing and Hooking with Visual Basic:
I found the book to be very helpful, but it did not explain the C++ code enough for vb6 developers to understand. Also there were no helpful hints or troubleshooting for the C++ code.
7/14/2002
(1 of 1 customers found this review helpful)
2.0
Subclassing & Hooking with Visual Basic Review
By Joe Hattaway
from Undisclosed
Comments about oreilly Subclassing and Hooking with Visual Basic:
The book said that it covered vb.net. However, the sample that I found for the keyboard hooking are for VB6 and do not work for vb.net . I feel that the authors and publishers owe me samples for vb.net as well as for vb6.
7/24/2001
5.0
Subclassing & Hooking with Visual Basic Review
By Dan Hagen
from Undisclosed
Comments about oreilly Subclassing and Hooking with Visual Basic:
Good special-purpose book. Contains materials I have not found anywhere else---which is rare of VB books these days. Overall, I rate this book highly, with the following exception:
Pet Peeve: why does the web site's source code download so sloppy? Several of the VB projects are broken and they all unzip onto just ONE big messy directory. Also, there appear to be several versions of the same code (!) with the same exact file name(s) and different creation dates contained within the Zip!!!. Winzip prompts to overwrite many of it's own packaged files as they HAVE THE SAME FILE NAMES!!
It takes just a few minutes to organize the ZIP so it will unzip into several nicely laid out project directories (and not to mention again---but I guess I am---that several of the project files are broken anyway...)