Registering a Window Class

A window class defines the attributes of a window, such as its style, icon, cursor, menu, and window procedure. The first step in registering a window class is to fill in a WNDCLASSEX structure with the window class information. For more information, see Elements of a Window Class. Next, pass the structure to the RegisterClassEx function. For more information, see Using Window Classes.

To register an application global class, specify the CS_GLOBALCLASS style in the style member of the WNDCLASSEX structure. When registering an application local class, do not specify the CS_GLOBALCLASS style.

If you register the window class using the ANSI version of RegisterClassEx, RegisterClassExA, the application requests that the system pass text parameters of messages to the windows of the created class using the ANSI character set; if you register the class using the Unicode version of RegisterClassEx, RegisterClassExW, the application requests that the system pass text parameters of messages to the windows of the created class using the Unicode character set. The IsWindowUnicode function enables applications to query the nature of each window. For more information on ANSI and Unicode functions in the Win32 API, see Win32 Function Prototypes.

The executable or DLL that registered the class is the owner of the class. The system determines class ownership from the hInstance member of the WNDCLASSEX structure passed to the RegisterClassEx function when the class is registered. For DLLs, the hInstance member must be the instance handle of the DLL.

Windows 95: The class is destroyed when the owner closes or is unloaded. For this reason, the process must destroy all windows using the class before the owner closes or is unloaded.

Windows NT: The class is not destroyed when the DLL that owns it is unloaded. Therefore, if the system calls the window procedure for a window of that class, it will cause an access violation, because the DLL containing the window procedure is no longer in memory. The process must destroy all windows using the class before the DLL is unloaded and call the UnregisterClass function.