Press releases

O'Reilly Author Helps VB Developers Explore the Hidden Power of Subclassing and Hooking

Press release: June 26, 2001

Sebastopol, CA--Windows is essentially a messaging system: every user action creates one or more messages to carry out the action. Clicking a button control is a good example, as author Stephen Teilhet explains in his new book, Subclassing & Hooking with Visual Basic (O'Reilly, US $49.95). In addition to generating the message for the mouse button click, the action produces a wide array of other messages, including messages to repaint the button in its depressed state, messages to determine the state of the mouse cursor, and others. The way it works is not unlike the way a simple action of your hand sends sensory information, or messages, from your motor nerves to your brain. Neurons in your brain receive and analyze the information, then pass other messages on to trigger appropriate actions. In just this way, a simple action in Windows can produce an astonishing flurry of messages to carry out the actions of the operating system.

Subclassing and the Windows hooking mechanism are two very powerful techniques that operate on messages within the Windows messaging system. As Teilhet explains, "Simply put, subclassing and hooking involve the interception of messages. Being able to examine and manipulate messages allows developers to have more control over their applications as well as the operating system. For example, when a window is being resized, several different types of messages are being sent to that window. With subclassing, the developer can control how and if the user can resize or move the window by intercepting and modifying a few of these messages." According to Teilhet, the Windows operating system has hundreds of messages it can send to a window. Using subclassing and hooking, developers can control or manipulate any of these messages to achieve their desired results.

Teilhet also explains that responsibility accompanies the power that subclassing and hooking give developers. He cautions, "It's up to the developer to make sure that he or she is using these techniques correctly. Windows is very unforgiving if these techniques are used incorrectly."

Teilhet guides developers through the basics of these techniques and well beyond, beginning with a thorough introduction to the Windows messaging system. He proceeds with a detailed discussion of the methods of intercepting and handling Windows messages, including the differences between subclassing and hooking. Subclassing techniques deal with intercepting messages bound for one or more windows or controls. The messages are intercepted before they reach their destination window. Hooking also deals with intercepting messages, but with a much broader scope than subclassing. Hooking allows a developer to intercept messages at various set points within the operating system.

Teilhet has written this book primarily for VB and VB.NET developers, but adds that developers using other languages such as C/C++/Managed C++, C# or even Borland's Delphi will be able to get a better understanding of how subclassing and hooking operate at a lower level. "This is a very advanced book," Teilhet says, "but I have written and organized it so that anyone from the beginner to the more advanced developer who wants a deeper understanding of VB, VB.NET, the Windows messaging system, subclassing, and hooking can obtain that information without becoming confused or having to buy other books."

Teilhet adds that many of the rules outlined in his book for writing good subclassing and hooking code carry over to VB.NET from VB5 and VB6. The author also discusses WinForm and delegates as they are used in VB.NET. C# developers will find that this information is easily ported from VB.NET to C#.

Online Resources:

Subclassing & Hooking with Visual Basic
By Stephen Teilhet
June 2001
ISBN 0-596-00118-5, 685 pages, $49.95 (US)
order@oreilly.com
1-800-998-9938

About O’Reilly

For over 40 years, O’Reilly has provided technology and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through the company’s SaaS-based training and learning platform. O’Reilly delivers highly topical and comprehensive technology and business learning solutions to millions of users across enterprise, consumer, and university channels. For more information, visit www.oreilly.com.

Email a link to this press release