The SetClassLong function replaces the specified 32-bit (long) value at the specified offset into the extra class memory or the WNDCLASSEX structure for the class to which the specified window belongs.
DWORD SetClassLong(
HWND hWnd, // handle of window
int nIndex, // index of value to change
LONG dwNewLong // new value
);
Value | Action |
---|---|
GCL_CBCLSEXTRA | Sets the size, in bytes, of the extra memory associated with the class. Setting this value does not change the number of extra bytes already allocated. |
GCL_CBWNDEXTRA | Sets the size, in bytes, of the extra window memory associated with each window in the class. Setting this value does not change the number of extra bytes already allocated. For information on how to access this memory, see SetWindowLong. |
GCL_HBRBACKGROUND | Replaces the handle of the background brush associated with the class. |
GCL_HCURSOR | Replaces the handle of the cursor associated with the class. |
GCL_HICON | Replaces the handle of the icon associated with the class. |
GCL_HMODULE | Replaces the handle of the module that registered the class. |
GCL_MENUNAME | Replaces the address of the menu name string. The string identifies the menu resource associated with the class. |
GCL_STYLE | Replaces the window-class style bits. |
GCL_WNDPROC | Replaces the address of the window procedure associated with the class. |
If the function succeeds, the return value is the previous value of the specified 32-bit integer. If the value was not previously set, the return value is zero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If you use the SetClassLong function and the GCL_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the WindowProc callback function.
Calling SetClassLong with the GCL_WNDPROC index creates a subclass of the window class that affects all windows subsequently created with the class. An application can subclass a system class, but should not subclass a window class created by another process.
Reserve extra class memory by specifying a nonzero value in the cbClsExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.
Use the SetClassLong function with care. For example, it is possible to change the background color for a class by using SetClassLong, but this change does not immediately repaint all windows belonging to the class.
Windows CE: The nIndex parameter is a byte offset but must be a multiple of 4 bytes. Unaligned access is not supported.
None of the standard GCL_* values are supported in the nIndex parameter, with one exception. If the device you are targetting supports a mouse cursor, you can use the GCL_HCURSOR value in the nIndex parameter.
Note Windows CE versions that support mouse cursors include the Iconcurs and Mcursor components rather than the Icon and Cursor components.
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
Window Classes Overview, Window Class Functions, GetClassLong, RegisterClassEx, SetWindowLong, WindowProc, WNDCLASSEX