1.2.1 Window Classes

A window class is a set of attributes that defines how a window looks and behaves. Before an application can create and use a window, it must define and register a window class for that window. An application registers a class by passing values for each element of the class to the RegisterClass function. Any number of window classes can be registered. Once a class has been registered, Windows lets the application create any number of windows belonging to that class. The registered class remains available until it is deleted or the application terminates.

Although the complete window class consists of many elements, Windows requires only that an application supply a class name, an address to the window procedure that will process all messages sent to windows belonging to this class, and an instance handle that identifies the application that registered the class. The other elements of the window class define default attributes for windows of the class, such as the shape of the cursor and the content of the menu for the window.

There are three types of window classes. They differ in scope and when they are created and destroyed.

System Global Classes

Windows creates system global classes when it starts. These classes are available for use by all applications at all times. Because Windows creates system global classes on behalf of all applications, an application cannot create or destroy any of these classes. Examples of system global classes include edit-control and list-box control classes.

Application Global Classes

An application or (more likely) a library creates an application global class by specifying the CS_GLOBALCLASS style for the class. Once created, it is globally available to all applications within the system. Most often, a library creates an application global class so that applications which call the library can use the class. Windows destroys an application global class when the application or library that created it terminates. For this reason, it is essential that all applications destroy all windows using that class before the library or application that created the class terminates.

Application Local Classes

An application local class is any window class created by an application for its exclusive use. This is the most common type of class created by an application.