2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/desktop.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
24 IN OUT PDESKTOP Desktop
27 /* GLOBALS *******************************************************************/
29 /* Currently active desktop */
30 PDESKTOP InputDesktop
= NULL
;
31 HDESK InputDesktopHandle
= NULL
;
32 HDC ScreenDeviceContext
= NULL
;
33 BOOL g_PaintDesktopVersion
= FALSE
;
35 GENERIC_MAPPING IntDesktopMapping
=
37 STANDARD_RIGHTS_READ
| DESKTOP_ENUMERATE
|
39 STANDARD_RIGHTS_WRITE
| DESKTOP_CREATEMENU
|
40 DESKTOP_CREATEWINDOW
|
42 DESKTOP_JOURNALPLAYBACK
|
43 DESKTOP_JOURNALRECORD
|
45 STANDARD_RIGHTS_EXECUTE
| DESKTOP_SWITCHDESKTOP
,
46 STANDARD_RIGHTS_REQUIRED
| DESKTOP_CREATEMENU
|
47 DESKTOP_CREATEWINDOW
|
50 DESKTOP_JOURNALPLAYBACK
|
51 DESKTOP_JOURNALRECORD
|
53 DESKTOP_SWITCHDESKTOP
|
57 /* OBJECT CALLBACKS **********************************************************/
61 IntDesktopObjectParse(IN PVOID ParseObject
,
63 IN OUT PACCESS_STATE AccessState
,
64 IN KPROCESSOR_MODE AccessMode
,
66 IN OUT PUNICODE_STRING CompleteName
,
67 IN OUT PUNICODE_STRING RemainingName
,
68 IN OUT PVOID Context OPTIONAL
,
69 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL
,
74 OBJECT_ATTRIBUTES ObjectAttributes
;
75 PLIST_ENTRY NextEntry
, ListHead
;
76 PWINSTATION_OBJECT WinStaObject
= (PWINSTATION_OBJECT
)ParseObject
;
77 PUNICODE_STRING DesktopName
;
79 /* Set the list pointers and loop the window station */
80 ListHead
= &WinStaObject
->DesktopListHead
;
81 NextEntry
= ListHead
->Flink
;
82 while (NextEntry
!= ListHead
)
84 /* Get the current desktop */
85 Desktop
= CONTAINING_RECORD(NextEntry
, DESKTOP
, ListEntry
);
88 DesktopName
= GET_DESKTOP_NAME(Desktop
);
91 /* Compare the name */
92 if (RtlEqualUnicodeString(RemainingName
,
94 (Attributes
& OBJ_CASE_INSENSITIVE
)))
96 /* We found a match. Did this come from a create? */
99 /* Unless OPEN_IF was given, fail with an error */
100 if (!(Attributes
& OBJ_OPENIF
))
103 return STATUS_OBJECT_NAME_COLLISION
;
107 /* Otherwise, return with a warning only */
108 Status
= STATUS_OBJECT_NAME_EXISTS
;
113 /* This was a real open, so this is OK */
114 Status
= STATUS_SUCCESS
;
117 /* Reference the desktop and return it */
118 ObReferenceObject(Desktop
);
124 /* Go to the next desktop */
125 NextEntry
= NextEntry
->Flink
;
128 /* If we got here but this isn't a create, then fail */
129 if (!Context
) return STATUS_OBJECT_NAME_NOT_FOUND
;
131 /* Create the desktop object */
132 InitializeObjectAttributes(&ObjectAttributes
, RemainingName
, 0, NULL
, NULL
);
133 Status
= ObCreateObject(KernelMode
,
142 if (!NT_SUCCESS(Status
)) return Status
;
144 /* Initialize shell hook window list and set the parent */
145 RtlZeroMemory(Desktop
, sizeof(DESKTOP
));
146 InitializeListHead(&Desktop
->ShellHookWindows
);
147 Desktop
->rpwinstaParent
= (PWINSTATION_OBJECT
)ParseObject
;
149 /* Put the desktop on the window station's list of associated desktops */
150 InsertTailList(&Desktop
->rpwinstaParent
->DesktopListHead
,
151 &Desktop
->ListEntry
);
153 /* Set the desktop object and return success */
155 return STATUS_SUCCESS
;
159 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters
)
161 PDESKTOP Desktop
= (PDESKTOP
)Parameters
->Object
;
163 DPRINT("Deleting desktop (0x%X)\n", Desktop
);
165 /* Remove the desktop from the window station's list of associcated desktops */
166 RemoveEntryList(&Desktop
->ListEntry
);
168 IntFreeDesktopHeap(Desktop
);
171 /* PRIVATE FUNCTIONS **********************************************************/
175 InitDesktopImpl(VOID
)
177 /* Set Desktop Object Attributes */
178 ExDesktopObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
= sizeof(DESKTOP
);
179 ExDesktopObjectType
->TypeInfo
.GenericMapping
= IntDesktopMapping
;
180 return STATUS_SUCCESS
;
185 CleanupDesktopImpl(VOID
)
187 return STATUS_SUCCESS
;
190 static int GetSystemVersionString(LPWSTR buffer
)
192 RTL_OSVERSIONINFOEXW versionInfo
;
195 versionInfo
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
197 if (!NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&versionInfo
)))
200 if (versionInfo
.dwMajorVersion
<= 4)
201 len
= swprintf(buffer
,
202 L
"ReactOS Version %d.%d %s Build %d",
203 versionInfo
.dwMajorVersion
, versionInfo
.dwMinorVersion
,
204 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
206 len
= swprintf(buffer
,
207 L
"ReactOS %s (Build %d)",
208 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
215 IntParseDesktopPath(PEPROCESS Process
,
216 PUNICODE_STRING DesktopPath
,
220 OBJECT_ATTRIBUTES ObjectAttributes
;
221 UNICODE_STRING WinSta
, Desktop
, FullName
;
222 BOOL DesktopPresent
= FALSE
;
223 BOOL WinStaPresent
= FALSE
;
235 RtlInitUnicodeString(&WinSta
, NULL
);
236 RtlInitUnicodeString(&Desktop
, NULL
);
238 if(DesktopPath
!= NULL
&& DesktopPath
->Buffer
!= NULL
&& DesktopPath
->Length
> sizeof(WCHAR
))
240 PWCHAR c
= DesktopPath
->Buffer
;
242 USHORT l
= DesktopPath
->Length
;
245 * Parse the desktop path string which can be in the form "WinSta\Desktop"
246 * or just "Desktop". In latter case WinSta0 will be used.
253 wl
= (ULONG_PTR
)c
- (ULONG_PTR
)DesktopPath
->Buffer
;
263 WinSta
.MaximumLength
= wl
+ sizeof(WCHAR
);
264 WinSta
.Buffer
= DesktopPath
->Buffer
;
266 WinStaPresent
= TRUE
;
270 Desktop
.Length
= DesktopPath
->Length
- wl
;
273 Desktop
.Length
-= sizeof(WCHAR
);
275 if(Desktop
.Length
> 0)
277 Desktop
.MaximumLength
= Desktop
.Length
+ sizeof(WCHAR
);
278 Desktop
.Buffer
= ((wl
> 0) ? c
: DesktopPath
->Buffer
);
279 DesktopPresent
= TRUE
;
286 /* search the process handle table for (inherited) window station
287 handles, use a more appropriate one than WinSta0 if possible. */
288 if (!ObFindHandleForObject(Process
,
290 ExWindowStationObjectType
,
295 /* we had no luck searching for opened handles, use WinSta0 now */
296 RtlInitUnicodeString(&WinSta
, L
"WinSta0");
300 if(!DesktopPresent
&& hDesktop
!= NULL
)
303 /* search the process handle table for (inherited) desktop
304 handles, use a more appropriate one than Default if possible. */
305 if (!ObFindHandleForObject(Process
,
312 /* we had no luck searching for opened handles, use Desktop now */
313 RtlInitUnicodeString(&Desktop
, L
"Default");
319 if(!IntGetFullWindowStationName(&FullName
, &WinSta
, NULL
))
321 return STATUS_INSUFFICIENT_RESOURCES
;
324 /* open the window station */
325 InitializeObjectAttributes(&ObjectAttributes
,
327 OBJ_CASE_INSENSITIVE
,
331 Status
= ObOpenObjectByName(&ObjectAttributes
,
332 ExWindowStationObjectType
,
339 ExFreePoolWithTag(FullName
.Buffer
, TAG_STRING
);
341 if(!NT_SUCCESS(Status
))
343 SetLastNtError(Status
);
344 DPRINT("Failed to reference window station %wZ PID: %d!\n", &WinSta
, PsGetCurrentProcessId());
349 if(hDesktop
!= NULL
&& *hDesktop
== NULL
)
351 if(!IntGetFullWindowStationName(&FullName
, &WinSta
, &Desktop
))
355 return STATUS_INSUFFICIENT_RESOURCES
;
358 /* open the desktop object */
359 InitializeObjectAttributes(&ObjectAttributes
,
361 OBJ_CASE_INSENSITIVE
,
365 Status
= ObOpenObjectByName(&ObjectAttributes
,
373 ExFreePoolWithTag(FullName
.Buffer
, TAG_STRING
);
375 if(!NT_SUCCESS(Status
))
380 SetLastNtError(Status
);
381 DPRINT("Failed to reference desktop %wZ PID: %d!\n", &Desktop
, PsGetCurrentProcessId());
386 return STATUS_SUCCESS
;
390 * IntValidateDesktopHandle
392 * Validates the desktop handle.
395 * If the function succeeds, the handle remains referenced. If the
396 * fucntion fails, last error is set.
400 IntValidateDesktopHandle(
402 KPROCESSOR_MODE AccessMode
,
403 ACCESS_MASK DesiredAccess
,
408 Status
= ObReferenceObjectByHandle(
416 if (!NT_SUCCESS(Status
))
417 SetLastNtError(Status
);
423 IntGetDesktopWorkArea(PDESKTOP Desktop
, RECTL
*Rect
)
429 Ret
= &Desktop
->WorkArea
;
430 if((Ret
->right
== -1) && ScreenDeviceContext
)
434 dc
= DC_LockDc(ScreenDeviceContext
);
435 /* FIXME - Handle dc == NULL!!!! */
436 psurf
= dc
->dclevel
.pSurface
;
439 Ret
->right
= psurf
->SurfObj
.sizlBitmap
.cx
;
440 Ret
->bottom
= psurf
->SurfObj
.sizlBitmap
.cy
;
452 IntGetActiveDesktop(VOID
)
458 * returns or creates a handle to the desktop object
461 IntGetDesktopObjectHandle(PDESKTOP DesktopObject
)
466 ASSERT(DesktopObject
);
468 if (!ObFindHandleForObject(PsGetCurrentProcess(),
474 Status
= ObOpenObjectByPointer(DesktopObject
,
481 if(!NT_SUCCESS(Status
))
483 /* unable to create a handle */
484 DPRINT1("Unable to create a desktop handle\n");
490 DPRINT1("Got handle: %lx\n", Ret
);
496 PUSER_MESSAGE_QUEUE FASTCALL
497 IntGetFocusMessageQueue(VOID
)
499 PDESKTOP pdo
= IntGetActiveDesktop();
502 DPRINT("No active desktop\n");
505 return (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
509 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue
)
511 PUSER_MESSAGE_QUEUE Old
;
512 PDESKTOP pdo
= IntGetActiveDesktop();
515 DPRINT("No active desktop\n");
520 if(NewQueue
->Desktop
!= NULL
)
522 DPRINT("Message Queue already attached to another desktop!\n");
525 IntReferenceMessageQueue(NewQueue
);
526 (void)InterlockedExchangePointer((PVOID
*)&NewQueue
->Desktop
, pdo
);
528 Old
= (PUSER_MESSAGE_QUEUE
)InterlockedExchangePointer((PVOID
*)&pdo
->ActiveMessageQueue
, NewQueue
);
531 (void)InterlockedExchangePointer((PVOID
*)&Old
->Desktop
, 0);
532 IntDereferenceMessageQueue(Old
);
536 HWND FASTCALL
IntGetDesktopWindow(VOID
)
538 PDESKTOP pdo
= IntGetActiveDesktop();
541 DPRINT("No active desktop\n");
544 return pdo
->DesktopWindow
;
547 PWINDOW_OBJECT FASTCALL
UserGetDesktopWindow(VOID
)
549 PDESKTOP pdo
= IntGetActiveDesktop();
553 DPRINT("No active desktop\n");
557 return UserGetWindowObject(pdo
->DesktopWindow
);
560 HWND FASTCALL
IntGetMessageWindow(VOID
)
562 PDESKTOP pdo
= IntGetActiveDesktop();
566 DPRINT("No active desktop\n");
569 return pdo
->spwndMessage
->head
.h
;
572 HWND FASTCALL
IntGetCurrentThreadDesktopWindow(VOID
)
574 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
575 PDESKTOP pdo
= pti
->rpdesk
;
578 DPRINT1("Thread doesn't have a desktop\n");
581 return pdo
->DesktopWindow
;
584 BOOL FASTCALL
IntDesktopUpdatePerUserSettings(BOOL bEnable
)
588 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
591 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
593 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
594 QueryTable
[0].Name
= L
"PaintDesktopVersion";
595 QueryTable
[0].EntryContext
= &g_PaintDesktopVersion
;
597 /* Query the "PaintDesktopVersion" flag in the "Control Panel\Desktop" key */
598 Status
= RtlQueryRegistryValues(RTL_REGISTRY_USER
,
599 L
"Control Panel\\Desktop",
600 QueryTable
, NULL
, NULL
);
601 if (!NT_SUCCESS(Status
))
603 DPRINT1("RtlQueryRegistryValues failed for PaintDesktopVersion (%x)\n",
605 g_PaintDesktopVersion
= FALSE
;
609 DPRINT("PaintDesktopVersion = %d\n", g_PaintDesktopVersion
);
615 g_PaintDesktopVersion
= FALSE
;
620 /* PUBLIC FUNCTIONS ***********************************************************/
623 UserGetDesktopDC(ULONG DcType
, BOOL EmptyDC
, BOOL ValidatehWnd
)
625 PWINDOW_OBJECT DesktopObject
= 0;
628 if (DcType
== DC_TYPE_DIRECT
)
630 DesktopObject
= UserGetDesktopWindow();
631 DesktopHDC
= (HDC
)UserGetWindowDC(DesktopObject
);
636 hDev
= (HDEV
)pPrimarySurface
;
637 DesktopHDC
= IntGdiCreateDisplayDC(hDev
, DcType
, EmptyDC
);
646 PWINDOW_OBJECT Window
= NULL
;
648 UserEnterExclusive();
650 Window
= UserGetDesktopWindow();
652 IntInvalidateWindows( Window
,
663 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
665 CSR_API_MESSAGE Request
;
667 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
668 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
669 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
670 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
672 return co_CsrNotify(&Request
);
676 IntHideDesktop(PDESKTOP Desktop
)
679 CSRSS_API_REQUEST Request
;
680 CSRSS_API_REPLY Reply
;
682 Request
.Type
= CSRSS_HIDE_DESKTOP
;
683 Request
.Data
.HideDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
685 return NotifyCsrss(&Request
, &Reply
);
688 PWINDOW_OBJECT DesktopWindow
;
691 DesktopWindow
= IntGetWindowObject(Desktop
->DesktopWindow
);
694 return ERROR_INVALID_WINDOW_HANDLE
;
696 DesktopWnd
= DesktopWindow
->Wnd
;
697 DesktopWnd
->style
&= ~WS_VISIBLE
;
699 return STATUS_SUCCESS
;
708 UserBuildShellHookHwndList(PDESKTOP Desktop
)
711 PSHELL_HOOK_WINDOW Current
;
714 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
715 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
718 if (!entries
) return NULL
;
720 list
= ExAllocatePool(PagedPool
, sizeof(HWND
) * (entries
+ 1)); /* alloc one extra for nullterm */
725 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
726 *cursor
++ = Current
->hWnd
;
728 *cursor
= NULL
; /* nullterm list */
735 * Send the Message to the windows registered for ShellHook
736 * notifications. The lParam contents depend on the Message. See
737 * MSDN for more details (RegisterShellHookWindow)
739 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
741 PDESKTOP Desktop
= IntGetActiveDesktop();
744 static UINT MsgType
= 0;
749 /* Too bad, this doesn't work.*/
752 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
753 MsgType
= UserRegisterWindowMessage(&Str
);
756 MsgType
= IntAddAtom(L
"SHELLHOOK");
758 DPRINT("MsgType = %x\n", MsgType
);
760 DPRINT1("LastError: %x\n", GetLastNtError());
765 DPRINT("IntShellHookNotify: No desktop!\n");
769 HwndList
= UserBuildShellHookHwndList(Desktop
);
772 HWND
* cursor
= HwndList
;
774 for (; *cursor
; cursor
++)
776 DPRINT("Sending notify\n");
777 co_IntPostOrSendMessage(*cursor
,
783 ExFreePool(HwndList
);
789 * Add the window to the ShellHookWindows list. The windows
790 * on that list get notifications that are important to shell
793 * TODO: Validate the window? I'm not sure if sending these messages to
794 * an unsuspecting application that is not your own is a nice thing to do.
796 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
798 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
799 PDESKTOP Desktop
= pti
->rpdesk
;
800 PSHELL_HOOK_WINDOW Entry
;
802 DPRINT("IntRegisterShellHookWindow\n");
804 /* First deregister the window, so we can be sure it's never twice in the
807 IntDeRegisterShellHookWindow(hWnd
);
809 Entry
= ExAllocatePoolWithTag(PagedPool
,
810 sizeof(SHELL_HOOK_WINDOW
),
818 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
824 * Remove the window from the ShellHookWindows list. The windows
825 * on that list get notifications that are important to shell
828 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
830 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
831 PDESKTOP Desktop
= pti
->rpdesk
;
832 PSHELL_HOOK_WINDOW Current
;
834 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
836 if (Current
->hWnd
== hWnd
)
838 RemoveEntryList(&Current
->ListEntry
);
848 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
850 if (Desktop
->hsectionDesktop
!= NULL
)
852 ObDereferenceObject(Desktop
->hsectionDesktop
);
853 Desktop
->hsectionDesktop
= NULL
;
856 /* SYSCALLS *******************************************************************/
859 * NtUserCreateDesktop
861 * Creates a new desktop.
868 * Name of the device.
877 * Requested type of access.
881 * If the function succeeds, the return value is a handle to the newly
882 * created desktop. If the specified desktop already exists, the function
883 * succeeds and returns a handle to the existing desktop. When you are
884 * finished using the handle, call the CloseDesktop function to close it.
885 * If the function fails, the return value is NULL.
893 POBJECT_ATTRIBUTES poa
,
894 PUNICODE_STRING lpszDesktopDevice
,
897 ACCESS_MASK dwDesiredAccess
)
899 OBJECT_ATTRIBUTES ObjectAttributes
;
900 PTHREADINFO W32Thread
;
901 PWINSTATION_OBJECT WinStaObject
;
902 PDESKTOP DesktopObject
;
903 UNICODE_STRING DesktopName
;
904 NTSTATUS Status
= STATUS_SUCCESS
;
906 CSR_API_MESSAGE Request
;
907 PVOID DesktopHeapSystemBase
= NULL
;
908 SIZE_T DesktopInfoSize
;
909 UNICODE_STRING SafeDesktopName
;
911 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
912 HWINSTA hWindowStation
= NULL
;
913 PUNICODE_STRING lpszDesktopName
= NULL
;
914 UNICODE_STRING ClassName
, WindowName
, MenuName
;
916 DECLARE_RETURN(HDESK
);
918 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
919 UserEnterExclusive();
924 sizeof(OBJECT_ATTRIBUTES
),
927 hWindowStation
= poa
->RootDirectory
;
928 lpszDesktopName
= poa
->ObjectName
;
930 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
932 Status
=_SEH2_GetExceptionCode();
936 if (! NT_SUCCESS(Status
))
938 DPRINT1("Failed reading Object Attributes from user space.\n");
939 SetLastNtError(Status
);
943 Status
= IntValidateWindowStationHandle(
946 0, /* FIXME - WINSTA_CREATEDESKTOP */
949 if (! NT_SUCCESS(Status
))
951 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
952 hWindowStation
, lpszDesktopName
);
953 SetLastNtError(Status
);
956 if(lpszDesktopName
!= NULL
)
958 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
959 if(!NT_SUCCESS(Status
))
961 SetLastNtError(Status
);
967 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
970 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
973 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
974 ObDereferenceObject(WinStaObject
);
976 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
980 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
981 ObDereferenceObject(WinStaObject
);
984 * Try to open already existing desktop
987 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
989 /* Initialize ObjectAttributes for the desktop object */
990 InitializeObjectAttributes(
997 Status
= ObOpenObjectByName(
1003 (PVOID
)&DummyContext
,
1005 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
1006 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
1008 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1012 /* Reference the desktop */
1013 Status
= ObReferenceObjectByHandle(Desktop
,
1015 ExDesktopObjectType
,
1017 (PVOID
)&DesktopObject
,
1019 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
1021 DesktopObject
->hsectionDesktop
= NULL
;
1022 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
1023 &DesktopHeapSystemBase
,
1025 if (DesktopObject
->pheapDesktop
== NULL
)
1027 ObDereferenceObject(DesktopObject
);
1028 DPRINT1("Failed to create desktop heap!\n");
1032 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1033 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1035 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1039 if (DesktopObject
->pDeskInfo
== NULL
)
1041 ObDereferenceObject(DesktopObject
);
1042 DPRINT1("Failed to create the DESKTOP structure!\n");
1046 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1049 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1050 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1051 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1052 lpszDesktopName
->Buffer
,
1053 lpszDesktopName
->Length
);
1055 // init desktop area
1056 DesktopObject
->WorkArea
.left
= 0;
1057 DesktopObject
->WorkArea
.top
= 0;
1058 DesktopObject
->WorkArea
.right
= -1;
1059 DesktopObject
->WorkArea
.bottom
= -1;
1060 IntGetDesktopWorkArea(DesktopObject
, NULL
);
1062 /* Initialize some local (to win32k) desktop state. */
1063 InitializeListHead(&DesktopObject
->PtiList
);
1064 DesktopObject
->ActiveMessageQueue
= NULL
;
1065 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1067 if (! NT_SUCCESS(Status
))
1069 DPRINT1("Failed to create desktop handle\n");
1070 SetLastNtError(Status
);
1075 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1077 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1078 * to function at the beginning of the project by ramroding the GUI into
1079 * operation and making the desktop window work from user space.
1082 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1083 Status
= CsrInsertObject(Desktop
,
1085 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1086 if (! NT_SUCCESS(Status
))
1088 DPRINT1("Failed to create desktop handle for CSRSS\n");
1090 SetLastNtError(Status
);
1094 Status
= co_CsrNotify(&Request
);
1095 if (! NT_SUCCESS(Status
))
1097 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1098 DPRINT1("Failed to notify CSRSS about new desktop\n");
1100 SetLastNtError(Status
);
1104 W32Thread
= PsGetCurrentThreadWin32Thread();
1106 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1109 Based on wine/server/window.c in get_desktop_window.
1112 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1113 ClassName
.Length
= 0;
1114 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1115 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1117 pWnd
= co_IntCreateWindowEx( 0,
1120 (WS_POPUP
|WS_CLIPCHILDREN
),
1133 DPRINT1("Failed to create Message window handle\n");
1137 DesktopObject
->spwndMessage
= pWnd
;
1143 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1151 * Opens an existing desktop.
1155 * Name of the existing desktop.
1158 * Interaction flags.
1161 * Requested type of access.
1164 * Handle to the desktop or zero on failure.
1172 PUNICODE_STRING lpszDesktopName
,
1174 ACCESS_MASK dwDesiredAccess
)
1176 OBJECT_ATTRIBUTES ObjectAttributes
;
1178 PWINSTATION_OBJECT WinStaObject
;
1179 UNICODE_STRING DesktopName
;
1180 UNICODE_STRING SafeDesktopName
;
1184 DECLARE_RETURN(HDESK
);
1186 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1187 UserEnterExclusive();
1190 * Validate the window station handle and compose the fully
1191 * qualified desktop name
1194 WinSta
= UserGetProcessWindowStation();
1195 Status
= IntValidateWindowStationHandle(
1201 if (!NT_SUCCESS(Status
))
1203 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1204 SetLastNtError(Status
);
1208 if(lpszDesktopName
!= NULL
)
1210 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1211 if(!NT_SUCCESS(Status
))
1213 SetLastNtError(Status
);
1219 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1222 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1225 if (lpszDesktopName
)
1226 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1227 ObDereferenceObject(WinStaObject
);
1232 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1237 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1239 /* Initialize ObjectAttributes for the desktop object */
1240 InitializeObjectAttributes(
1247 Status
= ObOpenObjectByName(
1249 ExDesktopObjectType
,
1256 if (!NT_SUCCESS(Status
))
1258 SetLastNtError(Status
);
1259 ExFreePool(DesktopName
.Buffer
);
1263 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1264 ExFreePool(DesktopName
.Buffer
);
1269 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1275 * NtUserOpenInputDesktop
1277 * Opens the input (interactive) desktop.
1281 * Interaction flags.
1284 * Inheritance option.
1287 * Requested type of access.
1290 * Handle to the input desktop or zero on failure.
1297 NtUserOpenInputDesktop(
1300 ACCESS_MASK dwDesiredAccess
)
1305 DECLARE_RETURN(HDESK
);
1307 DPRINT("Enter NtUserOpenInputDesktop\n");
1308 UserEnterExclusive();
1310 DPRINT("About to open input desktop\n");
1312 /* Get a pointer to the desktop object */
1314 Status
= IntValidateDesktopHandle(
1320 if (!NT_SUCCESS(Status
))
1322 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1326 /* Create a new handle to the object */
1328 Status
= ObOpenObjectByPointer(
1333 ExDesktopObjectType
,
1337 ObDereferenceObject(Object
);
1339 if (NT_SUCCESS(Status
))
1341 DPRINT("Successfully opened input desktop\n");
1342 RETURN((HDESK
)Desktop
);
1345 SetLastNtError(Status
);
1349 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1355 * NtUserCloseDesktop
1357 * Closes a desktop handle.
1361 * Handle to the desktop.
1367 * The desktop handle can be created with NtUserCreateDesktop or
1368 * NtUserOpenDesktop. This function will fail if any thread in the calling
1369 * process is using the specified desktop handle or if the handle refers
1370 * to the initial desktop of the calling process.
1377 NtUserCloseDesktop(HDESK hDesktop
)
1381 DECLARE_RETURN(BOOL
);
1383 DPRINT("Enter NtUserCloseDesktop\n");
1384 UserEnterExclusive();
1386 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1388 Status
= IntValidateDesktopHandle(
1394 if (!NT_SUCCESS(Status
))
1396 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1400 ObDereferenceObject(Object
);
1402 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1404 Status
= ZwClose(hDesktop
);
1405 if (!NT_SUCCESS(Status
))
1407 SetLastNtError(Status
);
1414 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1423 * NtUserPaintDesktop
1425 * The NtUserPaintDesktop function fills the clipping region in the
1426 * specified device context with the desktop pattern or wallpaper. The
1427 * function is provided primarily for shell desktops.
1431 * Handle to the device context.
1438 NtUserPaintDesktop(HDC hDC
)
1441 HBRUSH DesktopBrush
, PreviousBrush
;
1443 BOOL doPatBlt
= TRUE
;
1444 PWINDOW_OBJECT WndDesktop
;
1449 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1450 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1451 DECLARE_RETURN(BOOL
);
1453 UserEnterExclusive();
1454 DPRINT("Enter NtUserPaintDesktop\n");
1456 GdiGetClipBox(hDC
, &Rect
);
1458 hWndDesktop
= IntGetDesktopWindow();
1460 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1466 DesktopBrush
= (HBRUSH
)UserGetClassLongPtr(WndDesktop
->Wnd
->pcls
, GCL_HBRBACKGROUND
, FALSE
);
1470 * Paint desktop background
1473 if (WinSta
->hbmWallpaper
!= NULL
)
1475 PWINDOW_OBJECT DeskWin
;
1477 DeskWin
= UserGetWindowObject(hWndDesktop
);
1485 sz
.cx
= DeskWin
->Wnd
->rcWindow
.right
- DeskWin
->Wnd
->rcWindow
.left
;
1486 sz
.cy
= DeskWin
->Wnd
->rcWindow
.bottom
- DeskWin
->Wnd
->rcWindow
.top
;
1488 if (WinSta
->WallpaperMode
== wmStretch
||
1489 WinSta
->WallpaperMode
== wmTile
)
1496 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1497 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1498 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1501 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1502 if(hWallpaperDC
!= NULL
)
1506 /* fill in the area that the bitmap is not going to cover */
1509 /* FIXME - clip out the bitmap
1510 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1511 once we support DSTINVERT */
1512 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1513 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1514 NtGdiSelectBrush(hDC
, PreviousBrush
);
1517 /*Do not fill the background after it is painted no matter the size of the picture */
1520 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1522 if (WinSta
->WallpaperMode
== wmStretch
)
1524 if(Rect
.right
&& Rect
.bottom
)
1525 NtGdiStretchBlt(hDC
,
1533 WinSta
->cxWallpaper
,
1534 WinSta
->cyWallpaper
,
1539 else if (WinSta
->WallpaperMode
== wmTile
)
1541 /* paint the bitmap across the screen then down */
1542 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1544 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1549 WinSta
->cxWallpaper
,
1550 WinSta
->cyWallpaper
,
1565 WinSta
->cxWallpaper
,
1566 WinSta
->cyWallpaper
,
1574 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1575 NtGdiDeleteObjectApp(hWallpaperDC
);
1580 /* Back ground is set to none, clear the screen */
1583 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1584 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1585 NtGdiSelectBrush(hDC
, PreviousBrush
);
1589 * Display system version on the desktop background
1592 if (g_PaintDesktopVersion
)
1594 static WCHAR s_wszVersion
[256] = {0};
1599 len
= wcslen(s_wszVersion
);
1603 len
= GetSystemVersionString(s_wszVersion
);
1608 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1610 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1611 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1614 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1615 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1616 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1618 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1620 IntGdiSetBkMode(hDC
, mode_old
);
1621 IntGdiSetTextAlign(hDC
, align_old
);
1622 IntGdiSetTextColor(hDC
, color_old
);
1629 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1636 * NtUserSwitchDesktop
1638 * Sets the current input (interactive) desktop.
1642 * Handle to desktop.
1652 NtUserSwitchDesktop(HDESK hDesktop
)
1654 PDESKTOP DesktopObject
;
1656 DECLARE_RETURN(BOOL
);
1658 UserEnterExclusive();
1659 DPRINT("Enter NtUserSwitchDesktop\n");
1661 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1663 Status
= IntValidateDesktopHandle(
1669 if (!NT_SUCCESS(Status
))
1671 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1676 * Don't allow applications switch the desktop if it's locked, unless the caller
1677 * is the logon application itself
1679 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1680 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1682 ObDereferenceObject(DesktopObject
);
1683 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1687 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1689 ObDereferenceObject(DesktopObject
);
1690 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1694 /* FIXME: Fail if the process is associated with a secured
1695 desktop such as Winlogon or Screen-Saver */
1696 /* FIXME: Connect to input device */
1698 /* Set the active desktop in the desktop's window station. */
1699 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1701 /* Set the global state. */
1702 InputDesktop
= DesktopObject
;
1703 InputDesktopHandle
= hDesktop
;
1705 ObDereferenceObject(DesktopObject
);
1710 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1716 * NtUserResolveDesktopForWOW
1723 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1730 * NtUserGetThreadDesktop
1737 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1741 PDESKTOP DesktopObject
;
1742 HDESK Ret
, hThreadDesktop
;
1743 OBJECT_HANDLE_INFORMATION HandleInformation
;
1744 DECLARE_RETURN(HDESK
);
1746 UserEnterExclusive();
1747 DPRINT("Enter NtUserGetThreadDesktop\n");
1751 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1755 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1756 if(!NT_SUCCESS(Status
))
1758 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1762 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1764 /* just return the handle, we queried the desktop handle of a thread running
1765 in the same context */
1766 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1767 ObDereferenceObject(Thread
);
1771 /* get the desktop handle and the desktop of the thread */
1772 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1773 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1775 ObDereferenceObject(Thread
);
1776 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1780 /* we could just use DesktopObject instead of looking up the handle, but latter
1781 may be a bit safer (e.g. when the desktop is being destroyed */
1782 /* switch into the context of the thread we're trying to get the desktop from,
1783 so we can use the handle */
1784 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1785 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1787 ExDesktopObjectType
,
1789 (PVOID
*)&DesktopObject
,
1790 &HandleInformation
);
1793 /* the handle couldn't be found, there's nothing to get... */
1794 if(!NT_SUCCESS(Status
))
1796 ObDereferenceObject(Thread
);
1800 /* lookup our handle table if we can find a handle to the desktop object,
1801 if not, create one */
1802 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1804 /* all done, we got a valid handle to the desktop */
1805 ObDereferenceObject(DesktopObject
);
1806 ObDereferenceObject(Thread
);
1810 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1816 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1819 PPROCESSINFO CurrentWin32Process
;
1820 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1821 NTSTATUS Status
= STATUS_SUCCESS
;
1825 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1826 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1828 /* unmap if we're the last thread using the desktop */
1829 HeapMapping
= *PrevLink
;
1830 while (HeapMapping
!= NULL
)
1832 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1834 if (--HeapMapping
->Count
== 0)
1836 *PrevLink
= HeapMapping
->Next
;
1838 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1839 HeapMapping
->UserMapping
);
1841 ObDereferenceObject(DesktopObject
);
1843 UserHeapFree(HeapMapping
);
1848 PrevLink
= &HeapMapping
->Next
;
1849 HeapMapping
= HeapMapping
->Next
;
1852 ti
= GetW32ThreadInfo();
1855 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1857 GetWin32ClientInfo()->ulClientDelta
= 0;
1863 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1866 PPROCESSINFO CurrentWin32Process
;
1867 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1868 PVOID UserBase
= NULL
;
1869 SIZE_T ViewSize
= 0;
1870 LARGE_INTEGER Offset
;
1873 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1874 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1876 /* find out if another thread already mapped the desktop heap */
1877 HeapMapping
= *PrevLink
;
1878 while (HeapMapping
!= NULL
)
1880 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1882 HeapMapping
->Count
++;
1883 return STATUS_SUCCESS
;
1886 PrevLink
= &HeapMapping
->Next
;
1887 HeapMapping
= HeapMapping
->Next
;
1890 /* we're the first, map the heap */
1891 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1892 Offset
.QuadPart
= 0;
1893 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1894 PsGetCurrentProcess(),
1902 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1903 if (!NT_SUCCESS(Status
))
1905 DPRINT1("Failed to map desktop\n");
1909 /* add the mapping */
1910 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1911 if (HeapMapping
== NULL
)
1913 MmUnmapViewOfSection(PsGetCurrentProcess(),
1915 DPRINT1("UserHeapAlloc() failed!\n");
1916 return STATUS_NO_MEMORY
;
1919 HeapMapping
->Next
= NULL
;
1920 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1921 HeapMapping
->UserMapping
= UserBase
;
1922 HeapMapping
->Limit
= ViewSize
;
1923 HeapMapping
->Count
= 1;
1924 *PrevLink
= HeapMapping
;
1926 ObReferenceObject(DesktopObject
);
1928 /* create a W32THREADINFO structure if not already done, or update it */
1929 ti
= GetW32ThreadInfo();
1930 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1933 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1935 GetWin32ClientInfo()->pDeskInfo
=
1936 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1937 GetWin32ClientInfo()->ulClientDelta
);
1941 return STATUS_SUCCESS
;
1945 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1946 IN BOOL FreeOnFailure
)
1948 PDESKTOP OldDesktop
;
1949 PTHREADINFO W32Thread
;
1953 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1954 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1955 W32Thread
= PsGetCurrentThreadWin32Thread();
1957 if (W32Thread
->rpdesk
!= DesktopObject
)
1959 OldDesktop
= W32Thread
->rpdesk
;
1961 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1963 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1964 SetLastWin32Error(ERROR_BUSY
);
1968 W32Thread
->rpdesk
= DesktopObject
;
1970 if (MapHeap
&& DesktopObject
!= NULL
)
1972 Status
= IntMapDesktopView(DesktopObject
);
1973 if (!NT_SUCCESS(Status
))
1975 SetLastNtError(Status
);
1980 /* Hack for system threads */
1983 PCLIENTINFO pci
= GetWin32ClientInfo();
1984 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1987 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1991 if (OldDesktop
!= NULL
&&
1992 !IntCheckProcessDesktopClasses(OldDesktop
,
1995 DPRINT1("Failed to move process classes to shared heap!\n");
1997 /* failed to move desktop classes to the shared heap,
1998 unmap the view and return the error */
1999 if (MapHeap
&& DesktopObject
!= NULL
)
2000 IntUnmapDesktopView(DesktopObject
);
2005 /* Remove the thread from the old desktop's list */
2006 RemoveEntryList(&W32Thread
->PtiLink
);
2008 if (DesktopObject
!= NULL
)
2010 ObReferenceObject(DesktopObject
);
2011 /* Insert into new desktop's list */
2012 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
2015 if (OldDesktop
!= NULL
)
2019 IntUnmapDesktopView(OldDesktop
);
2022 ObDereferenceObject(OldDesktop
);
2030 * NtUserSetThreadDesktop
2037 NtUserSetThreadDesktop(HDESK hDesktop
)
2039 PDESKTOP DesktopObject
;
2041 DECLARE_RETURN(BOOL
);
2043 UserEnterExclusive();
2044 DPRINT("Enter NtUserSetThreadDesktop\n");
2046 /* Validate the new desktop. */
2047 Status
= IntValidateDesktopHandle(
2053 if (!NT_SUCCESS(Status
))
2055 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2059 /* FIXME: Should check here to see if the thread has any windows. */
2061 if (!IntSetThreadDesktop(DesktopObject
,
2070 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);