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 PWND 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 PWND 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
);
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
);
658 DesktopWnd
= IntGetWindowObject(Desktop
->DesktopWindow
);
661 return ERROR_INVALID_WINDOW_HANDLE
;
663 DesktopWnd
->style
&= ~WS_VISIBLE
;
665 return STATUS_SUCCESS
;
674 UserBuildShellHookHwndList(PDESKTOP Desktop
)
677 PSHELL_HOOK_WINDOW Current
;
680 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
681 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
684 if (!entries
) return NULL
;
686 list
= ExAllocatePoolWithTag(PagedPool
, sizeof(HWND
) * (entries
+ 1), USERTAG_WINDOWLIST
); /* alloc one extra for nullterm */
691 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
692 *cursor
++ = Current
->hWnd
;
694 *cursor
= NULL
; /* nullterm list */
701 * Send the Message to the windows registered for ShellHook
702 * notifications. The lParam contents depend on the Message. See
703 * MSDN for more details (RegisterShellHookWindow)
705 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
707 PDESKTOP Desktop
= IntGetActiveDesktop();
710 static UINT MsgType
= 0;
715 /* Too bad, this doesn't work.*/
718 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
719 MsgType
= UserRegisterWindowMessage(&Str
);
722 MsgType
= IntAddAtom(L
"SHELLHOOK");
724 DPRINT("MsgType = %x\n", MsgType
);
726 DPRINT1("LastError: %x\n", GetLastNtError());
731 DPRINT("IntShellHookNotify: No desktop!\n");
735 HwndList
= UserBuildShellHookHwndList(Desktop
);
738 HWND
* cursor
= HwndList
;
740 for (; *cursor
; cursor
++)
742 DPRINT("Sending notify\n");
743 co_IntPostOrSendMessage(*cursor
,
749 ExFreePool(HwndList
);
755 * Add the window to the ShellHookWindows list. The windows
756 * on that list get notifications that are important to shell
759 * TODO: Validate the window? I'm not sure if sending these messages to
760 * an unsuspecting application that is not your own is a nice thing to do.
762 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
764 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
765 PDESKTOP Desktop
= pti
->rpdesk
;
766 PSHELL_HOOK_WINDOW Entry
;
768 DPRINT("IntRegisterShellHookWindow\n");
770 /* First deregister the window, so we can be sure it's never twice in the
773 IntDeRegisterShellHookWindow(hWnd
);
775 Entry
= ExAllocatePoolWithTag(PagedPool
,
776 sizeof(SHELL_HOOK_WINDOW
),
784 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
790 * Remove the window from the ShellHookWindows list. The windows
791 * on that list get notifications that are important to shell
794 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
796 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
797 PDESKTOP Desktop
= pti
->rpdesk
;
798 PSHELL_HOOK_WINDOW Current
;
800 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
802 if (Current
->hWnd
== hWnd
)
804 RemoveEntryList(&Current
->ListEntry
);
814 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
816 if (Desktop
->hsectionDesktop
!= NULL
)
818 ObDereferenceObject(Desktop
->hsectionDesktop
);
819 Desktop
->hsectionDesktop
= NULL
;
822 /* SYSCALLS *******************************************************************/
825 * NtUserCreateDesktop
827 * Creates a new desktop.
834 * Name of the device.
843 * Requested type of access.
847 * If the function succeeds, the return value is a handle to the newly
848 * created desktop. If the specified desktop already exists, the function
849 * succeeds and returns a handle to the existing desktop. When you are
850 * finished using the handle, call the CloseDesktop function to close it.
851 * If the function fails, the return value is NULL.
859 POBJECT_ATTRIBUTES poa
,
860 PUNICODE_STRING lpszDesktopDevice
,
863 ACCESS_MASK dwDesiredAccess
)
865 OBJECT_ATTRIBUTES ObjectAttributes
;
866 PTHREADINFO W32Thread
;
867 PWINSTATION_OBJECT WinStaObject
;
868 PDESKTOP DesktopObject
;
869 UNICODE_STRING DesktopName
;
870 NTSTATUS Status
= STATUS_SUCCESS
;
872 CSR_API_MESSAGE Request
;
873 PVOID DesktopHeapSystemBase
= NULL
;
874 SIZE_T DesktopInfoSize
;
875 UNICODE_STRING SafeDesktopName
;
877 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
878 HWINSTA hWindowStation
= NULL
;
879 PUNICODE_STRING lpszDesktopName
= NULL
;
880 UNICODE_STRING ClassName
, MenuName
;
881 LARGE_STRING WindowName
;
885 DECLARE_RETURN(HDESK
);
887 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
888 UserEnterExclusive();
893 sizeof(OBJECT_ATTRIBUTES
),
896 hWindowStation
= poa
->RootDirectory
;
897 lpszDesktopName
= poa
->ObjectName
;
899 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
901 Status
=_SEH2_GetExceptionCode();
905 if (! NT_SUCCESS(Status
))
907 DPRINT1("Failed reading Object Attributes from user space.\n");
908 SetLastNtError(Status
);
912 Status
= IntValidateWindowStationHandle(
915 0, /* FIXME - WINSTA_CREATEDESKTOP */
918 if (! NT_SUCCESS(Status
))
920 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
921 hWindowStation
, lpszDesktopName
);
922 SetLastNtError(Status
);
925 if(lpszDesktopName
!= NULL
)
927 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
928 if(!NT_SUCCESS(Status
))
930 SetLastNtError(Status
);
936 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
939 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
942 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
943 ObDereferenceObject(WinStaObject
);
945 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
949 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
950 ObDereferenceObject(WinStaObject
);
953 * Try to open already existing desktop
956 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
958 /* Initialize ObjectAttributes for the desktop object */
959 InitializeObjectAttributes(
966 Status
= ObOpenObjectByName(
972 (PVOID
)&DummyContext
,
974 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
975 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
977 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
981 /* Reference the desktop */
982 Status
= ObReferenceObjectByHandle(Desktop
,
986 (PVOID
)&DesktopObject
,
988 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
990 DesktopObject
->hsectionDesktop
= NULL
;
991 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
992 &DesktopHeapSystemBase
,
994 if (DesktopObject
->pheapDesktop
== NULL
)
996 ObDereferenceObject(DesktopObject
);
997 DPRINT1("Failed to create desktop heap!\n");
1001 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1002 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1004 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1008 if (DesktopObject
->pDeskInfo
== NULL
)
1010 ObDereferenceObject(DesktopObject
);
1011 DPRINT1("Failed to create the DESKTOP structure!\n");
1015 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1018 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1019 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1020 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1021 lpszDesktopName
->Buffer
,
1022 lpszDesktopName
->Length
);
1024 /* Initialize some local (to win32k) desktop state. */
1025 InitializeListHead(&DesktopObject
->PtiList
);
1026 DesktopObject
->ActiveMessageQueue
= NULL
;
1027 /* Setup Global Hooks. */
1028 for (i
= 0; i
< NB_HOOKS
; i
++)
1030 InitializeListHead(&DesktopObject
->pDeskInfo
->aphkStart
[i
]);
1032 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1034 if (! NT_SUCCESS(Status
))
1036 DPRINT1("Failed to create desktop handle\n");
1037 SetLastNtError(Status
);
1042 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1044 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1045 * to function at the beginning of the project by ramroding the GUI into
1046 * operation and making the desktop window work from user space.
1049 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1050 Status
= CsrInsertObject(Desktop
,
1052 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1053 if (! NT_SUCCESS(Status
))
1055 DPRINT1("Failed to create desktop handle for CSRSS\n");
1057 SetLastNtError(Status
);
1061 Status
= co_CsrNotify(&Request
);
1062 if (! NT_SUCCESS(Status
))
1064 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1065 DPRINT1("Failed to notify CSRSS about new desktop\n");
1067 SetLastNtError(Status
);
1071 W32Thread
= PsGetCurrentThreadWin32Thread();
1073 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1076 Based on wine/server/window.c in get_desktop_window.
1079 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1080 ClassName
.Length
= 0;
1081 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1082 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1084 RtlZeroMemory(&Cs
, sizeof(Cs
));
1085 Cs
.cx
= Cs
.cy
= 100;
1086 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1087 Cs
.hInstance
= hModClient
;
1088 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1089 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1091 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
);
1094 DPRINT1("Failed to create Message window handle\n");
1098 DesktopObject
->spwndMessage
= pWnd
;
1104 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1112 * Opens an existing desktop.
1116 * Name of the existing desktop.
1119 * Interaction flags.
1122 * Requested type of access.
1125 * Handle to the desktop or zero on failure.
1133 PUNICODE_STRING lpszDesktopName
,
1135 ACCESS_MASK dwDesiredAccess
)
1137 OBJECT_ATTRIBUTES ObjectAttributes
;
1139 PWINSTATION_OBJECT WinStaObject
;
1140 UNICODE_STRING DesktopName
;
1141 UNICODE_STRING SafeDesktopName
;
1145 DECLARE_RETURN(HDESK
);
1147 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1148 UserEnterExclusive();
1151 * Validate the window station handle and compose the fully
1152 * qualified desktop name
1155 WinSta
= UserGetProcessWindowStation();
1156 Status
= IntValidateWindowStationHandle(
1162 if (!NT_SUCCESS(Status
))
1164 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1165 SetLastNtError(Status
);
1169 if(lpszDesktopName
!= NULL
)
1171 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1172 if(!NT_SUCCESS(Status
))
1174 SetLastNtError(Status
);
1180 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1183 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1186 if (lpszDesktopName
)
1187 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1188 ObDereferenceObject(WinStaObject
);
1193 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1198 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1200 /* Initialize ObjectAttributes for the desktop object */
1201 InitializeObjectAttributes(
1208 Status
= ObOpenObjectByName(
1210 ExDesktopObjectType
,
1217 if (!NT_SUCCESS(Status
))
1219 SetLastNtError(Status
);
1220 ExFreePool(DesktopName
.Buffer
);
1224 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1225 ExFreePool(DesktopName
.Buffer
);
1230 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1236 * NtUserOpenInputDesktop
1238 * Opens the input (interactive) desktop.
1242 * Interaction flags.
1245 * Inheritance option.
1248 * Requested type of access.
1251 * Handle to the input desktop or zero on failure.
1258 NtUserOpenInputDesktop(
1261 ACCESS_MASK dwDesiredAccess
)
1266 DECLARE_RETURN(HDESK
);
1268 DPRINT("Enter NtUserOpenInputDesktop\n");
1269 UserEnterExclusive();
1271 DPRINT("About to open input desktop\n");
1273 /* Get a pointer to the desktop object */
1275 Status
= IntValidateDesktopHandle(
1281 if (!NT_SUCCESS(Status
))
1283 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1287 /* Create a new handle to the object */
1289 Status
= ObOpenObjectByPointer(
1294 ExDesktopObjectType
,
1298 ObDereferenceObject(Object
);
1300 if (NT_SUCCESS(Status
))
1302 DPRINT("Successfully opened input desktop\n");
1303 RETURN((HDESK
)Desktop
);
1306 SetLastNtError(Status
);
1310 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1316 * NtUserCloseDesktop
1318 * Closes a desktop handle.
1322 * Handle to the desktop.
1328 * The desktop handle can be created with NtUserCreateDesktop or
1329 * NtUserOpenDesktop. This function will fail if any thread in the calling
1330 * process is using the specified desktop handle or if the handle refers
1331 * to the initial desktop of the calling process.
1338 NtUserCloseDesktop(HDESK hDesktop
)
1342 DECLARE_RETURN(BOOL
);
1344 DPRINT("Enter NtUserCloseDesktop\n");
1345 UserEnterExclusive();
1347 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1349 Status
= IntValidateDesktopHandle(
1355 if (!NT_SUCCESS(Status
))
1357 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1361 ObDereferenceObject(Object
);
1363 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1365 Status
= ZwClose(hDesktop
);
1366 if (!NT_SUCCESS(Status
))
1368 SetLastNtError(Status
);
1375 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1384 * NtUserPaintDesktop
1386 * The NtUserPaintDesktop function fills the clipping region in the
1387 * specified device context with the desktop pattern or wallpaper. The
1388 * function is provided primarily for shell desktops.
1392 * Handle to the device context.
1399 NtUserPaintDesktop(HDC hDC
)
1402 HBRUSH DesktopBrush
, PreviousBrush
;
1404 BOOL doPatBlt
= TRUE
;
1410 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1411 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1412 DECLARE_RETURN(BOOL
);
1414 UserEnterExclusive();
1415 DPRINT("Enter NtUserPaintDesktop\n");
1417 GdiGetClipBox(hDC
, &Rect
);
1419 hWndDesktop
= IntGetDesktopWindow();
1421 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1427 DesktopBrush
= (HBRUSH
)WndDesktop
->pcls
->hbrBackground
;
1431 * Paint desktop background
1434 if (WinSta
->hbmWallpaper
!= NULL
)
1438 DeskWin
= UserGetWindowObject(hWndDesktop
);
1446 sz
.cx
= DeskWin
->rcWindow
.right
- DeskWin
->rcWindow
.left
;
1447 sz
.cy
= DeskWin
->rcWindow
.bottom
- DeskWin
->rcWindow
.top
;
1449 if (WinSta
->WallpaperMode
== wmStretch
||
1450 WinSta
->WallpaperMode
== wmTile
)
1457 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1458 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1459 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1462 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1463 if(hWallpaperDC
!= NULL
)
1467 /* fill in the area that the bitmap is not going to cover */
1470 /* FIXME - clip out the bitmap
1471 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1472 once we support DSTINVERT */
1473 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1474 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1475 NtGdiSelectBrush(hDC
, PreviousBrush
);
1478 /*Do not fill the background after it is painted no matter the size of the picture */
1481 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1483 if (WinSta
->WallpaperMode
== wmStretch
)
1485 if(Rect
.right
&& Rect
.bottom
)
1486 NtGdiStretchBlt(hDC
,
1494 WinSta
->cxWallpaper
,
1495 WinSta
->cyWallpaper
,
1500 else if (WinSta
->WallpaperMode
== wmTile
)
1502 /* paint the bitmap across the screen then down */
1503 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1505 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1510 WinSta
->cxWallpaper
,
1511 WinSta
->cyWallpaper
,
1526 WinSta
->cxWallpaper
,
1527 WinSta
->cyWallpaper
,
1535 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1536 NtGdiDeleteObjectApp(hWallpaperDC
);
1541 /* Back ground is set to none, clear the screen */
1544 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1545 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1546 NtGdiSelectBrush(hDC
, PreviousBrush
);
1550 * Display system version on the desktop background
1553 if (g_PaintDesktopVersion
)
1555 static WCHAR s_wszVersion
[256] = {0};
1560 len
= wcslen(s_wszVersion
);
1564 len
= GetSystemVersionString(s_wszVersion
);
1569 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1571 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1572 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1575 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1576 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1577 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1579 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1581 IntGdiSetBkMode(hDC
, mode_old
);
1582 IntGdiSetTextAlign(hDC
, align_old
);
1583 IntGdiSetTextColor(hDC
, color_old
);
1590 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1597 * NtUserSwitchDesktop
1599 * Sets the current input (interactive) desktop.
1603 * Handle to desktop.
1613 NtUserSwitchDesktop(HDESK hDesktop
)
1615 PDESKTOP DesktopObject
;
1617 DECLARE_RETURN(BOOL
);
1619 UserEnterExclusive();
1620 DPRINT("Enter NtUserSwitchDesktop\n");
1622 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1624 Status
= IntValidateDesktopHandle(
1630 if (!NT_SUCCESS(Status
))
1632 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1637 * Don't allow applications switch the desktop if it's locked, unless the caller
1638 * is the logon application itself
1640 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1641 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1643 ObDereferenceObject(DesktopObject
);
1644 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1648 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1650 ObDereferenceObject(DesktopObject
);
1651 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1655 /* FIXME: Fail if the process is associated with a secured
1656 desktop such as Winlogon or Screen-Saver */
1657 /* FIXME: Connect to input device */
1659 /* Set the active desktop in the desktop's window station. */
1660 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1662 /* Set the global state. */
1663 InputDesktop
= DesktopObject
;
1664 InputDesktopHandle
= hDesktop
;
1666 ObDereferenceObject(DesktopObject
);
1671 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1677 * NtUserResolveDesktopForWOW
1684 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1691 * NtUserGetThreadDesktop
1698 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1702 PDESKTOP DesktopObject
;
1703 HDESK Ret
, hThreadDesktop
;
1704 OBJECT_HANDLE_INFORMATION HandleInformation
;
1705 DECLARE_RETURN(HDESK
);
1707 UserEnterExclusive();
1708 DPRINT("Enter NtUserGetThreadDesktop\n");
1712 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1716 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1717 if(!NT_SUCCESS(Status
))
1719 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1723 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1725 /* just return the handle, we queried the desktop handle of a thread running
1726 in the same context */
1727 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1728 ObDereferenceObject(Thread
);
1732 /* get the desktop handle and the desktop of the thread */
1733 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1734 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1736 ObDereferenceObject(Thread
);
1737 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1741 /* we could just use DesktopObject instead of looking up the handle, but latter
1742 may be a bit safer (e.g. when the desktop is being destroyed */
1743 /* switch into the context of the thread we're trying to get the desktop from,
1744 so we can use the handle */
1745 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1746 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1748 ExDesktopObjectType
,
1750 (PVOID
*)&DesktopObject
,
1751 &HandleInformation
);
1754 /* the handle couldn't be found, there's nothing to get... */
1755 if(!NT_SUCCESS(Status
))
1757 ObDereferenceObject(Thread
);
1761 /* lookup our handle table if we can find a handle to the desktop object,
1762 if not, create one */
1763 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1765 /* all done, we got a valid handle to the desktop */
1766 ObDereferenceObject(DesktopObject
);
1767 ObDereferenceObject(Thread
);
1771 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1777 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1780 PPROCESSINFO CurrentWin32Process
;
1781 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1782 NTSTATUS Status
= STATUS_SUCCESS
;
1786 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1787 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1789 /* unmap if we're the last thread using the desktop */
1790 HeapMapping
= *PrevLink
;
1791 while (HeapMapping
!= NULL
)
1793 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1795 if (--HeapMapping
->Count
== 0)
1797 *PrevLink
= HeapMapping
->Next
;
1799 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1800 HeapMapping
->UserMapping
);
1802 ObDereferenceObject(DesktopObject
);
1804 UserHeapFree(HeapMapping
);
1809 PrevLink
= &HeapMapping
->Next
;
1810 HeapMapping
= HeapMapping
->Next
;
1813 ti
= GetW32ThreadInfo();
1816 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1818 GetWin32ClientInfo()->ulClientDelta
= 0;
1824 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1827 PPROCESSINFO CurrentWin32Process
;
1828 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1829 PVOID UserBase
= NULL
;
1830 SIZE_T ViewSize
= 0;
1831 LARGE_INTEGER Offset
;
1834 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1835 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1837 /* find out if another thread already mapped the desktop heap */
1838 HeapMapping
= *PrevLink
;
1839 while (HeapMapping
!= NULL
)
1841 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1843 HeapMapping
->Count
++;
1844 return STATUS_SUCCESS
;
1847 PrevLink
= &HeapMapping
->Next
;
1848 HeapMapping
= HeapMapping
->Next
;
1851 /* we're the first, map the heap */
1852 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1853 Offset
.QuadPart
= 0;
1854 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1855 PsGetCurrentProcess(),
1863 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1864 if (!NT_SUCCESS(Status
))
1866 DPRINT1("Failed to map desktop\n");
1870 /* add the mapping */
1871 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1872 if (HeapMapping
== NULL
)
1874 MmUnmapViewOfSection(PsGetCurrentProcess(),
1876 DPRINT1("UserHeapAlloc() failed!\n");
1877 return STATUS_NO_MEMORY
;
1880 HeapMapping
->Next
= NULL
;
1881 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1882 HeapMapping
->UserMapping
= UserBase
;
1883 HeapMapping
->Limit
= ViewSize
;
1884 HeapMapping
->Count
= 1;
1885 *PrevLink
= HeapMapping
;
1887 ObReferenceObject(DesktopObject
);
1889 /* create a W32THREADINFO structure if not already done, or update it */
1890 ti
= GetW32ThreadInfo();
1891 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1894 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1896 GetWin32ClientInfo()->pDeskInfo
=
1897 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1898 GetWin32ClientInfo()->ulClientDelta
);
1902 return STATUS_SUCCESS
;
1906 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1907 IN BOOL FreeOnFailure
)
1909 PDESKTOP OldDesktop
;
1910 PTHREADINFO W32Thread
;
1914 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1915 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1916 W32Thread
= PsGetCurrentThreadWin32Thread();
1918 if (W32Thread
->rpdesk
!= DesktopObject
)
1920 OldDesktop
= W32Thread
->rpdesk
;
1922 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1924 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1925 SetLastWin32Error(ERROR_BUSY
);
1929 W32Thread
->rpdesk
= DesktopObject
;
1931 if (MapHeap
&& DesktopObject
!= NULL
)
1933 Status
= IntMapDesktopView(DesktopObject
);
1934 if (!NT_SUCCESS(Status
))
1936 SetLastNtError(Status
);
1941 /* Hack for system threads */
1944 PCLIENTINFO pci
= GetWin32ClientInfo();
1945 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1948 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1952 if (OldDesktop
!= NULL
&&
1953 !IntCheckProcessDesktopClasses(OldDesktop
,
1956 DPRINT1("Failed to move process classes to shared heap!\n");
1958 /* failed to move desktop classes to the shared heap,
1959 unmap the view and return the error */
1960 if (MapHeap
&& DesktopObject
!= NULL
)
1961 IntUnmapDesktopView(DesktopObject
);
1966 /* Remove the thread from the old desktop's list */
1967 RemoveEntryList(&W32Thread
->PtiLink
);
1969 if (DesktopObject
!= NULL
)
1971 ObReferenceObject(DesktopObject
);
1972 /* Insert into new desktop's list */
1973 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
1976 if (OldDesktop
!= NULL
)
1980 IntUnmapDesktopView(OldDesktop
);
1983 ObDereferenceObject(OldDesktop
);
1991 * NtUserSetThreadDesktop
1998 NtUserSetThreadDesktop(HDESK hDesktop
)
2000 PDESKTOP DesktopObject
;
2002 DECLARE_RETURN(BOOL
);
2004 UserEnterExclusive();
2005 DPRINT("Enter NtUserSetThreadDesktop\n");
2007 /* Validate the new desktop. */
2008 Status
= IntValidateDesktopHandle(
2014 if (!NT_SUCCESS(Status
))
2016 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2020 /* FIXME: Should check here to see if the thread has any windows. */
2022 if (!IntSetThreadDesktop(DesktopObject
,
2031 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);