Application Class Values

When a Windows application class is defined, normally within the WinMain procedure, several class values are assigned before the window class is registered. Under Windows 3.x, several of these are WORD values; under Windows 98/95/NT, DWORD values are used. Following is a fragmentary listing from a WinMain procedure that might belong to either a Windows 3.x or a 98/95/NT application.

    wc.style         = NULL;
    wc.lpfnWndProc   = (WNDPROC) WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon( hInstance, APP_ICON );
    wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = GetStockObject( WHITE_BRUSH );
    wc.lpszMenuName  = APP_MENU;
    wc.lpszClassName = szAppName;
    return( RegisterClass( &wc ) );

However, because the values used are assigned either as constants (wc.lpszMenuName and wc.lpszClassName) or by indirect reference (wc.hIcon and wc.hCursor), the question of whether a WORD or DWORD value is being used doesn’t really come up—at least, not at this time. But there are other circumstances where an application may quite reasonably desire to change one or more of these window class elements. Under Windows 3.x, this is normally accomplished using the SetClassWord function, as:

    SetClassWord( hwnd, GCW_HCURSOR, LoadCursor( hInst, HrGls[11] ) );                // 3.x

In this fragmentary example, the constant GCW_HCURSOR designates the wc.hCursor field as the element to be changed. The SetClassWord function, however, explicitly changes a WORD value and, for Windows 98/95/NT, the corresponding field is a DWORD or LONG value. Therefore, for Windows 98/95/NT applications, the SetClassWord function is replaced by a new function, SetClassLong, which is called as:

    SetClassLong( hwnd, GCL_HCURSOR, 
                  LoadCursor( hInst, HrGls[11] ) );    // 98/95/NT

Notice also that the GCW_HCURSOR constant has been changed to become GCL_HCURSOR.

The danger—in this pair of functions and in converting applications from Windows 3.x to 98/95/NT—is that the SetClassWord function has not been totally superseded by the SetClassLong function. Instead, both forms continue to be supported, as are both the GCW_xxxx and GCL_xxxx constants. And, in some circumstances, the SetClassWord function remains valid and useful. However, any applications being translated into Windows 98/95/NT format that use the SetWindowWord function to change window class assignments should be particularly careful to translate these to SetWindowLong API function calls, and to replace the GCW_xxxx constants with the corresponding GCL_xxxx constants.

© 1998 SYBEX Inc. All rights reserved.