HOWTO: Hook Into a Window's Messages Using AddressOfLast reviewed: October 16, 1997Article ID: Q168795 |
The information in this article applies to:
SUMMARYHooking into a Window (sometimes called sub-classing) is a technique that enables interception of the messages that are being sent to that Window. Microsoft Visual Basic version 5.0 allows sub-classing through the use of the AddressOf operator. NOTE: This article's purpose is to demonstrate a hooked message stream. It is beyond the scope of this article to describe any particular application of this technique. WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this sample code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. WARNING: Failure to unhook a window before its imminent destruction will result in application errors, Invalid Page Faults, and data loss. This is due the fact that the new WindowProc function being pointed to no longer exists, but the window has not been notified of the change. Always unhook the sub-classed window upon unloading the sub-classed form or exiting the application. This is especially important while debugging an application that uses this technique within the Microsoft Visual Basic 5.0 Development Environment. Pressing the End button or selecting End from the Run menu without unhooking will cause an Invalid Page Fault and close Microsoft Visual Basic.
MORE INFORMATIONMicrosoft Windows controls applications by sending messages to the windows that are created by each application. These messages alert the targeted window when it's time to redraw, when a mouse button is pressed, and all of the other information a window needs to know in order to act appropriately. Thus, a minimal Windows application consists of a function for which these messages are processed (called WindowProc). This function is registered into the system when the window is created so the system knows where to send messages. The following application consists of a simple form with two command buttons. The code is designed to intercept Windows messages being sent to the form and to print the values of those messages in the Immediate window.
REFERENCESMicrosoft Windows 32 SDK Win32 Programmer Reference CallWindowProc SetWindowLongMicrosoft Visual Basic Books Online Keywords : vb5all kbcode kbusage kbhowto Version : 5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |