Microsoft KB Archive/118624

{|
 * width="100%"|

HOWTO: Use GetForegroundWindow When Desktop Is Not Active

 * }

Q118624

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), used with:
 * the operating system: Microsoft Windows NT, versions 3.1, 3.5, 4.0
 * the operating system: Microsoft Windows 2000

-

SUMMARY
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 query words:

Keywords : kbOSWinNT310 kbOSWinNT350 kbOSWinNT400 kbOSWin2000 kbSDKWin32 kbGrpDSUser kbWndw

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch