Using GetForegroundWindow() When Desktop Is Not Active

Last reviewed: September 29, 1995
Article ID: Q118624
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1 and 3.5
    

GetForegroundWindow() is documented to return the handle of the foreground window, that is, the window that the user is currently working with. The proper handle is returned when the desktop that the application is running on is active; however, when another desktop is active, GetForegroundWindow() returns NULL.

This is expected behavior. There is no way to get the active window in your own desktop while another desktop is active.

The application desktop is one desktop. Other desktops include the logon and screen saver desktops. If GetForegroundWindow() returned a handle to the logon dialog box, it would be possible to create an application that could get user passwords. This would violate Windows NT security.

For this reason, it is not possible to create screen savers that melt or drop out.


Additional reference words: 3.10 3.50
KBCategory: kbui
KBSubcategory: UsrWndw


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: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.