INF: Scope of Window Classes

ID Number: Q28353

2.03 2.10 3.00 3.10

WINDOWS

Summary:

This article discusses the scope of window classes created by the

RegisterClass function and used by the CreateWindow function.

When an application calls the RegisterClass function, Windows

determines if that application has already registered a class with the

same name. If it has, registration fails because a module can register

only one class under a given name. When an application calls the

CreateWindow function to create a window of a specified class, Windows

looks in the list of registered classes for a class with the specified

class name registered by the calling module. If the class is not

found, Windows looks in the classes list for the specified class name

registered by any module. If the class name is not found, the call to

CreateWindow fails.

This implies that a module can create a window using any other

module's class if and only if it has not registered a class with the

same name. If a module registers a class with the same name as another

module's class, the module can use only its own version. However,

consider the following situation regarding the MyClass window class:

- Application A and Application B each register window classes named

MyClass.

- Application C, which has not registered a MyClass window class,

calls CreateWindow to create a MyClass-class window.

One cannot predict whether Windows will create the window using

Application A's MyClass class or Application B's MyClass class. To be

safe, the name of each window class should include the registering

application's name.

An application can reference a class defined by a dynamic-link library

(DLL). Under versions of Windows earlier than 3.1, an application should

not reference window classes registered by other applications. This

restriction is caused by the expanded memory manager (EMM) provided by

Windows real mode. Under certain conditions, the window procedure in

the module that registers a class is not available while the

application that created the window is running.

Additional reference words: 2.03 2.10 3.00 3.10 2.x TAR73212