Extending Standard Windows Controls Through SuperclassingLast reviewed: November 29, 1995Article ID: Q76947 |
The information in this article applies to:
SUMMARYA Windows-based application can extend the behavior of a standard Windows control by using the technique of superclassing. An application can superclass a standard Windows control by retrieving its window class information, modifying the fields of the WNDCLASS structure, and registering a new class. For example, to associate status information with each button control in an application, the buttons can be superclassed to provide a number of window extra bytes. This article describes a technique to access the WNDCLASS structure associated with the standard "button" class.
MORE INFORMATIONThe following five steps are necessary to register a new class that uses some information from the standard windows "button" class:
Any new class created in this manner MUST have a unique class name. Typically, this name would be similar but not identical to the original class. For example, to superclass a button, an appropriate class name might be "superbutton." There is no conflict with class names used by other applications as long as the CS_GLOBALCLASS class style is not specified. The standard Windows "button" class remains unchanged and can still be used by the application as normal. In addition, once a new class has been registered, any number of controls can be created and destroyed with no extra coding effort. The superclass is simply another class in the pool of classes that can be used when creating a window. The sample code below demonstrates this procedure: BOOL DefineSuperButtonClass(void) { #define MYEXTRABYTES 8 HWND hButton; WNDCLASS wc; static char pszClassName[] = "superbutton"; GetClassInfo(NULL, "button", (LPWNDCLASS)&wc); iStdButtonWndExtra = wc.cbWndExtra; // Save this in a global wc.cbWndExtra += MYEXTRABYTES; wc.lpszClassName= pszClassName; return(RegisterClass((LPWNDCLASS)&wc));} It is important to note that the lpszClassName, lpszMenuName, and hInstance fields in the WNDCLASS structure are NOT returned by the GetClassInfo() function. Please refer to page 4-153 of the "Microsoft Windows Software Development Kit Reference Volume 1" for more information. Also, each time a new class is registered, scarce system resources are used. If it is necessary to alter many different standard classes, the GetProp(), SetProp(), and RemoveProp() functions should be used as an alternative approach to associating extra information with standard Windows controls.
|
Additional reference words: 3.00 3.10 3.50 4.00 95
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |