GetThreadDesktop

The GetThreadDesktop function returns a handle to the desktop associated with a specified thread.

HDESK GetThreadDesktop(
  DWORD dwThreadId   // thread identifier
);
 

Parameters

dwThreadId
Handle to the thread for which to return the desktop handle. The GetCurrentThreadId and CreateProcess functions return thread identifiers.

Return Values

If the function succeeds, the return value is a handle to the desktop associated with the specified thread. You do not need to call the CloseDesktop function to close the returned handle.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The system associates a desktop with a thread when that thread is created. A thread can use the SetThreadDesktop function to change its desktop. The desktop associated with a thread must be on the window station associated with the thread's process.

The calling process can use the returned handle in calls to the GetUserObjectInformation, GetUserObjectSecurity, SetUserObjectInformation, and SetUserObjectSecurity functions.

Windows 95 and Windows 98: The system does not support multiple desktops, so GetThreadDesktop always returns the same value.

Windows NT version 3.51: A Win32 service does not have an associated window station or desktop until the service calls a USER or GDI function that interacts with the desktop. If a service calls GetThreadDesktop before it has an associated desktop, the return value is NULL. After a service interacts with the desktop, the return value is a valid desktop handle.

Windows NT: A Win32 service is created with an associated window station and desktop, so there is no need to call a USER or GDI function to connect the service to a window station and desktop.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.

See Also

Window Stations and Desktops Overview, Window Station and Desktop Functions, GetCurrentThreadId, GetProcessWindowStation, GetUserObjectInformation, GetUserObjectSecurity, SetProcessWindowStation, SetThreadDesktop, SetUserObjectInformation, SetUserObjectSecurity