Windows/Windows API

SetClassLong, GetClassLong

aucd29 2013. 10. 1. 18:53

WNDCLASS(EX) 구조체의 값은 윈도우를 등록할 때 정해진다. 일단 윈도우 클래스가 등록되고 윈도우가 만들어진 뒤 WNDCLASS값을 변경 시키거나 조사하려면 다음 함수를 이용해야한다.

SetClassLong Function



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.

Note  This function has been superseded by the SetClassLongPtr function. To write code that is compatible with both 32-bit and 64-bit versions of Microsoft? Windows?, use SetClassLongPtr.

Syntax

DWORD SetClassLong(      

    HWND hWnd,     int nIndex,     LONG dwNewLong );

Parameters

hWnd
[in] Handle to the window and, indirectly, the class to which the window belongs.
nIndex
[in] Specifies the 32-bit value to replace. To set a 32-bit value in the extra class memory, specify the positive, zero-based byte offset of the value to be set. Valid values are in the range zero through the number of bytes of extra class memory, minus four; for example, if you specified 12 or more bytes of extra class memory, a value of 8 would be an index to the third 32-bit integer. To set any other value from the WNDCLASSEX structure, specify one of the following values.
GCL_CBCLSEXTRA
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
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 a handle to the background brush associated with the class.
GCL_HCURSOR
커서값
Replaces a handle to the cursor associated with the class.
GCL_HICON
Replaces a handle to the icon associated with the class.
GCL_HICONSM
Replace a handle to the small icon associated with the class.
GCL_HMODULE
hInstance값
Replaces a handle to the module that registered the class.
GCL_MENUNAME
hMenu값
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.
dwNewLong
[in] Specifies the replacement value.

Return Value

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.



Remarks

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 95/98/Me: SetClassLongW is supported by the Microsoft Layer for Unicode (MSLU). Note that subsequent calls to this function will overwrite the results of previous calls, so you must save any results that you want to use later. To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example

For an example, see Displaying an Icon.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP

See Also

Window Classes Overview, GetClassLong, RegisterClassEx, SetClassLongPtr, SetWindowLong, WindowProc, WNDCLASSEX


GetClassLong Function


The GetClassLong function retrieves the specified 32-bit (long) value from the WNDCLASSEX structure associated with the specified window.

Syntax

DWORD GetClassLong(      

    HWND hWnd,     int nIndex );

Parameters

hWnd
[in] Handle to the window and, indirectly, the class to which the window belongs.
nIndex
[in] Specifies the 32-bit value to retrieve. To retrieve a 32-bit value from the extra class memory, specify the positive, zero-based byte offset of the value to be retrieved. Valid values are in the range zero through the number of bytes of extra class memory, minus four; for example, if you specified 12 or more bytes of extra class memory, a value of 8 would be an index to the third 32-bit integer. To retrieve any other value from the WNDCLASSEX structure, specify one of the following values.
GCW_ATOM
Retrieves an ATOM value that uniquely identifies the window class. This is the same atom that the RegisterClassEx function returns.
GCL_CBCLSEXTRA
Retrieves the size, in bytes, of the extra memory associated with the class.
GCL_CBWNDEXTRA
Retrieves the size, in bytes, of the extra window memory associated with each window in the class. For information on how to access this memory, see GetWindowLong.
GCL_HBRBACKGROUND
Retrieves a handle to the background brush associated with the class.
GCL_HCURSOR
Retrieves a handle to the cursor associated with the class.
GCL_HICON
Retrieves a handle to the icon associated with the class.
GCL_HICONSM
Retrieves a handle to the small icon associated with the class.
GCL_HMODULE
Retrieves a handle to the module that registered the class.
GCL_MENUNAME
Retrieves the address of the menu name string. The string identifies the menu resource associated with the class.
GCL_STYLE
Retrieves the window-class style bits.
GCL_WNDPROC
Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure.

Return Value

If the function succeeds, the return value is the requested 32-bit value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.



Remarks

Reserve extra class memory by specifying a nonzero value in the cbClsExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.

Windows 95/98/Me: GetClassLongW is supported by the Microsoft? Layer for Unicode (MSLU). Note that subsequent calls to this function will overwrite the results of previous calls, so you must save any results that you want to use later. To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP

See Also

Window Classes Overview, GetClassLongPtr, GetWindowLong, RegisterClassEx, SetClassLong, WNDCLASSEX