SetWindowLong

  LONG SetWindowLong(hwnd, nIndex, lNewLong)    
  HWND hwnd; /* handle of window */
  int nIndex; /* offset of value to set */
  LONG lNewLong; /* new value */

This function changes an attribute of the window specified by the hwnd parameter.

This function is unicode or ansi. This information is needed for subclassing so the system knows that the subclassing procedure is expecting unicode or ansi window messages.

Parameters

hwnd

Identifies the window.

nIndex

Specifies the byte offset of the attribute to be changed. It may also be one of the following values:

Value Meaning

GWL_EXSTYLE  
  Sets a new extended window style.
GWL_STYLE  
  Sets a new window style.
GWL_WNDPROC  
  Sets a new pointer to the window procedure.
GWL_HINSTANCE  
  Handle of the instance.
GWL_ID  
  Control ID of the child window.
GWL_USERDATA  
  This index can be used to access a LONG that is reserved in every window structure. This LONG is reserved specifically for applications. In general an application should not store values in this LONG if the associated window was created by some other application.

lNewLong

Specifies the replacement value.

Return Value

The return value specifies the previous value of the specified long integer.

Comments

If the SetWindowLong function and the GWL_WNDPROC index are used to set a new window function, that function must have the window-function form and be exported in the module-definition file of the application. For more information, see the RegisterClass function, earlier in this chapter.

Calling SetWindowLong with the GCL_WNDPROC index creates a subclass of the window class used to create the window. See Chapter 1, Window Manager Interface Functions, for more information on window subclassing. An application should not attempt to subclass a window created by another process because it won't work.

To access any extra four-byte values allocated when the window-class structure was created, use a positive byte offset as the index specified by the nIndex parameter, starting at zero for the first four-byte value in the extra space, 4 for the next four-byte value and so on.

See Also

RegisterClass, GetWindowLong, GetWindowWord, SetWindowWord