1.2.10 Window Subclassing

A subclass is a window or set of windows that belong to the same window class, and whose messages are intercepted and processed by another window function (or functions) before being passed to the class window function.

To create the subclass, the SetWindowLong function is used to change the window function associated with a particular window, causing Windows to call the new window function instead of the previous one. Any messages not processed by the new window function must be passed to the previous window function by calling the CallWindowProc function. This allows Windows to create a chain of window functions. The address of the previous window function can be retrieved by using the GetWindowLong function before using SetWindowLong.

Similarly, the SetClassLong function changes the window function associated with a window class. Any window that is subsequently created with that class will be associated with the replacement window function for that class, as will the window whose handle is passed to SetClassLong. Other existing windows that were previously created with the class are not affected, however.

When you subclass a window or class of windows, you must export the replacement window procedure in your application's definition file, and you must create the address of the procedure which you pass to SetWindowLong or SetClassLong by calling the MakeProcInstance function.

NOTE:

An application should not attempt to create a window subclass for standard Windows controls such as combo boxes and buttons.