ID: Q32167
SuperCls.exe is a sample application that demonstrates the concept of superclassing control windows. Superclassing provides the same capabilities as subclassing; however, it can be much more convenient to use and produces smaller code if there are multiple controls to be altered in the same fashion.
The following file is available for download from the Microsoft Software Library:
~ SuperCls.exe (size: 24247 bytes)
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591
TITLE : How to Obtain Microsoft Support Files from Online Services
To superclass, create a new class that uses the control window procedure
instead of the default window procedure. This enables the application to
process the appropriate messages and to pass the others along to the
default procedure where the messages will be processed correctly based on
the control type.
To implement superclassing, create a window of the type to superclass. Query all available information about the control and use this information when the new window is created, substituting the class name and window procedure. When this window procedure is called, process the desired messages and pass the others to the standard control procedure (determined in the query phase).
By registering a new class, the application can create superclassed controls using the application resource (RC) file or CreateWindow() function without any further work, which can eliminate a number of SetWindowLong() calls if many controls are to be modified in the same manner.
In the SUPERCLS example, the application creates a new control class called "SuperEdit", which is identical to a regular edit control but refuses to accept the "b" character.
Look for the string "SuperEdit" in the .C, .RC, and .DEF files to see the affected areas of the code.
This example shows superclassed Windows controls. Because the class name has been changed and the application's instance is used in the class registration, all controls will be created with this application's DS. This causes no problems for controls. However, this does not work if an attempt is made to superclass something other than a control. In that case, it is desirable to use the application's instance with the class so that it will be destroyed when the application exits. However, it is necessary to perform some additional work before the call to CallWindowProc() to set the DS for the subclassed window procedure. The hInstance passed to CreateWindow() determines which DS the superclassing procedure uses; to have the superclassed procedure use a different DS, it is necessary to change the DS value. For more information, see the notes near the call to CallWindowProc().
Each edit control created using DialogBox(), CreateDialog(), or through an RC file normally has its own DS. When the application changes the class name, the code within Windows that handles edit controls is not activated. Instead, the control uses the application's DS as if it were created using CreateWindow(). This does not cause any difficulties except that when the code for the superclassed edit control calls LocalAlloc(), it consumes space in the application's local heap. This should not cause problems in most cases.
Additional query words: sub class subclass control Keywords : kbfile kbsample kb16bitonly kbGrpUser kbWinOS310 kbWndw kbWndwClass kbWndwProc kbWinOS300
Last Reviewed: December 18, 1998