Functions That Access the Extra Window Data

The functions described in this section manipulate the “extra” data area of a window structure. This structure can contain system information and user-defined data. You specify the size of this data area by using the cbClsExtra and cbWndExtra members of the WNDCLASS structure when you register the window class.

The following Windows 3.x functions get or set 16 bits during each call: GetClassWord, GetWindowWord, SetClassWord, and SetWindowWord.

In Win32, each of these system-information items grows to 32 bits. Therefore, in Win32, you would use the following functions which access 32 bits at a time: GetClassLong, GetWindowLong, SetClassLong, and SetWindowLong.

Each of these functions takes two parameters: a window handle and an offset into the data area. These offsets differ depending on whether you are compiling for Windows 3.x or Win32.

The index values specifying these offsets correspond to each other as follows:

Windows 3.x Win32 (nonportable)
GCW_CURSOR GCL_CURSOR
GCW_HBRBACKGROUND GCL_HBRBACKGROUND
GCW_HICON GCL_HICON
GWW_HINSTANCE GWL_HINSTANCE
GWW_HWNDPARENT GWL_HWNDPARENT
GWW_ID GWL_ID
GWW_USERDATA GWL_USERDATA

In the case of GWW_HWNDPARENT, you can avoid calls to GetWindowLong and GetWindowWord, and instead use a single call to a new API function, GetParent. This API function returns a handle of the appropriate size. The following example illustrates a call to GetParent that has the same results as the #ifdef statements shown in the previous example:

hwndParent = GetParent( hWnd );

Remember that offsets may change for private data that you store in the window structure. You should review this code carefully and recalculate offsets for Win32, noting that some data types, such as handles, increase in size.