Subclassing the Desktop and Windows of Other Applications

Last reviewed: July 23, 1997
Article ID: Q79276
3.00 3.10 WINDOWS kbprg

The information in this article applies to:

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

SUMMARY

The code to subclass the desktop window, or windows that belong to other applications, must be placed in a dynamic-link library (DLL).

MORE INFORMATION

In most cases, the desktop window uses the stack segment (SS) of the currently scheduled task. This is done for performance reasons because it reduces the number of task switches that take place when the desktop receives paint or mouse messages. In some cases, the desktop cannot be switched immediately to the currently scheduled task. In this situation, it will temporarily use the SS of the previously scheduled task.

When the desktop is subclassed, the data segment (DS) that the subclass procedure uses is specified by the hInstance used in a MakeProcInstance() call. However, the subclass procedure's SS depends on the currently scheduled task, as described earlier. Because the currently scheduled task may not be the task that subclassed the desktop, it is possible that SS != DS when the subclass procedure is executed. Therefore, the subclass procedure cannot assume that SS == DS. For this reason, the code to subclass the desktop must reside in a DLL where it is assumed that SS != DS.

When a window belonging to another application is subclassed, the DS that the subclass procedure uses is specified by the hInstance used in the MakeProcInstance() call. The SS used by the subclass procedure is the SS of the application that owns the window. Therefore, the subclass procedure cannot assume that SS == DS. For this reason, the code to subclass another application's window must reside in a DLL where it is assumed that SS != DS.

The DLL in which the subclass procedure is placed should be compiled with the Microsoft C Compiler's -Aw option, which tells the compiler that SS != DS. Using this option causes the compiler to generate a warning message when it detects the improper creation of a near pointer to an automatic variable.


Additional reference words: 3.00 3.10
KBCategory: kbprg
KBSubcategory: UsrWndw
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 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.