Scope of Window Classes

Last reviewed: July 22, 1997
Article ID: Q28353
3.00 3.10 WINDOWS kbprgt

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0

SUMMARY

This article discusses the scope of window classes created by the RegisterClass function and used by the CreateWindow function.

MORE INFORMATION

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: 3.00 3.10
KBCategory: kbprgt
KBSubcategory: UsrCls
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.