Microsoft KB Archive/198590

{|
 * width="100%"|

BUG: EnumDesktopWindows Might Enumerate the Wrong Desktop

 * }

Q198590

-

The information in this article applies to:


 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 4.0
 * Microsoft Win32 Application Programming Interface (API)

-

SYMPTOMS
If a desktop has no child windows, a call to EnumDesktopWindows may enumerate windows on a different desktop.

CAUSE
This is caused by a bug in the operating system.

RESOLUTION
To ensure that EnumDesktopWindows is enumerating the intended desktop, use GetWindowThreadProcessID, GetThreadDesktop, and/or GetUserObjectInformation functions to verify that the desktop is correct.

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION
This bug will affect those applications that attempt to enumerate a desktop immediately after it has been created, or in a scenario where there are currently no child windows of the desktop.

The following code snippet uses GetThreadDesktop to validate that the correct desktop is being enumerated. Be sure to free any desktop handles opened with GetThreadDesktop by calling CloseDesktop.

  HDESK hdesk; hdesk = GetThreadDesktop( GetCurrentThreadId ); EnumDesktopWindows( hdesk, EnumProc, (LPARAM)hdesk ); .  .   .   return;

BOOL CALLBACK EnumProc( HWND hwnd, LPARAM lParam ) {

DWORD dwThreadId; HDESK hdesk;

dwThreadId = GetWindowThreadProcessId( hwnd, NULL ); hdesk = GetThreadDesktop( dwThreadId );

if( hdesk && hdesk != (HDESK)lParam ) { return FALSE; } else { // now certain this is the desktop we want to enumerate .       .        .      }

return TRUE;

} Additional query words: kbDSupport

Keywords : kbOSWinNT400bug kbScreenSaver kbWndwMsg

Issue type : kbbug

Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT400xsearch kbWinNTSsearch kbWinNTS400xsearch kbWinNTS400 kbAudDeveloper kbWin32sSearch kbWin32API