Microsoft KB Archive/32167

{|
 * width="100%"|

SuperCls.exe Demonstrates Superclassing

 * }

Q32167

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1

-

SUMMARY
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.

MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

"SuperCls.exe" For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

"Q119591 How to Obtain Microsoft Support Files from Online Services" Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.

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 &quot;SuperEdit&quot;, which is identical to a regular edit control but refuses to accept the &quot;b&quot; character.

Look for the string &quot;SuperEdit&quot; 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 kbGrpDSUser kbOSWin310 kbWndw kbWndwClass kbWndwProc kbOSWin300

Issue type :

Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310