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 Window
= UserGetDesktopWindow();
621 IntInvalidateWindows( Window
,
631 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
633 CSR_API_MESSAGE Request
;
635 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
636 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
637 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
638 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
640 return co_CsrNotify(&Request
);
644 IntHideDesktop(PDESKTOP Desktop
)
647 CSRSS_API_REQUEST Request
;
648 CSRSS_API_REPLY Reply
;
650 Request
.Type
= CSRSS_HIDE_DESKTOP
;
651 Request
.Data
.HideDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
653 return NotifyCsrss(&Request
, &Reply
);
656 PWINDOW_OBJECT DesktopWindow
;
659 DesktopWindow
= IntGetWindowObject(Desktop
->DesktopWindow
);
662 return ERROR_INVALID_WINDOW_HANDLE
;
664 DesktopWnd
= DesktopWindow
->Wnd
;
665 DesktopWnd
->style
&= ~WS_VISIBLE
;
667 return STATUS_SUCCESS
;
676 UserBuildShellHookHwndList(PDESKTOP Desktop
)
679 PSHELL_HOOK_WINDOW Current
;
682 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
683 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
686 if (!entries
) return NULL
;
688 list
= ExAllocatePoolWithTag(PagedPool
, sizeof(HWND
) * (entries
+ 1), USERTAG_WINDOWLIST
); /* alloc one extra for nullterm */
693 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
694 *cursor
++ = Current
->hWnd
;
696 *cursor
= NULL
; /* nullterm list */
703 * Send the Message to the windows registered for ShellHook
704 * notifications. The lParam contents depend on the Message. See
705 * MSDN for more details (RegisterShellHookWindow)
707 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
709 PDESKTOP Desktop
= IntGetActiveDesktop();
712 static UINT MsgType
= 0;
717 /* Too bad, this doesn't work.*/
720 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
721 MsgType
= UserRegisterWindowMessage(&Str
);
724 MsgType
= IntAddAtom(L
"SHELLHOOK");
726 DPRINT("MsgType = %x\n", MsgType
);
728 DPRINT1("LastError: %x\n", GetLastNtError());
733 DPRINT("IntShellHookNotify: No desktop!\n");
737 HwndList
= UserBuildShellHookHwndList(Desktop
);
740 HWND
* cursor
= HwndList
;
742 for (; *cursor
; cursor
++)
744 DPRINT("Sending notify\n");
745 co_IntPostOrSendMessage(*cursor
,
751 ExFreePool(HwndList
);
757 * Add the window to the ShellHookWindows list. The windows
758 * on that list get notifications that are important to shell
761 * TODO: Validate the window? I'm not sure if sending these messages to
762 * an unsuspecting application that is not your own is a nice thing to do.
764 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
766 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
767 PDESKTOP Desktop
= pti
->rpdesk
;
768 PSHELL_HOOK_WINDOW Entry
;
770 DPRINT("IntRegisterShellHookWindow\n");
772 /* First deregister the window, so we can be sure it's never twice in the
775 IntDeRegisterShellHookWindow(hWnd
);
777 Entry
= ExAllocatePoolWithTag(PagedPool
,
778 sizeof(SHELL_HOOK_WINDOW
),
786 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
792 * Remove the window from the ShellHookWindows list. The windows
793 * on that list get notifications that are important to shell
796 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
798 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
799 PDESKTOP Desktop
= pti
->rpdesk
;
800 PSHELL_HOOK_WINDOW Current
;
802 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
804 if (Current
->hWnd
== hWnd
)
806 RemoveEntryList(&Current
->ListEntry
);
816 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
818 if (Desktop
->hsectionDesktop
!= NULL
)
820 ObDereferenceObject(Desktop
->hsectionDesktop
);
821 Desktop
->hsectionDesktop
= NULL
;
824 /* SYSCALLS *******************************************************************/
827 * NtUserCreateDesktop
829 * Creates a new desktop.
836 * Name of the device.
845 * Requested type of access.
849 * If the function succeeds, the return value is a handle to the newly
850 * created desktop. If the specified desktop already exists, the function
851 * succeeds and returns a handle to the existing desktop. When you are
852 * finished using the handle, call the CloseDesktop function to close it.
853 * If the function fails, the return value is NULL.
861 POBJECT_ATTRIBUTES poa
,
862 PUNICODE_STRING lpszDesktopDevice
,
865 ACCESS_MASK dwDesiredAccess
)
867 OBJECT_ATTRIBUTES ObjectAttributes
;
868 PTHREADINFO W32Thread
;
869 PWINSTATION_OBJECT WinStaObject
;
870 PDESKTOP DesktopObject
;
871 UNICODE_STRING DesktopName
;
872 NTSTATUS Status
= STATUS_SUCCESS
;
874 CSR_API_MESSAGE Request
;
875 PVOID DesktopHeapSystemBase
= NULL
;
876 SIZE_T DesktopInfoSize
;
877 UNICODE_STRING SafeDesktopName
;
879 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
880 HWINSTA hWindowStation
= NULL
;
881 PUNICODE_STRING lpszDesktopName
= NULL
;
882 UNICODE_STRING ClassName
, MenuName
;
883 LARGE_STRING WindowName
;
886 DECLARE_RETURN(HDESK
);
888 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
889 UserEnterExclusive();
894 sizeof(OBJECT_ATTRIBUTES
),
897 hWindowStation
= poa
->RootDirectory
;
898 lpszDesktopName
= poa
->ObjectName
;
900 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
902 Status
=_SEH2_GetExceptionCode();
906 if (! NT_SUCCESS(Status
))
908 DPRINT1("Failed reading Object Attributes from user space.\n");
909 SetLastNtError(Status
);
913 Status
= IntValidateWindowStationHandle(
916 0, /* FIXME - WINSTA_CREATEDESKTOP */
919 if (! NT_SUCCESS(Status
))
921 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
922 hWindowStation
, lpszDesktopName
);
923 SetLastNtError(Status
);
926 if(lpszDesktopName
!= NULL
)
928 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
929 if(!NT_SUCCESS(Status
))
931 SetLastNtError(Status
);
937 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
940 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
943 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
944 ObDereferenceObject(WinStaObject
);
946 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
950 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
951 ObDereferenceObject(WinStaObject
);
954 * Try to open already existing desktop
957 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
959 /* Initialize ObjectAttributes for the desktop object */
960 InitializeObjectAttributes(
967 Status
= ObOpenObjectByName(
973 (PVOID
)&DummyContext
,
975 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
976 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
978 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
982 /* Reference the desktop */
983 Status
= ObReferenceObjectByHandle(Desktop
,
987 (PVOID
)&DesktopObject
,
989 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
991 DesktopObject
->hsectionDesktop
= NULL
;
992 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
993 &DesktopHeapSystemBase
,
995 if (DesktopObject
->pheapDesktop
== NULL
)
997 ObDereferenceObject(DesktopObject
);
998 DPRINT1("Failed to create desktop heap!\n");
1002 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1003 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1005 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1009 if (DesktopObject
->pDeskInfo
== NULL
)
1011 ObDereferenceObject(DesktopObject
);
1012 DPRINT1("Failed to create the DESKTOP structure!\n");
1016 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1019 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1020 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1021 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1022 lpszDesktopName
->Buffer
,
1023 lpszDesktopName
->Length
);
1025 /* Initialize some local (to win32k) desktop state. */
1026 InitializeListHead(&DesktopObject
->PtiList
);
1027 DesktopObject
->ActiveMessageQueue
= NULL
;
1028 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1030 if (! NT_SUCCESS(Status
))
1032 DPRINT1("Failed to create desktop handle\n");
1033 SetLastNtError(Status
);
1038 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1040 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1041 * to function at the beginning of the project by ramroding the GUI into
1042 * operation and making the desktop window work from user space.
1045 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1046 Status
= CsrInsertObject(Desktop
,
1048 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1049 if (! NT_SUCCESS(Status
))
1051 DPRINT1("Failed to create desktop handle for CSRSS\n");
1053 SetLastNtError(Status
);
1057 Status
= co_CsrNotify(&Request
);
1058 if (! NT_SUCCESS(Status
))
1060 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1061 DPRINT1("Failed to notify CSRSS about new desktop\n");
1063 SetLastNtError(Status
);
1067 W32Thread
= PsGetCurrentThreadWin32Thread();
1069 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1072 Based on wine/server/window.c in get_desktop_window.
1075 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1076 ClassName
.Length
= 0;
1077 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1078 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1080 RtlZeroMemory(&Cs
, sizeof(Cs
));
1081 Cs
.cx
= Cs
.cy
= 100;
1082 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1083 Cs
.hInstance
= hModClient
;
1084 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1085 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1087 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
);
1090 DPRINT1("Failed to create Message window handle\n");
1094 DesktopObject
->spwndMessage
= pWnd
;
1100 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1108 * Opens an existing desktop.
1112 * Name of the existing desktop.
1115 * Interaction flags.
1118 * Requested type of access.
1121 * Handle to the desktop or zero on failure.
1129 PUNICODE_STRING lpszDesktopName
,
1131 ACCESS_MASK dwDesiredAccess
)
1133 OBJECT_ATTRIBUTES ObjectAttributes
;
1135 PWINSTATION_OBJECT WinStaObject
;
1136 UNICODE_STRING DesktopName
;
1137 UNICODE_STRING SafeDesktopName
;
1141 DECLARE_RETURN(HDESK
);
1143 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1144 UserEnterExclusive();
1147 * Validate the window station handle and compose the fully
1148 * qualified desktop name
1151 WinSta
= UserGetProcessWindowStation();
1152 Status
= IntValidateWindowStationHandle(
1158 if (!NT_SUCCESS(Status
))
1160 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1161 SetLastNtError(Status
);
1165 if(lpszDesktopName
!= NULL
)
1167 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1168 if(!NT_SUCCESS(Status
))
1170 SetLastNtError(Status
);
1176 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1179 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1182 if (lpszDesktopName
)
1183 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1184 ObDereferenceObject(WinStaObject
);
1189 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1194 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1196 /* Initialize ObjectAttributes for the desktop object */
1197 InitializeObjectAttributes(
1204 Status
= ObOpenObjectByName(
1206 ExDesktopObjectType
,
1213 if (!NT_SUCCESS(Status
))
1215 SetLastNtError(Status
);
1216 ExFreePool(DesktopName
.Buffer
);
1220 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1221 ExFreePool(DesktopName
.Buffer
);
1226 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1232 * NtUserOpenInputDesktop
1234 * Opens the input (interactive) desktop.
1238 * Interaction flags.
1241 * Inheritance option.
1244 * Requested type of access.
1247 * Handle to the input desktop or zero on failure.
1254 NtUserOpenInputDesktop(
1257 ACCESS_MASK dwDesiredAccess
)
1262 DECLARE_RETURN(HDESK
);
1264 DPRINT("Enter NtUserOpenInputDesktop\n");
1265 UserEnterExclusive();
1267 DPRINT("About to open input desktop\n");
1269 /* Get a pointer to the desktop object */
1271 Status
= IntValidateDesktopHandle(
1277 if (!NT_SUCCESS(Status
))
1279 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1283 /* Create a new handle to the object */
1285 Status
= ObOpenObjectByPointer(
1290 ExDesktopObjectType
,
1294 ObDereferenceObject(Object
);
1296 if (NT_SUCCESS(Status
))
1298 DPRINT("Successfully opened input desktop\n");
1299 RETURN((HDESK
)Desktop
);
1302 SetLastNtError(Status
);
1306 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1312 * NtUserCloseDesktop
1314 * Closes a desktop handle.
1318 * Handle to the desktop.
1324 * The desktop handle can be created with NtUserCreateDesktop or
1325 * NtUserOpenDesktop. This function will fail if any thread in the calling
1326 * process is using the specified desktop handle or if the handle refers
1327 * to the initial desktop of the calling process.
1334 NtUserCloseDesktop(HDESK hDesktop
)
1338 DECLARE_RETURN(BOOL
);
1340 DPRINT("Enter NtUserCloseDesktop\n");
1341 UserEnterExclusive();
1343 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1345 Status
= IntValidateDesktopHandle(
1351 if (!NT_SUCCESS(Status
))
1353 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1357 ObDereferenceObject(Object
);
1359 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1361 Status
= ZwClose(hDesktop
);
1362 if (!NT_SUCCESS(Status
))
1364 SetLastNtError(Status
);
1371 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1380 * NtUserPaintDesktop
1382 * The NtUserPaintDesktop function fills the clipping region in the
1383 * specified device context with the desktop pattern or wallpaper. The
1384 * function is provided primarily for shell desktops.
1388 * Handle to the device context.
1395 NtUserPaintDesktop(HDC hDC
)
1398 HBRUSH DesktopBrush
, PreviousBrush
;
1400 BOOL doPatBlt
= TRUE
;
1401 PWINDOW_OBJECT WndDesktop
;
1406 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1407 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1408 DECLARE_RETURN(BOOL
);
1410 UserEnterExclusive();
1411 DPRINT("Enter NtUserPaintDesktop\n");
1413 GdiGetClipBox(hDC
, &Rect
);
1415 hWndDesktop
= IntGetDesktopWindow();
1417 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1423 DesktopBrush
= (HBRUSH
)WndDesktop
->Wnd
->pcls
->hbrBackground
;
1427 * Paint desktop background
1430 if (WinSta
->hbmWallpaper
!= NULL
)
1432 PWINDOW_OBJECT DeskWin
;
1434 DeskWin
= UserGetWindowObject(hWndDesktop
);
1442 sz
.cx
= DeskWin
->Wnd
->rcWindow
.right
- DeskWin
->Wnd
->rcWindow
.left
;
1443 sz
.cy
= DeskWin
->Wnd
->rcWindow
.bottom
- DeskWin
->Wnd
->rcWindow
.top
;
1445 if (WinSta
->WallpaperMode
== wmStretch
||
1446 WinSta
->WallpaperMode
== wmTile
)
1453 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1454 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1455 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1458 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1459 if(hWallpaperDC
!= NULL
)
1463 /* fill in the area that the bitmap is not going to cover */
1466 /* FIXME - clip out the bitmap
1467 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1468 once we support DSTINVERT */
1469 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1470 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1471 NtGdiSelectBrush(hDC
, PreviousBrush
);
1474 /*Do not fill the background after it is painted no matter the size of the picture */
1477 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1479 if (WinSta
->WallpaperMode
== wmStretch
)
1481 if(Rect
.right
&& Rect
.bottom
)
1482 NtGdiStretchBlt(hDC
,
1490 WinSta
->cxWallpaper
,
1491 WinSta
->cyWallpaper
,
1496 else if (WinSta
->WallpaperMode
== wmTile
)
1498 /* paint the bitmap across the screen then down */
1499 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1501 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1506 WinSta
->cxWallpaper
,
1507 WinSta
->cyWallpaper
,
1522 WinSta
->cxWallpaper
,
1523 WinSta
->cyWallpaper
,
1531 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1532 NtGdiDeleteObjectApp(hWallpaperDC
);
1537 /* Back ground is set to none, clear the screen */
1540 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1541 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1542 NtGdiSelectBrush(hDC
, PreviousBrush
);
1546 * Display system version on the desktop background
1549 if (g_PaintDesktopVersion
)
1551 static WCHAR s_wszVersion
[256] = {0};
1556 len
= wcslen(s_wszVersion
);
1560 len
= GetSystemVersionString(s_wszVersion
);
1565 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1567 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1568 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1571 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1572 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1573 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1575 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1577 IntGdiSetBkMode(hDC
, mode_old
);
1578 IntGdiSetTextAlign(hDC
, align_old
);
1579 IntGdiSetTextColor(hDC
, color_old
);
1586 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1593 * NtUserSwitchDesktop
1595 * Sets the current input (interactive) desktop.
1599 * Handle to desktop.
1609 NtUserSwitchDesktop(HDESK hDesktop
)
1611 PDESKTOP DesktopObject
;
1613 DECLARE_RETURN(BOOL
);
1615 UserEnterExclusive();
1616 DPRINT("Enter NtUserSwitchDesktop\n");
1618 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1620 Status
= IntValidateDesktopHandle(
1626 if (!NT_SUCCESS(Status
))
1628 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1633 * Don't allow applications switch the desktop if it's locked, unless the caller
1634 * is the logon application itself
1636 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1637 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1639 ObDereferenceObject(DesktopObject
);
1640 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1644 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1646 ObDereferenceObject(DesktopObject
);
1647 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1651 /* FIXME: Fail if the process is associated with a secured
1652 desktop such as Winlogon or Screen-Saver */
1653 /* FIXME: Connect to input device */
1655 /* Set the active desktop in the desktop's window station. */
1656 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1658 /* Set the global state. */
1659 InputDesktop
= DesktopObject
;
1660 InputDesktopHandle
= hDesktop
;
1662 ObDereferenceObject(DesktopObject
);
1667 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1673 * NtUserResolveDesktopForWOW
1680 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1687 * NtUserGetThreadDesktop
1694 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1698 PDESKTOP DesktopObject
;
1699 HDESK Ret
, hThreadDesktop
;
1700 OBJECT_HANDLE_INFORMATION HandleInformation
;
1701 DECLARE_RETURN(HDESK
);
1703 UserEnterExclusive();
1704 DPRINT("Enter NtUserGetThreadDesktop\n");
1708 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1712 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1713 if(!NT_SUCCESS(Status
))
1715 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1719 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1721 /* just return the handle, we queried the desktop handle of a thread running
1722 in the same context */
1723 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1724 ObDereferenceObject(Thread
);
1728 /* get the desktop handle and the desktop of the thread */
1729 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1730 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1732 ObDereferenceObject(Thread
);
1733 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1737 /* we could just use DesktopObject instead of looking up the handle, but latter
1738 may be a bit safer (e.g. when the desktop is being destroyed */
1739 /* switch into the context of the thread we're trying to get the desktop from,
1740 so we can use the handle */
1741 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1742 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1744 ExDesktopObjectType
,
1746 (PVOID
*)&DesktopObject
,
1747 &HandleInformation
);
1750 /* the handle couldn't be found, there's nothing to get... */
1751 if(!NT_SUCCESS(Status
))
1753 ObDereferenceObject(Thread
);
1757 /* lookup our handle table if we can find a handle to the desktop object,
1758 if not, create one */
1759 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1761 /* all done, we got a valid handle to the desktop */
1762 ObDereferenceObject(DesktopObject
);
1763 ObDereferenceObject(Thread
);
1767 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1773 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1776 PPROCESSINFO CurrentWin32Process
;
1777 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1778 NTSTATUS Status
= STATUS_SUCCESS
;
1782 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1783 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1785 /* unmap if we're the last thread using the desktop */
1786 HeapMapping
= *PrevLink
;
1787 while (HeapMapping
!= NULL
)
1789 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1791 if (--HeapMapping
->Count
== 0)
1793 *PrevLink
= HeapMapping
->Next
;
1795 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1796 HeapMapping
->UserMapping
);
1798 ObDereferenceObject(DesktopObject
);
1800 UserHeapFree(HeapMapping
);
1805 PrevLink
= &HeapMapping
->Next
;
1806 HeapMapping
= HeapMapping
->Next
;
1809 ti
= GetW32ThreadInfo();
1812 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1814 GetWin32ClientInfo()->ulClientDelta
= 0;
1820 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1823 PPROCESSINFO CurrentWin32Process
;
1824 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1825 PVOID UserBase
= NULL
;
1826 SIZE_T ViewSize
= 0;
1827 LARGE_INTEGER Offset
;
1830 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1831 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1833 /* find out if another thread already mapped the desktop heap */
1834 HeapMapping
= *PrevLink
;
1835 while (HeapMapping
!= NULL
)
1837 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1839 HeapMapping
->Count
++;
1840 return STATUS_SUCCESS
;
1843 PrevLink
= &HeapMapping
->Next
;
1844 HeapMapping
= HeapMapping
->Next
;
1847 /* we're the first, map the heap */
1848 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1849 Offset
.QuadPart
= 0;
1850 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1851 PsGetCurrentProcess(),
1859 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1860 if (!NT_SUCCESS(Status
))
1862 DPRINT1("Failed to map desktop\n");
1866 /* add the mapping */
1867 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1868 if (HeapMapping
== NULL
)
1870 MmUnmapViewOfSection(PsGetCurrentProcess(),
1872 DPRINT1("UserHeapAlloc() failed!\n");
1873 return STATUS_NO_MEMORY
;
1876 HeapMapping
->Next
= NULL
;
1877 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1878 HeapMapping
->UserMapping
= UserBase
;
1879 HeapMapping
->Limit
= ViewSize
;
1880 HeapMapping
->Count
= 1;
1881 *PrevLink
= HeapMapping
;
1883 ObReferenceObject(DesktopObject
);
1885 /* create a W32THREADINFO structure if not already done, or update it */
1886 ti
= GetW32ThreadInfo();
1887 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1890 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1892 GetWin32ClientInfo()->pDeskInfo
=
1893 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1894 GetWin32ClientInfo()->ulClientDelta
);
1898 return STATUS_SUCCESS
;
1902 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1903 IN BOOL FreeOnFailure
)
1905 PDESKTOP OldDesktop
;
1906 PTHREADINFO W32Thread
;
1910 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1911 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1912 W32Thread
= PsGetCurrentThreadWin32Thread();
1914 if (W32Thread
->rpdesk
!= DesktopObject
)
1916 OldDesktop
= W32Thread
->rpdesk
;
1918 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1920 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1921 SetLastWin32Error(ERROR_BUSY
);
1925 W32Thread
->rpdesk
= DesktopObject
;
1927 if (MapHeap
&& DesktopObject
!= NULL
)
1929 Status
= IntMapDesktopView(DesktopObject
);
1930 if (!NT_SUCCESS(Status
))
1932 SetLastNtError(Status
);
1937 /* Hack for system threads */
1940 PCLIENTINFO pci
= GetWin32ClientInfo();
1941 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1944 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1948 if (OldDesktop
!= NULL
&&
1949 !IntCheckProcessDesktopClasses(OldDesktop
,
1952 DPRINT1("Failed to move process classes to shared heap!\n");
1954 /* failed to move desktop classes to the shared heap,
1955 unmap the view and return the error */
1956 if (MapHeap
&& DesktopObject
!= NULL
)
1957 IntUnmapDesktopView(DesktopObject
);
1962 /* Remove the thread from the old desktop's list */
1963 RemoveEntryList(&W32Thread
->PtiLink
);
1965 if (DesktopObject
!= NULL
)
1967 ObReferenceObject(DesktopObject
);
1968 /* Insert into new desktop's list */
1969 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
1972 if (OldDesktop
!= NULL
)
1976 IntUnmapDesktopView(OldDesktop
);
1979 ObDereferenceObject(OldDesktop
);
1987 * NtUserSetThreadDesktop
1994 NtUserSetThreadDesktop(HDESK hDesktop
)
1996 PDESKTOP DesktopObject
;
1998 DECLARE_RETURN(BOOL
);
2000 UserEnterExclusive();
2001 DPRINT("Enter NtUserSetThreadDesktop\n");
2003 /* Validate the new desktop. */
2004 Status
= IntValidateDesktopHandle(
2010 if (!NT_SUCCESS(Status
))
2012 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2016 /* FIXME: Should check here to see if the thread has any windows. */
2018 if (!IntSetThreadDesktop(DesktopObject
,
2027 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);