HOWTO: Use SetClassLong Function to Subclass a Window Class (32519)



The information in this article applies to:

  • Microsoft Platform Software Development Kit (SDK) 1.0

This article was previously published under Q32519

SUMMARY

It is possible to subclass an entire window class by using the SetClassLong() function. However, doing so will only subclass windows of that class created after the call to the SetClassLong() function. Windows created before the call to the SetClassLong() function are not affected.

In Win32, SetClassLong() only affects Windows in the same address space. For example, if you subclass EDIT, only edit controls created in your application will be subclassed.

NOTE: This function has been superceded by the SetClassLongPtr() function. To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetClassLongPtr().

MORE INFORMATION

Calling the SetClassLong() function with the GCL_WNDPROC index changes the class function address for that window class, creating a subclass of the window class. When a subsequent window of that class is created, the new class function address is inserted into its window structure, subclassing the new window. Windows created before the call to the SetClassLong() function (in other words, before the class function address was changed) are not subclassed.

An application should not use the SetClassLong() function to subclass standard Windows controls such as edit controls or buttons. If, for example, an application were to subclass the entire "edit" class, then subsequent edit controls created by other applications would be subclassed.

An application can subclass individual standard Windows controls that it has created by calling the SetWindowLong() function.

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbhowto kbWndw kbWndwClass kbWndwProc KB32519