2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/desktop.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
24 IN OUT PDESKTOP Desktop
27 /* GLOBALS *******************************************************************/
29 /* Currently active desktop */
30 PDESKTOP InputDesktop
= NULL
;
31 HDESK InputDesktopHandle
= NULL
;
32 HDC ScreenDeviceContext
= NULL
;
33 BOOL g_PaintDesktopVersion
= FALSE
;
35 GENERIC_MAPPING IntDesktopMapping
=
37 STANDARD_RIGHTS_READ
| DESKTOP_ENUMERATE
|
39 STANDARD_RIGHTS_WRITE
| DESKTOP_CREATEMENU
|
40 DESKTOP_CREATEWINDOW
|
42 DESKTOP_JOURNALPLAYBACK
|
43 DESKTOP_JOURNALRECORD
|
45 STANDARD_RIGHTS_EXECUTE
| DESKTOP_SWITCHDESKTOP
,
46 STANDARD_RIGHTS_REQUIRED
| DESKTOP_CREATEMENU
|
47 DESKTOP_CREATEWINDOW
|
50 DESKTOP_JOURNALPLAYBACK
|
51 DESKTOP_JOURNALRECORD
|
53 DESKTOP_SWITCHDESKTOP
|
57 /* OBJECT CALLBACKS **********************************************************/
61 IntDesktopObjectParse(IN PVOID ParseObject
,
63 IN OUT PACCESS_STATE AccessState
,
64 IN KPROCESSOR_MODE AccessMode
,
66 IN OUT PUNICODE_STRING CompleteName
,
67 IN OUT PUNICODE_STRING RemainingName
,
68 IN OUT PVOID Context OPTIONAL
,
69 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL
,
74 OBJECT_ATTRIBUTES ObjectAttributes
;
75 PLIST_ENTRY NextEntry
, ListHead
;
76 PWINSTATION_OBJECT WinStaObject
= (PWINSTATION_OBJECT
)ParseObject
;
77 PUNICODE_STRING DesktopName
;
79 /* Set the list pointers and loop the window station */
80 ListHead
= &WinStaObject
->DesktopListHead
;
81 NextEntry
= ListHead
->Flink
;
82 while (NextEntry
!= ListHead
)
84 /* Get the current desktop */
85 Desktop
= CONTAINING_RECORD(NextEntry
, DESKTOP
, ListEntry
);
88 DesktopName
= GET_DESKTOP_NAME(Desktop
);
91 /* Compare the name */
92 if (RtlEqualUnicodeString(RemainingName
,
94 (Attributes
& OBJ_CASE_INSENSITIVE
)))
96 /* We found a match. Did this come from a create? */
99 /* Unless OPEN_IF was given, fail with an error */
100 if (!(Attributes
& OBJ_OPENIF
))
103 return STATUS_OBJECT_NAME_COLLISION
;
107 /* Otherwise, return with a warning only */
108 Status
= STATUS_OBJECT_NAME_EXISTS
;
113 /* This was a real open, so this is OK */
114 Status
= STATUS_SUCCESS
;
117 /* Reference the desktop and return it */
118 ObReferenceObject(Desktop
);
124 /* Go to the next desktop */
125 NextEntry
= NextEntry
->Flink
;
128 /* If we got here but this isn't a create, then fail */
129 if (!Context
) return STATUS_OBJECT_NAME_NOT_FOUND
;
131 /* Create the desktop object */
132 InitializeObjectAttributes(&ObjectAttributes
, RemainingName
, 0, NULL
, NULL
);
133 Status
= ObCreateObject(KernelMode
,
142 if (!NT_SUCCESS(Status
)) return Status
;
144 /* Initialize shell hook window list and set the parent */
145 RtlZeroMemory(Desktop
, sizeof(DESKTOP
));
146 InitializeListHead(&Desktop
->ShellHookWindows
);
147 Desktop
->rpwinstaParent
= (PWINSTATION_OBJECT
)ParseObject
;
149 /* Put the desktop on the window station's list of associated desktops */
150 InsertTailList(&Desktop
->rpwinstaParent
->DesktopListHead
,
151 &Desktop
->ListEntry
);
153 /* Set the desktop object and return success */
155 return STATUS_SUCCESS
;
159 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters
)
161 PDESKTOP Desktop
= (PDESKTOP
)Parameters
->Object
;
163 DPRINT("Deleting desktop (0x%X)\n", Desktop
);
165 /* Remove the desktop from the window station's list of associcated desktops */
166 RemoveEntryList(&Desktop
->ListEntry
);
168 IntFreeDesktopHeap(Desktop
);
171 /* PRIVATE FUNCTIONS **********************************************************/
175 InitDesktopImpl(VOID
)
177 /* Set Desktop Object Attributes */
178 ExDesktopObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
= sizeof(DESKTOP
);
179 ExDesktopObjectType
->TypeInfo
.GenericMapping
= IntDesktopMapping
;
180 return STATUS_SUCCESS
;
185 CleanupDesktopImpl(VOID
)
187 return STATUS_SUCCESS
;
190 static int GetSystemVersionString(LPWSTR buffer
)
192 RTL_OSVERSIONINFOEXW versionInfo
;
195 versionInfo
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
197 if (!NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&versionInfo
)))
200 if (versionInfo
.dwMajorVersion
<= 4)
201 len
= swprintf(buffer
,
202 L
"ReactOS Version %d.%d %s Build %d",
203 versionInfo
.dwMajorVersion
, versionInfo
.dwMinorVersion
,
204 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
206 len
= swprintf(buffer
,
207 L
"ReactOS %s (Build %d)",
208 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
215 IntParseDesktopPath(PEPROCESS Process
,
216 PUNICODE_STRING DesktopPath
,
220 OBJECT_ATTRIBUTES ObjectAttributes
;
221 UNICODE_STRING WinSta
, Desktop
, FullName
;
222 BOOL DesktopPresent
= FALSE
;
223 BOOL WinStaPresent
= FALSE
;
235 RtlInitUnicodeString(&WinSta
, NULL
);
236 RtlInitUnicodeString(&Desktop
, NULL
);
238 if(DesktopPath
!= NULL
&& DesktopPath
->Buffer
!= NULL
&& DesktopPath
->Length
> sizeof(WCHAR
))
240 PWCHAR c
= DesktopPath
->Buffer
;
242 USHORT l
= DesktopPath
->Length
;
245 * Parse the desktop path string which can be in the form "WinSta\Desktop"
246 * or just "Desktop". In latter case WinSta0 will be used.
253 wl
= (ULONG_PTR
)c
- (ULONG_PTR
)DesktopPath
->Buffer
;
263 WinSta
.MaximumLength
= wl
+ sizeof(WCHAR
);
264 WinSta
.Buffer
= DesktopPath
->Buffer
;
266 WinStaPresent
= TRUE
;
270 Desktop
.Length
= DesktopPath
->Length
- wl
;
273 Desktop
.Length
-= sizeof(WCHAR
);
275 if(Desktop
.Length
> 0)
277 Desktop
.MaximumLength
= Desktop
.Length
+ sizeof(WCHAR
);
278 Desktop
.Buffer
= ((wl
> 0) ? c
: DesktopPath
->Buffer
);
279 DesktopPresent
= TRUE
;
286 /* search the process handle table for (inherited) window station
287 handles, use a more appropriate one than WinSta0 if possible. */
288 if (!ObFindHandleForObject(Process
,
290 ExWindowStationObjectType
,
295 /* we had no luck searching for opened handles, use WinSta0 now */
296 RtlInitUnicodeString(&WinSta
, L
"WinSta0");
300 if(!DesktopPresent
&& hDesktop
!= NULL
)
303 /* search the process handle table for (inherited) desktop
304 handles, use a more appropriate one than Default if possible. */
305 if (!ObFindHandleForObject(Process
,
312 /* we had no luck searching for opened handles, use Desktop now */
313 RtlInitUnicodeString(&Desktop
, L
"Default");
319 if(!IntGetFullWindowStationName(&FullName
, &WinSta
, NULL
))
321 return STATUS_INSUFFICIENT_RESOURCES
;
324 /* open the window station */
325 InitializeObjectAttributes(&ObjectAttributes
,
327 OBJ_CASE_INSENSITIVE
,
331 Status
= ObOpenObjectByName(&ObjectAttributes
,
332 ExWindowStationObjectType
,
339 ExFreePoolWithTag(FullName
.Buffer
, TAG_STRING
);
341 if(!NT_SUCCESS(Status
))
343 SetLastNtError(Status
);
344 DPRINT("Failed to reference window station %wZ PID: %d!\n", &WinSta
, PsGetCurrentProcessId());
349 if(hDesktop
!= NULL
&& *hDesktop
== NULL
)
351 if(!IntGetFullWindowStationName(&FullName
, &WinSta
, &Desktop
))
355 return STATUS_INSUFFICIENT_RESOURCES
;
358 /* open the desktop object */
359 InitializeObjectAttributes(&ObjectAttributes
,
361 OBJ_CASE_INSENSITIVE
,
365 Status
= ObOpenObjectByName(&ObjectAttributes
,
373 ExFreePoolWithTag(FullName
.Buffer
, TAG_STRING
);
375 if(!NT_SUCCESS(Status
))
380 SetLastNtError(Status
);
381 DPRINT("Failed to reference desktop %wZ PID: %d!\n", &Desktop
, PsGetCurrentProcessId());
386 return STATUS_SUCCESS
;
390 * IntValidateDesktopHandle
392 * Validates the desktop handle.
395 * If the function succeeds, the handle remains referenced. If the
396 * fucntion fails, last error is set.
400 IntValidateDesktopHandle(
402 KPROCESSOR_MODE AccessMode
,
403 ACCESS_MASK DesiredAccess
,
408 Status
= ObReferenceObjectByHandle(
416 if (!NT_SUCCESS(Status
))
417 SetLastNtError(Status
);
423 IntGetDesktopWorkArea(PDESKTOP Desktop
, RECTL
*Rect
)
429 Ret
= &Desktop
->WorkArea
;
430 if((Ret
->right
== -1) && ScreenDeviceContext
)
434 dc
= DC_LockDc(ScreenDeviceContext
);
435 /* FIXME - Handle dc == NULL!!!! */
436 psurf
= dc
->dclevel
.pSurface
;
439 Ret
->right
= psurf
->SurfObj
.sizlBitmap
.cx
;
440 Ret
->bottom
= psurf
->SurfObj
.sizlBitmap
.cy
;
452 IntGetActiveDesktop(VOID
)
458 * returns or creates a handle to the desktop object
461 IntGetDesktopObjectHandle(PDESKTOP DesktopObject
)
466 ASSERT(DesktopObject
);
468 if (!ObFindHandleForObject(PsGetCurrentProcess(),
474 Status
= ObOpenObjectByPointer(DesktopObject
,
481 if(!NT_SUCCESS(Status
))
483 /* unable to create a handle */
484 DPRINT1("Unable to create a desktop handle\n");
490 DPRINT1("Got handle: %lx\n", Ret
);
496 PUSER_MESSAGE_QUEUE FASTCALL
497 IntGetFocusMessageQueue(VOID
)
499 PDESKTOP pdo
= IntGetActiveDesktop();
502 DPRINT("No active desktop\n");
505 return (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
509 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue
)
511 PUSER_MESSAGE_QUEUE Old
;
512 PDESKTOP pdo
= IntGetActiveDesktop();
515 DPRINT("No active desktop\n");
520 if(NewQueue
->Desktop
!= NULL
)
522 DPRINT("Message Queue already attached to another desktop!\n");
525 IntReferenceMessageQueue(NewQueue
);
526 (void)InterlockedExchangePointer((PVOID
*)&NewQueue
->Desktop
, pdo
);
528 Old
= (PUSER_MESSAGE_QUEUE
)InterlockedExchangePointer((PVOID
*)&pdo
->ActiveMessageQueue
, NewQueue
);
531 (void)InterlockedExchangePointer((PVOID
*)&Old
->Desktop
, 0);
532 IntDereferenceMessageQueue(Old
);
536 HWND FASTCALL
IntGetDesktopWindow(VOID
)
538 PDESKTOP pdo
= IntGetActiveDesktop();
541 DPRINT("No active desktop\n");
544 return pdo
->DesktopWindow
;
547 PWINDOW_OBJECT FASTCALL
UserGetDesktopWindow(VOID
)
549 PDESKTOP pdo
= IntGetActiveDesktop();
553 DPRINT("No active desktop\n");
557 return UserGetWindowObject(pdo
->DesktopWindow
);
560 HWND FASTCALL
IntGetMessageWindow(VOID
)
562 PDESKTOP pdo
= IntGetActiveDesktop();
566 DPRINT("No active desktop\n");
569 return pdo
->spwndMessage
->head
.h
;
572 HWND FASTCALL
IntGetCurrentThreadDesktopWindow(VOID
)
574 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
575 PDESKTOP pdo
= pti
->rpdesk
;
578 DPRINT1("Thread doesn't have a desktop\n");
581 return pdo
->DesktopWindow
;
584 BOOL FASTCALL
IntDesktopUpdatePerUserSettings(BOOL bEnable
)
588 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
591 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
593 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
594 QueryTable
[0].Name
= L
"PaintDesktopVersion";
595 QueryTable
[0].EntryContext
= &g_PaintDesktopVersion
;
597 /* Query the "PaintDesktopVersion" flag in the "Control Panel\Desktop" key */
598 Status
= RtlQueryRegistryValues(RTL_REGISTRY_USER
,
599 L
"Control Panel\\Desktop",
600 QueryTable
, NULL
, NULL
);
601 if (!NT_SUCCESS(Status
))
603 DPRINT1("RtlQueryRegistryValues failed for PaintDesktopVersion (%x)\n",
605 g_PaintDesktopVersion
= FALSE
;
609 DPRINT("PaintDesktopVersion = %d\n", g_PaintDesktopVersion
);
615 g_PaintDesktopVersion
= FALSE
;
620 /* PUBLIC FUNCTIONS ***********************************************************/
623 UserGetDesktopDC(ULONG DcType
, BOOL EmptyDC
, BOOL ValidatehWnd
)
625 PWINDOW_OBJECT DesktopObject
= 0;
628 if (DcType
== DC_TYPE_DIRECT
)
630 DesktopObject
= UserGetDesktopWindow();
631 DesktopHDC
= (HDC
)UserGetWindowDC(DesktopObject
);
636 hDev
= (HDEV
)pPrimarySurface
;
637 DesktopHDC
= IntGdiCreateDisplayDC(hDev
, DcType
, EmptyDC
);
646 PWINDOW_OBJECT Window
= NULL
;
648 Window
= UserGetDesktopWindow();
650 IntInvalidateWindows( Window
,
660 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
662 CSR_API_MESSAGE Request
;
664 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
665 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
666 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
667 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
669 return co_CsrNotify(&Request
);
673 IntHideDesktop(PDESKTOP Desktop
)
676 CSRSS_API_REQUEST Request
;
677 CSRSS_API_REPLY Reply
;
679 Request
.Type
= CSRSS_HIDE_DESKTOP
;
680 Request
.Data
.HideDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
682 return NotifyCsrss(&Request
, &Reply
);
685 PWINDOW_OBJECT DesktopWindow
;
688 DesktopWindow
= IntGetWindowObject(Desktop
->DesktopWindow
);
691 return ERROR_INVALID_WINDOW_HANDLE
;
693 DesktopWnd
= DesktopWindow
->Wnd
;
694 DesktopWnd
->style
&= ~WS_VISIBLE
;
696 return STATUS_SUCCESS
;
705 UserBuildShellHookHwndList(PDESKTOP Desktop
)
708 PSHELL_HOOK_WINDOW Current
;
711 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
712 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
715 if (!entries
) return NULL
;
717 list
= ExAllocatePool(PagedPool
, sizeof(HWND
) * (entries
+ 1)); /* alloc one extra for nullterm */
722 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
723 *cursor
++ = Current
->hWnd
;
725 *cursor
= NULL
; /* nullterm list */
732 * Send the Message to the windows registered for ShellHook
733 * notifications. The lParam contents depend on the Message. See
734 * MSDN for more details (RegisterShellHookWindow)
736 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
738 PDESKTOP Desktop
= IntGetActiveDesktop();
741 static UINT MsgType
= 0;
746 /* Too bad, this doesn't work.*/
749 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
750 MsgType
= UserRegisterWindowMessage(&Str
);
753 MsgType
= IntAddAtom(L
"SHELLHOOK");
755 DPRINT("MsgType = %x\n", MsgType
);
757 DPRINT1("LastError: %x\n", GetLastNtError());
762 DPRINT("IntShellHookNotify: No desktop!\n");
766 HwndList
= UserBuildShellHookHwndList(Desktop
);
769 HWND
* cursor
= HwndList
;
771 for (; *cursor
; cursor
++)
773 DPRINT("Sending notify\n");
774 co_IntPostOrSendMessage(*cursor
,
780 ExFreePool(HwndList
);
786 * Add the window to the ShellHookWindows list. The windows
787 * on that list get notifications that are important to shell
790 * TODO: Validate the window? I'm not sure if sending these messages to
791 * an unsuspecting application that is not your own is a nice thing to do.
793 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
795 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
796 PDESKTOP Desktop
= pti
->rpdesk
;
797 PSHELL_HOOK_WINDOW Entry
;
799 DPRINT("IntRegisterShellHookWindow\n");
801 /* First deregister the window, so we can be sure it's never twice in the
804 IntDeRegisterShellHookWindow(hWnd
);
806 Entry
= ExAllocatePoolWithTag(PagedPool
,
807 sizeof(SHELL_HOOK_WINDOW
),
815 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
821 * Remove the window from the ShellHookWindows list. The windows
822 * on that list get notifications that are important to shell
825 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
827 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
828 PDESKTOP Desktop
= pti
->rpdesk
;
829 PSHELL_HOOK_WINDOW Current
;
831 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
833 if (Current
->hWnd
== hWnd
)
835 RemoveEntryList(&Current
->ListEntry
);
845 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
847 if (Desktop
->hsectionDesktop
!= NULL
)
849 ObDereferenceObject(Desktop
->hsectionDesktop
);
850 Desktop
->hsectionDesktop
= NULL
;
853 /* SYSCALLS *******************************************************************/
856 * NtUserCreateDesktop
858 * Creates a new desktop.
865 * Name of the device.
874 * Requested type of access.
878 * If the function succeeds, the return value is a handle to the newly
879 * created desktop. If the specified desktop already exists, the function
880 * succeeds and returns a handle to the existing desktop. When you are
881 * finished using the handle, call the CloseDesktop function to close it.
882 * If the function fails, the return value is NULL.
890 POBJECT_ATTRIBUTES poa
,
891 PUNICODE_STRING lpszDesktopDevice
,
894 ACCESS_MASK dwDesiredAccess
)
896 OBJECT_ATTRIBUTES ObjectAttributes
;
897 PTHREADINFO W32Thread
;
898 PWINSTATION_OBJECT WinStaObject
;
899 PDESKTOP DesktopObject
;
900 UNICODE_STRING DesktopName
;
901 NTSTATUS Status
= STATUS_SUCCESS
;
903 CSR_API_MESSAGE Request
;
904 PVOID DesktopHeapSystemBase
= NULL
;
905 SIZE_T DesktopInfoSize
;
906 UNICODE_STRING SafeDesktopName
;
908 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
909 HWINSTA hWindowStation
= NULL
;
910 PUNICODE_STRING lpszDesktopName
= NULL
;
911 UNICODE_STRING ClassName
, WindowName
, MenuName
;
913 DECLARE_RETURN(HDESK
);
915 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
916 UserEnterExclusive();
921 sizeof(OBJECT_ATTRIBUTES
),
924 hWindowStation
= poa
->RootDirectory
;
925 lpszDesktopName
= poa
->ObjectName
;
927 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
929 Status
=_SEH2_GetExceptionCode();
933 if (! NT_SUCCESS(Status
))
935 DPRINT1("Failed reading Object Attributes from user space.\n");
936 SetLastNtError(Status
);
940 Status
= IntValidateWindowStationHandle(
943 0, /* FIXME - WINSTA_CREATEDESKTOP */
946 if (! NT_SUCCESS(Status
))
948 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
949 hWindowStation
, lpszDesktopName
);
950 SetLastNtError(Status
);
953 if(lpszDesktopName
!= NULL
)
955 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
956 if(!NT_SUCCESS(Status
))
958 SetLastNtError(Status
);
964 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
967 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
970 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
971 ObDereferenceObject(WinStaObject
);
973 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
977 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
978 ObDereferenceObject(WinStaObject
);
981 * Try to open already existing desktop
984 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
986 /* Initialize ObjectAttributes for the desktop object */
987 InitializeObjectAttributes(
994 Status
= ObOpenObjectByName(
1000 (PVOID
)&DummyContext
,
1002 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
1003 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
1005 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1009 /* Reference the desktop */
1010 Status
= ObReferenceObjectByHandle(Desktop
,
1012 ExDesktopObjectType
,
1014 (PVOID
)&DesktopObject
,
1016 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
1018 DesktopObject
->hsectionDesktop
= NULL
;
1019 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
1020 &DesktopHeapSystemBase
,
1022 if (DesktopObject
->pheapDesktop
== NULL
)
1024 ObDereferenceObject(DesktopObject
);
1025 DPRINT1("Failed to create desktop heap!\n");
1029 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1030 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1032 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1036 if (DesktopObject
->pDeskInfo
== NULL
)
1038 ObDereferenceObject(DesktopObject
);
1039 DPRINT1("Failed to create the DESKTOP structure!\n");
1043 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1046 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1047 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1048 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1049 lpszDesktopName
->Buffer
,
1050 lpszDesktopName
->Length
);
1052 // init desktop area
1053 DesktopObject
->WorkArea
.left
= 0;
1054 DesktopObject
->WorkArea
.top
= 0;
1055 DesktopObject
->WorkArea
.right
= -1;
1056 DesktopObject
->WorkArea
.bottom
= -1;
1057 IntGetDesktopWorkArea(DesktopObject
, NULL
);
1059 /* Initialize some local (to win32k) desktop state. */
1060 InitializeListHead(&DesktopObject
->PtiList
);
1061 DesktopObject
->ActiveMessageQueue
= NULL
;
1062 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1064 if (! NT_SUCCESS(Status
))
1066 DPRINT1("Failed to create desktop handle\n");
1067 SetLastNtError(Status
);
1072 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1074 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1075 * to function at the beginning of the project by ramroding the GUI into
1076 * operation and making the desktop window work from user space.
1079 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1080 Status
= CsrInsertObject(Desktop
,
1082 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1083 if (! NT_SUCCESS(Status
))
1085 DPRINT1("Failed to create desktop handle for CSRSS\n");
1087 SetLastNtError(Status
);
1091 Status
= co_CsrNotify(&Request
);
1092 if (! NT_SUCCESS(Status
))
1094 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1095 DPRINT1("Failed to notify CSRSS about new desktop\n");
1097 SetLastNtError(Status
);
1101 W32Thread
= PsGetCurrentThreadWin32Thread();
1103 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1106 Based on wine/server/window.c in get_desktop_window.
1109 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1110 ClassName
.Length
= 0;
1111 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1112 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1114 pWnd
= co_IntCreateWindowEx( 0,
1117 (WS_POPUP
|WS_CLIPCHILDREN
),
1130 DPRINT1("Failed to create Message window handle\n");
1134 DesktopObject
->spwndMessage
= pWnd
;
1140 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1148 * Opens an existing desktop.
1152 * Name of the existing desktop.
1155 * Interaction flags.
1158 * Requested type of access.
1161 * Handle to the desktop or zero on failure.
1169 PUNICODE_STRING lpszDesktopName
,
1171 ACCESS_MASK dwDesiredAccess
)
1173 OBJECT_ATTRIBUTES ObjectAttributes
;
1175 PWINSTATION_OBJECT WinStaObject
;
1176 UNICODE_STRING DesktopName
;
1177 UNICODE_STRING SafeDesktopName
;
1181 DECLARE_RETURN(HDESK
);
1183 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1184 UserEnterExclusive();
1187 * Validate the window station handle and compose the fully
1188 * qualified desktop name
1191 WinSta
= UserGetProcessWindowStation();
1192 Status
= IntValidateWindowStationHandle(
1198 if (!NT_SUCCESS(Status
))
1200 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1201 SetLastNtError(Status
);
1205 if(lpszDesktopName
!= NULL
)
1207 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1208 if(!NT_SUCCESS(Status
))
1210 SetLastNtError(Status
);
1216 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1219 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1222 if (lpszDesktopName
)
1223 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1224 ObDereferenceObject(WinStaObject
);
1229 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1234 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1236 /* Initialize ObjectAttributes for the desktop object */
1237 InitializeObjectAttributes(
1244 Status
= ObOpenObjectByName(
1246 ExDesktopObjectType
,
1253 if (!NT_SUCCESS(Status
))
1255 SetLastNtError(Status
);
1256 ExFreePool(DesktopName
.Buffer
);
1260 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1261 ExFreePool(DesktopName
.Buffer
);
1266 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1272 * NtUserOpenInputDesktop
1274 * Opens the input (interactive) desktop.
1278 * Interaction flags.
1281 * Inheritance option.
1284 * Requested type of access.
1287 * Handle to the input desktop or zero on failure.
1294 NtUserOpenInputDesktop(
1297 ACCESS_MASK dwDesiredAccess
)
1302 DECLARE_RETURN(HDESK
);
1304 DPRINT("Enter NtUserOpenInputDesktop\n");
1305 UserEnterExclusive();
1307 DPRINT("About to open input desktop\n");
1309 /* Get a pointer to the desktop object */
1311 Status
= IntValidateDesktopHandle(
1317 if (!NT_SUCCESS(Status
))
1319 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1323 /* Create a new handle to the object */
1325 Status
= ObOpenObjectByPointer(
1330 ExDesktopObjectType
,
1334 ObDereferenceObject(Object
);
1336 if (NT_SUCCESS(Status
))
1338 DPRINT("Successfully opened input desktop\n");
1339 RETURN((HDESK
)Desktop
);
1342 SetLastNtError(Status
);
1346 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1352 * NtUserCloseDesktop
1354 * Closes a desktop handle.
1358 * Handle to the desktop.
1364 * The desktop handle can be created with NtUserCreateDesktop or
1365 * NtUserOpenDesktop. This function will fail if any thread in the calling
1366 * process is using the specified desktop handle or if the handle refers
1367 * to the initial desktop of the calling process.
1374 NtUserCloseDesktop(HDESK hDesktop
)
1378 DECLARE_RETURN(BOOL
);
1380 DPRINT("Enter NtUserCloseDesktop\n");
1381 UserEnterExclusive();
1383 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1385 Status
= IntValidateDesktopHandle(
1391 if (!NT_SUCCESS(Status
))
1393 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1397 ObDereferenceObject(Object
);
1399 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1401 Status
= ZwClose(hDesktop
);
1402 if (!NT_SUCCESS(Status
))
1404 SetLastNtError(Status
);
1411 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1420 * NtUserPaintDesktop
1422 * The NtUserPaintDesktop function fills the clipping region in the
1423 * specified device context with the desktop pattern or wallpaper. The
1424 * function is provided primarily for shell desktops.
1428 * Handle to the device context.
1435 NtUserPaintDesktop(HDC hDC
)
1438 HBRUSH DesktopBrush
, PreviousBrush
;
1440 BOOL doPatBlt
= TRUE
;
1441 PWINDOW_OBJECT WndDesktop
;
1446 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1447 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1448 DECLARE_RETURN(BOOL
);
1450 UserEnterExclusive();
1451 DPRINT("Enter NtUserPaintDesktop\n");
1453 GdiGetClipBox(hDC
, &Rect
);
1455 hWndDesktop
= IntGetDesktopWindow();
1457 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1463 DesktopBrush
= (HBRUSH
)UserGetClassLongPtr(WndDesktop
->Wnd
->pcls
, GCL_HBRBACKGROUND
, FALSE
);
1467 * Paint desktop background
1470 if (WinSta
->hbmWallpaper
!= NULL
)
1472 PWINDOW_OBJECT DeskWin
;
1474 DeskWin
= UserGetWindowObject(hWndDesktop
);
1482 sz
.cx
= DeskWin
->Wnd
->rcWindow
.right
- DeskWin
->Wnd
->rcWindow
.left
;
1483 sz
.cy
= DeskWin
->Wnd
->rcWindow
.bottom
- DeskWin
->Wnd
->rcWindow
.top
;
1485 if (WinSta
->WallpaperMode
== wmStretch
||
1486 WinSta
->WallpaperMode
== wmTile
)
1493 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1494 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1495 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1498 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1499 if(hWallpaperDC
!= NULL
)
1503 /* fill in the area that the bitmap is not going to cover */
1506 /* FIXME - clip out the bitmap
1507 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1508 once we support DSTINVERT */
1509 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1510 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1511 NtGdiSelectBrush(hDC
, PreviousBrush
);
1514 /*Do not fill the background after it is painted no matter the size of the picture */
1517 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1519 if (WinSta
->WallpaperMode
== wmStretch
)
1521 if(Rect
.right
&& Rect
.bottom
)
1522 NtGdiStretchBlt(hDC
,
1530 WinSta
->cxWallpaper
,
1531 WinSta
->cyWallpaper
,
1536 else if (WinSta
->WallpaperMode
== wmTile
)
1538 /* paint the bitmap across the screen then down */
1539 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1541 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1546 WinSta
->cxWallpaper
,
1547 WinSta
->cyWallpaper
,
1562 WinSta
->cxWallpaper
,
1563 WinSta
->cyWallpaper
,
1571 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1572 NtGdiDeleteObjectApp(hWallpaperDC
);
1577 /* Back ground is set to none, clear the screen */
1580 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1581 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1582 NtGdiSelectBrush(hDC
, PreviousBrush
);
1586 * Display system version on the desktop background
1589 if (g_PaintDesktopVersion
)
1591 static WCHAR s_wszVersion
[256] = {0};
1596 len
= wcslen(s_wszVersion
);
1600 len
= GetSystemVersionString(s_wszVersion
);
1605 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1607 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1608 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1611 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1612 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1613 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1615 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1617 IntGdiSetBkMode(hDC
, mode_old
);
1618 IntGdiSetTextAlign(hDC
, align_old
);
1619 IntGdiSetTextColor(hDC
, color_old
);
1626 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1633 * NtUserSwitchDesktop
1635 * Sets the current input (interactive) desktop.
1639 * Handle to desktop.
1649 NtUserSwitchDesktop(HDESK hDesktop
)
1651 PDESKTOP DesktopObject
;
1653 DECLARE_RETURN(BOOL
);
1655 UserEnterExclusive();
1656 DPRINT("Enter NtUserSwitchDesktop\n");
1658 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1660 Status
= IntValidateDesktopHandle(
1666 if (!NT_SUCCESS(Status
))
1668 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1673 * Don't allow applications switch the desktop if it's locked, unless the caller
1674 * is the logon application itself
1676 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1677 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1679 ObDereferenceObject(DesktopObject
);
1680 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1684 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1686 ObDereferenceObject(DesktopObject
);
1687 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1691 /* FIXME: Fail if the process is associated with a secured
1692 desktop such as Winlogon or Screen-Saver */
1693 /* FIXME: Connect to input device */
1695 /* Set the active desktop in the desktop's window station. */
1696 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1698 /* Set the global state. */
1699 InputDesktop
= DesktopObject
;
1700 InputDesktopHandle
= hDesktop
;
1702 ObDereferenceObject(DesktopObject
);
1707 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1713 * NtUserResolveDesktopForWOW
1720 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1727 * NtUserGetThreadDesktop
1734 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1738 PDESKTOP DesktopObject
;
1739 HDESK Ret
, hThreadDesktop
;
1740 OBJECT_HANDLE_INFORMATION HandleInformation
;
1741 DECLARE_RETURN(HDESK
);
1743 UserEnterExclusive();
1744 DPRINT("Enter NtUserGetThreadDesktop\n");
1748 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1752 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1753 if(!NT_SUCCESS(Status
))
1755 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1759 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1761 /* just return the handle, we queried the desktop handle of a thread running
1762 in the same context */
1763 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1764 ObDereferenceObject(Thread
);
1768 /* get the desktop handle and the desktop of the thread */
1769 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1770 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1772 ObDereferenceObject(Thread
);
1773 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1777 /* we could just use DesktopObject instead of looking up the handle, but latter
1778 may be a bit safer (e.g. when the desktop is being destroyed */
1779 /* switch into the context of the thread we're trying to get the desktop from,
1780 so we can use the handle */
1781 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1782 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1784 ExDesktopObjectType
,
1786 (PVOID
*)&DesktopObject
,
1787 &HandleInformation
);
1790 /* the handle couldn't be found, there's nothing to get... */
1791 if(!NT_SUCCESS(Status
))
1793 ObDereferenceObject(Thread
);
1797 /* lookup our handle table if we can find a handle to the desktop object,
1798 if not, create one */
1799 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1801 /* all done, we got a valid handle to the desktop */
1802 ObDereferenceObject(DesktopObject
);
1803 ObDereferenceObject(Thread
);
1807 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1813 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1816 PPROCESSINFO CurrentWin32Process
;
1817 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1818 NTSTATUS Status
= STATUS_SUCCESS
;
1822 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1823 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1825 /* unmap if we're the last thread using the desktop */
1826 HeapMapping
= *PrevLink
;
1827 while (HeapMapping
!= NULL
)
1829 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1831 if (--HeapMapping
->Count
== 0)
1833 *PrevLink
= HeapMapping
->Next
;
1835 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1836 HeapMapping
->UserMapping
);
1838 ObDereferenceObject(DesktopObject
);
1840 UserHeapFree(HeapMapping
);
1845 PrevLink
= &HeapMapping
->Next
;
1846 HeapMapping
= HeapMapping
->Next
;
1849 ti
= GetW32ThreadInfo();
1852 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1854 GetWin32ClientInfo()->ulClientDelta
= 0;
1860 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1863 PPROCESSINFO CurrentWin32Process
;
1864 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1865 PVOID UserBase
= NULL
;
1866 SIZE_T ViewSize
= 0;
1867 LARGE_INTEGER Offset
;
1870 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1871 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1873 /* find out if another thread already mapped the desktop heap */
1874 HeapMapping
= *PrevLink
;
1875 while (HeapMapping
!= NULL
)
1877 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1879 HeapMapping
->Count
++;
1880 return STATUS_SUCCESS
;
1883 PrevLink
= &HeapMapping
->Next
;
1884 HeapMapping
= HeapMapping
->Next
;
1887 /* we're the first, map the heap */
1888 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1889 Offset
.QuadPart
= 0;
1890 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1891 PsGetCurrentProcess(),
1899 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1900 if (!NT_SUCCESS(Status
))
1902 DPRINT1("Failed to map desktop\n");
1906 /* add the mapping */
1907 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1908 if (HeapMapping
== NULL
)
1910 MmUnmapViewOfSection(PsGetCurrentProcess(),
1912 DPRINT1("UserHeapAlloc() failed!\n");
1913 return STATUS_NO_MEMORY
;
1916 HeapMapping
->Next
= NULL
;
1917 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1918 HeapMapping
->UserMapping
= UserBase
;
1919 HeapMapping
->Limit
= ViewSize
;
1920 HeapMapping
->Count
= 1;
1921 *PrevLink
= HeapMapping
;
1923 ObReferenceObject(DesktopObject
);
1925 /* create a W32THREADINFO structure if not already done, or update it */
1926 ti
= GetW32ThreadInfo();
1927 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1930 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1932 GetWin32ClientInfo()->pDeskInfo
=
1933 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1934 GetWin32ClientInfo()->ulClientDelta
);
1938 return STATUS_SUCCESS
;
1942 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1943 IN BOOL FreeOnFailure
)
1945 PDESKTOP OldDesktop
;
1946 PTHREADINFO W32Thread
;
1950 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1951 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1952 W32Thread
= PsGetCurrentThreadWin32Thread();
1954 if (W32Thread
->rpdesk
!= DesktopObject
)
1956 OldDesktop
= W32Thread
->rpdesk
;
1958 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1960 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1961 SetLastWin32Error(ERROR_BUSY
);
1965 W32Thread
->rpdesk
= DesktopObject
;
1967 if (MapHeap
&& DesktopObject
!= NULL
)
1969 Status
= IntMapDesktopView(DesktopObject
);
1970 if (!NT_SUCCESS(Status
))
1972 SetLastNtError(Status
);
1977 /* Hack for system threads */
1980 PCLIENTINFO pci
= GetWin32ClientInfo();
1981 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1984 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1988 if (OldDesktop
!= NULL
&&
1989 !IntCheckProcessDesktopClasses(OldDesktop
,
1992 DPRINT1("Failed to move process classes to shared heap!\n");
1994 /* failed to move desktop classes to the shared heap,
1995 unmap the view and return the error */
1996 if (MapHeap
&& DesktopObject
!= NULL
)
1997 IntUnmapDesktopView(DesktopObject
);
2002 /* Remove the thread from the old desktop's list */
2003 RemoveEntryList(&W32Thread
->PtiLink
);
2005 if (DesktopObject
!= NULL
)
2007 ObReferenceObject(DesktopObject
);
2008 /* Insert into new desktop's list */
2009 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
2012 if (OldDesktop
!= NULL
)
2016 IntUnmapDesktopView(OldDesktop
);
2019 ObDereferenceObject(OldDesktop
);
2027 * NtUserSetThreadDesktop
2034 NtUserSetThreadDesktop(HDESK hDesktop
)
2036 PDESKTOP DesktopObject
;
2038 DECLARE_RETURN(BOOL
);
2040 UserEnterExclusive();
2041 DPRINT("Enter NtUserSetThreadDesktop\n");
2043 /* Validate the new desktop. */
2044 Status
= IntValidateDesktopHandle(
2050 if (!NT_SUCCESS(Status
))
2052 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2056 /* FIXME: Should check here to see if the thread has any windows. */
2058 if (!IntSetThreadDesktop(DesktopObject
,
2067 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);