RegisterClassEx Function

The RegisterClassEx function registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.

Syntax

ATOM RegisterClassEx(      
    CONST WNDCLASSEX *lpwcx );

Parameters

lpwcx
[in] Pointer to a WNDCLASSEX structure. You must fill the structure with the appropriate class attributes before passing it to the function.

Return Value

If the function succeeds, the return value is a class atom that uniquely identifies the class being registered. This atom can only be used by the CreateWindow, CreateWindowEx, GetClassInfo, GetClassInfoEx, FindWindow, FindWindowEx, and UnregisterClass functions and the IActiveIMMap::FilterClientWindows method.

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

Remarks

If you register the window class by using RegisterClassExA, the application tells the system that the windows of the created class expect messages with text or character parameters to use the ANSI character set; if you register it by using RegisterClassExW, the application requests that the system pass text parameters of messages as Unicode. The IsWindowUnicode function enables applications to query the nature of each window. For more information on ANSI and Unicode functions, see Conventions for Function Prototypes.

All window classes that an application registers are unregistered when it terminates.

Windows 95/98/Me: All window classes registered by a DLL are unregistered when the .dll is unloaded.

Windows NT/2000/XP: No window classes registered by a DLL are unregistered when the DLL is unloaded. A DLL must explicitly unregister its classes when it is unloaded.

Windows 95/98/Me: RegisterClassEx fails if the cbWndExtra or cbClsExtra member of the WNDCLASSEX structure contains more than 40 bytes.

Windows 95/98/Me: RegisterClassExW is supported by the Microsoft Layer for Unicode (MSLU). 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 Using Window Classes.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 4.0
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags :


Community Content

Chris_Guzak
avoid testing the return value of this function

since a class an only be registered once the second caller will fail if it tries to register the class again.

instead of trying to detect this using GetClassInfo(), a solution that does not work in a multi-threaded program due to a race condition; it is better to simply ignore the return value from this function and pick up the failure when CreateWindow() is called as that will fail due to "class not registered".

Tags :

neptunecentury
return value is zero on failure
it is ok to test the return value. "If the function fails, the return value is zero" it will fail if a parameter is not set correctly, or if the class is already registered. You should not have to use GetClassInfo to see if the function failed.
Tags :

Page view tracker