SuperCls.exe Demonstrates Superclassing

ID: 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. Click the file name below to download the file:

SuperCls.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

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
Version : WINDOWS:3.0,3.1
Platform : WINDOWS
Issue type :


Last Reviewed: December 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.