Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function changes an attribute of the specified window. SetWindowLongalso sets a 32-bit ( LONG) value at the specified offset into the extra window memory of a window.
LONG SetWindowLong( HWND hWnd , int nIndex , LONG dwNewLong );
Parameters
To set any other value, specify one of the following values:
Value | Description |
---|---|
GWL_EXSTYLE | Sets a new extended window style. |
GWL_STYLE | Sets a new window style. |
GWL_ID | Sets a new identifier of the window. |
GWL_USERDATA | Sets the 32-bit value associated with the window. Each window has a corresponding 32-bit value intended for use by the application that created the window. Windows CE versions 2.0 and later support this value, but Windows CE versions 1.0 and 1.01 do not. |
The following values are also available when the hWndparameter identifies a dialog box:
Value | Description |
---|---|
DWL_DLGPROC | Sets the new address of the dialog box procedure. Windows CE versions 2.0 and later support the this value, but Windows CE versions 1.0 and 1.01 do not. |
DWL_MSGRESULT | Sets the return value of a message processed in the dialog box procedure. |
DWL_USER | Sets new extra information that is private to the application, such as handles or pointers. |
Return Values
The previous value of the specified 32-bit integer indicates success. Zero indicates failure. To get extended error information, call GetLastError.
If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by calling SetLastError(0) before calling SetWindowLong. Then, function failure is indicated by a return value of zero and a GetLastErrorresult that is nonzero.
Remarks
The SetWindowLongfunction fails if the window specified by the hWndparameter does not belong to the same process as the calling thread.
Unaligned access is not supported.
Certain window data is cached, so changes you make using SetWindowLongwill not take effect until you call the SetWindowPosfunction.
If you use SetWindowLongwith the GWL_WNDPROC index to replace the window procedure, the window procedure must conform to the guidelines specified in the description of the WindowProccallback function.
If you use SetWindowLongwith the DWL_MSGRESULT index to set the return value for a message processed by a dialog procedure, you should return TRUE directly afterwards. Otherwise, if you call any function that results in your dialog procedure receiving a window message, the nested window message could overwrite the return value you set using DWL_MSGRESULT.
Calling SetWindowLongwith the GWL_WNDPROC index creates a subclass of the window class used to create the window. An application can subclass a system class, but should not subclass a window class created by another process. The SetWindowLongfunction creates the window subclass by changing the window procedure associated with a particular window class, causing the system to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures.
You must not call SetWindowLongwith the GWL_HWNDPARENT index to change the parent of a child window. Instead, use the SetParentfunction.
Requirements
Runs on | Versions | Defined in | Include | Link to |
---|---|---|---|---|
Windows CE OS | 1.0 and later | Winuser.h |
Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.
See Also
CallWindowProc, GetLastError, GetWindowLong, RegisterClass, SetLastError, SetParent, SetWindowPos, WindowProc, WNDCLASS