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 IntGetActiveDesktop(VOID
)
429 * returns or creates a handle to the desktop object
432 IntGetDesktopObjectHandle(PDESKTOP DesktopObject
)
437 ASSERT(DesktopObject
);
439 if (!ObFindHandleForObject(PsGetCurrentProcess(),
445 Status
= ObOpenObjectByPointer(DesktopObject
,
452 if(!NT_SUCCESS(Status
))
454 /* unable to create a handle */
455 DPRINT1("Unable to create a desktop handle\n");
461 DPRINT1("Got handle: %lx\n", Ret
);
467 PUSER_MESSAGE_QUEUE FASTCALL
468 IntGetFocusMessageQueue(VOID
)
470 PDESKTOP pdo
= IntGetActiveDesktop();
473 DPRINT("No active desktop\n");
476 return (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
480 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue
)
482 PUSER_MESSAGE_QUEUE Old
;
483 PDESKTOP pdo
= IntGetActiveDesktop();
486 DPRINT("No active desktop\n");
491 if(NewQueue
->Desktop
!= NULL
)
493 DPRINT("Message Queue already attached to another desktop!\n");
496 IntReferenceMessageQueue(NewQueue
);
497 (void)InterlockedExchangePointer((PVOID
*)&NewQueue
->Desktop
, pdo
);
499 Old
= (PUSER_MESSAGE_QUEUE
)InterlockedExchangePointer((PVOID
*)&pdo
->ActiveMessageQueue
, NewQueue
);
502 (void)InterlockedExchangePointer((PVOID
*)&Old
->Desktop
, 0);
503 IntDereferenceMessageQueue(Old
);
507 HWND FASTCALL
IntGetDesktopWindow(VOID
)
509 PDESKTOP pdo
= IntGetActiveDesktop();
512 DPRINT("No active desktop\n");
515 return pdo
->DesktopWindow
;
518 PWINDOW_OBJECT FASTCALL
UserGetDesktopWindow(VOID
)
520 PDESKTOP pdo
= IntGetActiveDesktop();
524 DPRINT("No active desktop\n");
528 return UserGetWindowObject(pdo
->DesktopWindow
);
531 HWND FASTCALL
IntGetMessageWindow(VOID
)
533 PDESKTOP pdo
= IntGetActiveDesktop();
537 DPRINT("No active desktop\n");
540 return pdo
->spwndMessage
->head
.h
;
543 HWND FASTCALL
IntGetCurrentThreadDesktopWindow(VOID
)
545 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
546 PDESKTOP pdo
= pti
->rpdesk
;
549 DPRINT1("Thread doesn't have a desktop\n");
552 return pdo
->DesktopWindow
;
555 BOOL FASTCALL
IntDesktopUpdatePerUserSettings(BOOL bEnable
)
559 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
562 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
564 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
565 QueryTable
[0].Name
= L
"PaintDesktopVersion";
566 QueryTable
[0].EntryContext
= &g_PaintDesktopVersion
;
568 /* Query the "PaintDesktopVersion" flag in the "Control Panel\Desktop" key */
569 Status
= RtlQueryRegistryValues(RTL_REGISTRY_USER
,
570 L
"Control Panel\\Desktop",
571 QueryTable
, NULL
, NULL
);
572 if (!NT_SUCCESS(Status
))
574 DPRINT1("RtlQueryRegistryValues failed for PaintDesktopVersion (%x)\n",
576 g_PaintDesktopVersion
= FALSE
;
580 DPRINT("PaintDesktopVersion = %d\n", g_PaintDesktopVersion
);
586 g_PaintDesktopVersion
= FALSE
;
591 /* PUBLIC FUNCTIONS ***********************************************************/
594 UserGetDesktopDC(ULONG DcType
, BOOL EmptyDC
, BOOL ValidatehWnd
)
596 PWINDOW_OBJECT DesktopObject
= 0;
599 if (DcType
== DC_TYPE_DIRECT
)
601 DesktopObject
= UserGetDesktopWindow();
602 DesktopHDC
= (HDC
)UserGetWindowDC(DesktopObject
);
607 hDev
= (HDEV
)pPrimarySurface
;
608 DesktopHDC
= IntGdiCreateDisplayDC(hDev
, DcType
, EmptyDC
);
617 PWINDOW_OBJECT Window
= NULL
;
619 UserEnterExclusive();
621 Window
= UserGetDesktopWindow();
623 IntInvalidateWindows( Window
,
634 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
636 CSR_API_MESSAGE Request
;
638 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
639 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
640 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
641 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
643 return co_CsrNotify(&Request
);
647 IntHideDesktop(PDESKTOP Desktop
)
650 CSRSS_API_REQUEST Request
;
651 CSRSS_API_REPLY Reply
;
653 Request
.Type
= CSRSS_HIDE_DESKTOP
;
654 Request
.Data
.HideDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
656 return NotifyCsrss(&Request
, &Reply
);
659 PWINDOW_OBJECT DesktopWindow
;
662 DesktopWindow
= IntGetWindowObject(Desktop
->DesktopWindow
);
665 return ERROR_INVALID_WINDOW_HANDLE
;
667 DesktopWnd
= DesktopWindow
->Wnd
;
668 DesktopWnd
->style
&= ~WS_VISIBLE
;
670 return STATUS_SUCCESS
;
679 UserBuildShellHookHwndList(PDESKTOP Desktop
)
682 PSHELL_HOOK_WINDOW Current
;
685 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
686 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
689 if (!entries
) return NULL
;
691 list
= ExAllocatePool(PagedPool
, sizeof(HWND
) * (entries
+ 1)); /* alloc one extra for nullterm */
696 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
697 *cursor
++ = Current
->hWnd
;
699 *cursor
= NULL
; /* nullterm list */
706 * Send the Message to the windows registered for ShellHook
707 * notifications. The lParam contents depend on the Message. See
708 * MSDN for more details (RegisterShellHookWindow)
710 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
712 PDESKTOP Desktop
= IntGetActiveDesktop();
715 static UINT MsgType
= 0;
720 /* Too bad, this doesn't work.*/
723 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
724 MsgType
= UserRegisterWindowMessage(&Str
);
727 MsgType
= IntAddAtom(L
"SHELLHOOK");
729 DPRINT("MsgType = %x\n", MsgType
);
731 DPRINT1("LastError: %x\n", GetLastNtError());
736 DPRINT("IntShellHookNotify: No desktop!\n");
740 HwndList
= UserBuildShellHookHwndList(Desktop
);
743 HWND
* cursor
= HwndList
;
745 for (; *cursor
; cursor
++)
747 DPRINT("Sending notify\n");
748 co_IntPostOrSendMessage(*cursor
,
754 ExFreePool(HwndList
);
760 * Add the window to the ShellHookWindows list. The windows
761 * on that list get notifications that are important to shell
764 * TODO: Validate the window? I'm not sure if sending these messages to
765 * an unsuspecting application that is not your own is a nice thing to do.
767 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
769 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
770 PDESKTOP Desktop
= pti
->rpdesk
;
771 PSHELL_HOOK_WINDOW Entry
;
773 DPRINT("IntRegisterShellHookWindow\n");
775 /* First deregister the window, so we can be sure it's never twice in the
778 IntDeRegisterShellHookWindow(hWnd
);
780 Entry
= ExAllocatePoolWithTag(PagedPool
,
781 sizeof(SHELL_HOOK_WINDOW
),
789 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
795 * Remove the window from the ShellHookWindows list. The windows
796 * on that list get notifications that are important to shell
799 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
801 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
802 PDESKTOP Desktop
= pti
->rpdesk
;
803 PSHELL_HOOK_WINDOW Current
;
805 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
807 if (Current
->hWnd
== hWnd
)
809 RemoveEntryList(&Current
->ListEntry
);
819 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
821 if (Desktop
->hsectionDesktop
!= NULL
)
823 ObDereferenceObject(Desktop
->hsectionDesktop
);
824 Desktop
->hsectionDesktop
= NULL
;
827 /* SYSCALLS *******************************************************************/
830 * NtUserCreateDesktop
832 * Creates a new desktop.
839 * Name of the device.
848 * Requested type of access.
852 * If the function succeeds, the return value is a handle to the newly
853 * created desktop. If the specified desktop already exists, the function
854 * succeeds and returns a handle to the existing desktop. When you are
855 * finished using the handle, call the CloseDesktop function to close it.
856 * If the function fails, the return value is NULL.
864 POBJECT_ATTRIBUTES poa
,
865 PUNICODE_STRING lpszDesktopDevice
,
868 ACCESS_MASK dwDesiredAccess
)
870 OBJECT_ATTRIBUTES ObjectAttributes
;
871 PTHREADINFO W32Thread
;
872 PWINSTATION_OBJECT WinStaObject
;
873 PDESKTOP DesktopObject
;
874 UNICODE_STRING DesktopName
;
875 NTSTATUS Status
= STATUS_SUCCESS
;
877 CSR_API_MESSAGE Request
;
878 PVOID DesktopHeapSystemBase
= NULL
;
879 SIZE_T DesktopInfoSize
;
880 UNICODE_STRING SafeDesktopName
;
882 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
883 HWINSTA hWindowStation
= NULL
;
884 PUNICODE_STRING lpszDesktopName
= NULL
;
885 UNICODE_STRING ClassName
, MenuName
;
886 LARGE_STRING WindowName
;
889 DECLARE_RETURN(HDESK
);
891 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
892 UserEnterExclusive();
897 sizeof(OBJECT_ATTRIBUTES
),
900 hWindowStation
= poa
->RootDirectory
;
901 lpszDesktopName
= poa
->ObjectName
;
903 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
905 Status
=_SEH2_GetExceptionCode();
909 if (! NT_SUCCESS(Status
))
911 DPRINT1("Failed reading Object Attributes from user space.\n");
912 SetLastNtError(Status
);
916 Status
= IntValidateWindowStationHandle(
919 0, /* FIXME - WINSTA_CREATEDESKTOP */
922 if (! NT_SUCCESS(Status
))
924 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
925 hWindowStation
, lpszDesktopName
);
926 SetLastNtError(Status
);
929 if(lpszDesktopName
!= NULL
)
931 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
932 if(!NT_SUCCESS(Status
))
934 SetLastNtError(Status
);
940 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
943 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
946 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
947 ObDereferenceObject(WinStaObject
);
949 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
953 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
954 ObDereferenceObject(WinStaObject
);
957 * Try to open already existing desktop
960 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
962 /* Initialize ObjectAttributes for the desktop object */
963 InitializeObjectAttributes(
970 Status
= ObOpenObjectByName(
976 (PVOID
)&DummyContext
,
978 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
979 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
981 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
985 /* Reference the desktop */
986 Status
= ObReferenceObjectByHandle(Desktop
,
990 (PVOID
)&DesktopObject
,
992 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
994 DesktopObject
->hsectionDesktop
= NULL
;
995 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
996 &DesktopHeapSystemBase
,
998 if (DesktopObject
->pheapDesktop
== NULL
)
1000 ObDereferenceObject(DesktopObject
);
1001 DPRINT1("Failed to create desktop heap!\n");
1005 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1006 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1008 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1012 if (DesktopObject
->pDeskInfo
== NULL
)
1014 ObDereferenceObject(DesktopObject
);
1015 DPRINT1("Failed to create the DESKTOP structure!\n");
1019 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1022 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1023 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1024 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1025 lpszDesktopName
->Buffer
,
1026 lpszDesktopName
->Length
);
1028 /* Initialize some local (to win32k) desktop state. */
1029 InitializeListHead(&DesktopObject
->PtiList
);
1030 DesktopObject
->ActiveMessageQueue
= NULL
;
1031 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1033 if (! NT_SUCCESS(Status
))
1035 DPRINT1("Failed to create desktop handle\n");
1036 SetLastNtError(Status
);
1041 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1043 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1044 * to function at the beginning of the project by ramroding the GUI into
1045 * operation and making the desktop window work from user space.
1048 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1049 Status
= CsrInsertObject(Desktop
,
1051 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1052 if (! NT_SUCCESS(Status
))
1054 DPRINT1("Failed to create desktop handle for CSRSS\n");
1056 SetLastNtError(Status
);
1060 Status
= co_CsrNotify(&Request
);
1061 if (! NT_SUCCESS(Status
))
1063 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1064 DPRINT1("Failed to notify CSRSS about new desktop\n");
1066 SetLastNtError(Status
);
1070 W32Thread
= PsGetCurrentThreadWin32Thread();
1072 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1075 Based on wine/server/window.c in get_desktop_window.
1078 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1079 ClassName
.Length
= 0;
1080 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1081 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1083 RtlZeroMemory(&Cs
, sizeof(Cs
));
1084 Cs
.cx
= Cs
.cy
= 100;
1085 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1086 Cs
.hInstance
= hModClient
;
1087 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1088 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1090 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
);
1093 DPRINT1("Failed to create Message window handle\n");
1097 DesktopObject
->spwndMessage
= pWnd
;
1103 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1111 * Opens an existing desktop.
1115 * Name of the existing desktop.
1118 * Interaction flags.
1121 * Requested type of access.
1124 * Handle to the desktop or zero on failure.
1132 PUNICODE_STRING lpszDesktopName
,
1134 ACCESS_MASK dwDesiredAccess
)
1136 OBJECT_ATTRIBUTES ObjectAttributes
;
1138 PWINSTATION_OBJECT WinStaObject
;
1139 UNICODE_STRING DesktopName
;
1140 UNICODE_STRING SafeDesktopName
;
1144 DECLARE_RETURN(HDESK
);
1146 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1147 UserEnterExclusive();
1150 * Validate the window station handle and compose the fully
1151 * qualified desktop name
1154 WinSta
= UserGetProcessWindowStation();
1155 Status
= IntValidateWindowStationHandle(
1161 if (!NT_SUCCESS(Status
))
1163 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1164 SetLastNtError(Status
);
1168 if(lpszDesktopName
!= NULL
)
1170 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1171 if(!NT_SUCCESS(Status
))
1173 SetLastNtError(Status
);
1179 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1182 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1185 if (lpszDesktopName
)
1186 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1187 ObDereferenceObject(WinStaObject
);
1192 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1197 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1199 /* Initialize ObjectAttributes for the desktop object */
1200 InitializeObjectAttributes(
1207 Status
= ObOpenObjectByName(
1209 ExDesktopObjectType
,
1216 if (!NT_SUCCESS(Status
))
1218 SetLastNtError(Status
);
1219 ExFreePool(DesktopName
.Buffer
);
1223 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1224 ExFreePool(DesktopName
.Buffer
);
1229 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1235 * NtUserOpenInputDesktop
1237 * Opens the input (interactive) desktop.
1241 * Interaction flags.
1244 * Inheritance option.
1247 * Requested type of access.
1250 * Handle to the input desktop or zero on failure.
1257 NtUserOpenInputDesktop(
1260 ACCESS_MASK dwDesiredAccess
)
1265 DECLARE_RETURN(HDESK
);
1267 DPRINT("Enter NtUserOpenInputDesktop\n");
1268 UserEnterExclusive();
1270 DPRINT("About to open input desktop\n");
1272 /* Get a pointer to the desktop object */
1274 Status
= IntValidateDesktopHandle(
1280 if (!NT_SUCCESS(Status
))
1282 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1286 /* Create a new handle to the object */
1288 Status
= ObOpenObjectByPointer(
1293 ExDesktopObjectType
,
1297 ObDereferenceObject(Object
);
1299 if (NT_SUCCESS(Status
))
1301 DPRINT("Successfully opened input desktop\n");
1302 RETURN((HDESK
)Desktop
);
1305 SetLastNtError(Status
);
1309 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1315 * NtUserCloseDesktop
1317 * Closes a desktop handle.
1321 * Handle to the desktop.
1327 * The desktop handle can be created with NtUserCreateDesktop or
1328 * NtUserOpenDesktop. This function will fail if any thread in the calling
1329 * process is using the specified desktop handle or if the handle refers
1330 * to the initial desktop of the calling process.
1337 NtUserCloseDesktop(HDESK hDesktop
)
1341 DECLARE_RETURN(BOOL
);
1343 DPRINT("Enter NtUserCloseDesktop\n");
1344 UserEnterExclusive();
1346 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1348 Status
= IntValidateDesktopHandle(
1354 if (!NT_SUCCESS(Status
))
1356 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1360 ObDereferenceObject(Object
);
1362 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1364 Status
= ZwClose(hDesktop
);
1365 if (!NT_SUCCESS(Status
))
1367 SetLastNtError(Status
);
1374 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1383 * NtUserPaintDesktop
1385 * The NtUserPaintDesktop function fills the clipping region in the
1386 * specified device context with the desktop pattern or wallpaper. The
1387 * function is provided primarily for shell desktops.
1391 * Handle to the device context.
1398 NtUserPaintDesktop(HDC hDC
)
1401 HBRUSH DesktopBrush
, PreviousBrush
;
1403 BOOL doPatBlt
= TRUE
;
1404 PWINDOW_OBJECT WndDesktop
;
1409 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1410 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1411 DECLARE_RETURN(BOOL
);
1413 UserEnterExclusive();
1414 DPRINT("Enter NtUserPaintDesktop\n");
1416 GdiGetClipBox(hDC
, &Rect
);
1418 hWndDesktop
= IntGetDesktopWindow();
1420 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1426 DesktopBrush
= (HBRUSH
)WndDesktop
->Wnd
->pcls
->hbrBackground
;
1430 * Paint desktop background
1433 if (WinSta
->hbmWallpaper
!= NULL
)
1435 PWINDOW_OBJECT DeskWin
;
1437 DeskWin
= UserGetWindowObject(hWndDesktop
);
1445 sz
.cx
= DeskWin
->Wnd
->rcWindow
.right
- DeskWin
->Wnd
->rcWindow
.left
;
1446 sz
.cy
= DeskWin
->Wnd
->rcWindow
.bottom
- DeskWin
->Wnd
->rcWindow
.top
;
1448 if (WinSta
->WallpaperMode
== wmStretch
||
1449 WinSta
->WallpaperMode
== wmTile
)
1456 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1457 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1458 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1461 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1462 if(hWallpaperDC
!= NULL
)
1466 /* fill in the area that the bitmap is not going to cover */
1469 /* FIXME - clip out the bitmap
1470 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1471 once we support DSTINVERT */
1472 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1473 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1474 NtGdiSelectBrush(hDC
, PreviousBrush
);
1477 /*Do not fill the background after it is painted no matter the size of the picture */
1480 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1482 if (WinSta
->WallpaperMode
== wmStretch
)
1484 if(Rect
.right
&& Rect
.bottom
)
1485 NtGdiStretchBlt(hDC
,
1493 WinSta
->cxWallpaper
,
1494 WinSta
->cyWallpaper
,
1499 else if (WinSta
->WallpaperMode
== wmTile
)
1501 /* paint the bitmap across the screen then down */
1502 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1504 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1509 WinSta
->cxWallpaper
,
1510 WinSta
->cyWallpaper
,
1525 WinSta
->cxWallpaper
,
1526 WinSta
->cyWallpaper
,
1534 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1535 NtGdiDeleteObjectApp(hWallpaperDC
);
1540 /* Back ground is set to none, clear the screen */
1543 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1544 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1545 NtGdiSelectBrush(hDC
, PreviousBrush
);
1549 * Display system version on the desktop background
1552 if (g_PaintDesktopVersion
)
1554 static WCHAR s_wszVersion
[256] = {0};
1559 len
= wcslen(s_wszVersion
);
1563 len
= GetSystemVersionString(s_wszVersion
);
1568 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1570 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1571 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1574 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1575 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1576 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1578 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1580 IntGdiSetBkMode(hDC
, mode_old
);
1581 IntGdiSetTextAlign(hDC
, align_old
);
1582 IntGdiSetTextColor(hDC
, color_old
);
1589 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1596 * NtUserSwitchDesktop
1598 * Sets the current input (interactive) desktop.
1602 * Handle to desktop.
1612 NtUserSwitchDesktop(HDESK hDesktop
)
1614 PDESKTOP DesktopObject
;
1616 DECLARE_RETURN(BOOL
);
1618 UserEnterExclusive();
1619 DPRINT("Enter NtUserSwitchDesktop\n");
1621 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1623 Status
= IntValidateDesktopHandle(
1629 if (!NT_SUCCESS(Status
))
1631 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1636 * Don't allow applications switch the desktop if it's locked, unless the caller
1637 * is the logon application itself
1639 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1640 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1642 ObDereferenceObject(DesktopObject
);
1643 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1647 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1649 ObDereferenceObject(DesktopObject
);
1650 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1654 /* FIXME: Fail if the process is associated with a secured
1655 desktop such as Winlogon or Screen-Saver */
1656 /* FIXME: Connect to input device */
1658 /* Set the active desktop in the desktop's window station. */
1659 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1661 /* Set the global state. */
1662 InputDesktop
= DesktopObject
;
1663 InputDesktopHandle
= hDesktop
;
1665 ObDereferenceObject(DesktopObject
);
1670 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1676 * NtUserResolveDesktopForWOW
1683 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1690 * NtUserGetThreadDesktop
1697 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1701 PDESKTOP DesktopObject
;
1702 HDESK Ret
, hThreadDesktop
;
1703 OBJECT_HANDLE_INFORMATION HandleInformation
;
1704 DECLARE_RETURN(HDESK
);
1706 UserEnterExclusive();
1707 DPRINT("Enter NtUserGetThreadDesktop\n");
1711 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1715 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1716 if(!NT_SUCCESS(Status
))
1718 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1722 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1724 /* just return the handle, we queried the desktop handle of a thread running
1725 in the same context */
1726 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1727 ObDereferenceObject(Thread
);
1731 /* get the desktop handle and the desktop of the thread */
1732 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1733 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1735 ObDereferenceObject(Thread
);
1736 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1740 /* we could just use DesktopObject instead of looking up the handle, but latter
1741 may be a bit safer (e.g. when the desktop is being destroyed */
1742 /* switch into the context of the thread we're trying to get the desktop from,
1743 so we can use the handle */
1744 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1745 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1747 ExDesktopObjectType
,
1749 (PVOID
*)&DesktopObject
,
1750 &HandleInformation
);
1753 /* the handle couldn't be found, there's nothing to get... */
1754 if(!NT_SUCCESS(Status
))
1756 ObDereferenceObject(Thread
);
1760 /* lookup our handle table if we can find a handle to the desktop object,
1761 if not, create one */
1762 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1764 /* all done, we got a valid handle to the desktop */
1765 ObDereferenceObject(DesktopObject
);
1766 ObDereferenceObject(Thread
);
1770 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1776 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1779 PPROCESSINFO CurrentWin32Process
;
1780 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1781 NTSTATUS Status
= STATUS_SUCCESS
;
1785 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1786 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1788 /* unmap if we're the last thread using the desktop */
1789 HeapMapping
= *PrevLink
;
1790 while (HeapMapping
!= NULL
)
1792 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1794 if (--HeapMapping
->Count
== 0)
1796 *PrevLink
= HeapMapping
->Next
;
1798 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1799 HeapMapping
->UserMapping
);
1801 ObDereferenceObject(DesktopObject
);
1803 UserHeapFree(HeapMapping
);
1808 PrevLink
= &HeapMapping
->Next
;
1809 HeapMapping
= HeapMapping
->Next
;
1812 ti
= GetW32ThreadInfo();
1815 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1817 GetWin32ClientInfo()->ulClientDelta
= 0;
1823 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1826 PPROCESSINFO CurrentWin32Process
;
1827 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1828 PVOID UserBase
= NULL
;
1829 SIZE_T ViewSize
= 0;
1830 LARGE_INTEGER Offset
;
1833 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1834 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1836 /* find out if another thread already mapped the desktop heap */
1837 HeapMapping
= *PrevLink
;
1838 while (HeapMapping
!= NULL
)
1840 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1842 HeapMapping
->Count
++;
1843 return STATUS_SUCCESS
;
1846 PrevLink
= &HeapMapping
->Next
;
1847 HeapMapping
= HeapMapping
->Next
;
1850 /* we're the first, map the heap */
1851 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1852 Offset
.QuadPart
= 0;
1853 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1854 PsGetCurrentProcess(),
1862 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1863 if (!NT_SUCCESS(Status
))
1865 DPRINT1("Failed to map desktop\n");
1869 /* add the mapping */
1870 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1871 if (HeapMapping
== NULL
)
1873 MmUnmapViewOfSection(PsGetCurrentProcess(),
1875 DPRINT1("UserHeapAlloc() failed!\n");
1876 return STATUS_NO_MEMORY
;
1879 HeapMapping
->Next
= NULL
;
1880 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1881 HeapMapping
->UserMapping
= UserBase
;
1882 HeapMapping
->Limit
= ViewSize
;
1883 HeapMapping
->Count
= 1;
1884 *PrevLink
= HeapMapping
;
1886 ObReferenceObject(DesktopObject
);
1888 /* create a W32THREADINFO structure if not already done, or update it */
1889 ti
= GetW32ThreadInfo();
1890 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1893 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1895 GetWin32ClientInfo()->pDeskInfo
=
1896 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1897 GetWin32ClientInfo()->ulClientDelta
);
1901 return STATUS_SUCCESS
;
1905 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1906 IN BOOL FreeOnFailure
)
1908 PDESKTOP OldDesktop
;
1909 PTHREADINFO W32Thread
;
1913 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1914 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1915 W32Thread
= PsGetCurrentThreadWin32Thread();
1917 if (W32Thread
->rpdesk
!= DesktopObject
)
1919 OldDesktop
= W32Thread
->rpdesk
;
1921 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1923 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1924 SetLastWin32Error(ERROR_BUSY
);
1928 W32Thread
->rpdesk
= DesktopObject
;
1930 if (MapHeap
&& DesktopObject
!= NULL
)
1932 Status
= IntMapDesktopView(DesktopObject
);
1933 if (!NT_SUCCESS(Status
))
1935 SetLastNtError(Status
);
1940 /* Hack for system threads */
1943 PCLIENTINFO pci
= GetWin32ClientInfo();
1944 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1947 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1951 if (OldDesktop
!= NULL
&&
1952 !IntCheckProcessDesktopClasses(OldDesktop
,
1955 DPRINT1("Failed to move process classes to shared heap!\n");
1957 /* failed to move desktop classes to the shared heap,
1958 unmap the view and return the error */
1959 if (MapHeap
&& DesktopObject
!= NULL
)
1960 IntUnmapDesktopView(DesktopObject
);
1965 /* Remove the thread from the old desktop's list */
1966 RemoveEntryList(&W32Thread
->PtiLink
);
1968 if (DesktopObject
!= NULL
)
1970 ObReferenceObject(DesktopObject
);
1971 /* Insert into new desktop's list */
1972 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
1975 if (OldDesktop
!= NULL
)
1979 IntUnmapDesktopView(OldDesktop
);
1982 ObDereferenceObject(OldDesktop
);
1990 * NtUserSetThreadDesktop
1997 NtUserSetThreadDesktop(HDESK hDesktop
)
1999 PDESKTOP DesktopObject
;
2001 DECLARE_RETURN(BOOL
);
2003 UserEnterExclusive();
2004 DPRINT("Enter NtUserSetThreadDesktop\n");
2006 /* Validate the new desktop. */
2007 Status
= IntValidateDesktopHandle(
2013 if (!NT_SUCCESS(Status
))
2015 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2019 /* FIXME: Should check here to see if the thread has any windows. */
2021 if (!IntSetThreadDesktop(DesktopObject
,
2030 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);