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 UserEnterExclusive();
621 Window
= UserGetDesktopWindow();
623 IntInvalidateWindows( Window
,
634 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
636 CSR_API_MESSAGE Request
;
638 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
639 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
640 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
641 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
643 return co_CsrNotify(&Request
);
647 IntHideDesktop(PDESKTOP Desktop
)
650 CSRSS_API_REQUEST Request
;
651 CSRSS_API_REPLY Reply
;
653 Request
.Type
= CSRSS_HIDE_DESKTOP
;
654 Request
.Data
.HideDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
656 return NotifyCsrss(&Request
, &Reply
);
661 DesktopWnd
= IntGetWindowObject(Desktop
->DesktopWindow
);
664 return ERROR_INVALID_WINDOW_HANDLE
;
666 DesktopWnd
->style
&= ~WS_VISIBLE
;
668 return STATUS_SUCCESS
;
677 UserBuildShellHookHwndList(PDESKTOP Desktop
)
680 PSHELL_HOOK_WINDOW Current
;
683 /* fixme: if we save nb elements in desktop, we dont have to loop to find nb entries */
684 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
687 if (!entries
) return NULL
;
689 list
= ExAllocatePoolWithTag(PagedPool
, sizeof(HWND
) * (entries
+ 1), USERTAG_WINDOWLIST
); /* alloc one extra for nullterm */
694 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
695 *cursor
++ = Current
->hWnd
;
697 *cursor
= NULL
; /* nullterm list */
704 * Send the Message to the windows registered for ShellHook
705 * notifications. The lParam contents depend on the Message. See
706 * MSDN for more details (RegisterShellHookWindow)
708 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
710 PDESKTOP Desktop
= IntGetActiveDesktop();
713 static UINT MsgType
= 0;
718 /* Too bad, this doesn't work.*/
721 RtlInitUnicodeString(&Str
, L
"SHELLHOOK");
722 MsgType
= UserRegisterWindowMessage(&Str
);
725 MsgType
= IntAddAtom(L
"SHELLHOOK");
727 DPRINT("MsgType = %x\n", MsgType
);
729 DPRINT1("LastError: %x\n", GetLastNtError());
734 DPRINT("IntShellHookNotify: No desktop!\n");
738 HwndList
= UserBuildShellHookHwndList(Desktop
);
741 HWND
* cursor
= HwndList
;
743 for (; *cursor
; cursor
++)
745 DPRINT("Sending notify\n");
746 co_IntPostOrSendMessage(*cursor
,
752 ExFreePool(HwndList
);
758 * Add the window to the ShellHookWindows list. The windows
759 * on that list get notifications that are important to shell
762 * TODO: Validate the window? I'm not sure if sending these messages to
763 * an unsuspecting application that is not your own is a nice thing to do.
765 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
767 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
768 PDESKTOP Desktop
= pti
->rpdesk
;
769 PSHELL_HOOK_WINDOW Entry
;
771 DPRINT("IntRegisterShellHookWindow\n");
773 /* First deregister the window, so we can be sure it's never twice in the
776 IntDeRegisterShellHookWindow(hWnd
);
778 Entry
= ExAllocatePoolWithTag(PagedPool
,
779 sizeof(SHELL_HOOK_WINDOW
),
787 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
793 * Remove the window from the ShellHookWindows list. The windows
794 * on that list get notifications that are important to shell
797 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
799 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
800 PDESKTOP Desktop
= pti
->rpdesk
;
801 PSHELL_HOOK_WINDOW Current
;
803 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
805 if (Current
->hWnd
== hWnd
)
807 RemoveEntryList(&Current
->ListEntry
);
817 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
819 if (Desktop
->hsectionDesktop
!= NULL
)
821 ObDereferenceObject(Desktop
->hsectionDesktop
);
822 Desktop
->hsectionDesktop
= NULL
;
825 /* SYSCALLS *******************************************************************/
828 * NtUserCreateDesktop
830 * Creates a new desktop.
837 * Name of the device.
846 * Requested type of access.
850 * If the function succeeds, the return value is a handle to the newly
851 * created desktop. If the specified desktop already exists, the function
852 * succeeds and returns a handle to the existing desktop. When you are
853 * finished using the handle, call the CloseDesktop function to close it.
854 * If the function fails, the return value is NULL.
862 POBJECT_ATTRIBUTES poa
,
863 PUNICODE_STRING lpszDesktopDevice
,
866 ACCESS_MASK dwDesiredAccess
)
868 OBJECT_ATTRIBUTES ObjectAttributes
;
869 PTHREADINFO W32Thread
;
870 PWINSTATION_OBJECT WinStaObject
;
871 PDESKTOP DesktopObject
;
872 UNICODE_STRING DesktopName
;
873 NTSTATUS Status
= STATUS_SUCCESS
;
875 CSR_API_MESSAGE Request
;
876 PVOID DesktopHeapSystemBase
= NULL
;
877 SIZE_T DesktopInfoSize
;
878 UNICODE_STRING SafeDesktopName
;
880 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
881 HWINSTA hWindowStation
= NULL
;
882 PUNICODE_STRING lpszDesktopName
= NULL
;
883 UNICODE_STRING ClassName
, MenuName
;
884 LARGE_STRING WindowName
;
887 DECLARE_RETURN(HDESK
);
889 DPRINT("Enter NtUserCreateDesktop: %wZ\n", lpszDesktopName
);
890 UserEnterExclusive();
895 sizeof(OBJECT_ATTRIBUTES
),
898 hWindowStation
= poa
->RootDirectory
;
899 lpszDesktopName
= poa
->ObjectName
;
901 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
903 Status
=_SEH2_GetExceptionCode();
907 if (! NT_SUCCESS(Status
))
909 DPRINT1("Failed reading Object Attributes from user space.\n");
910 SetLastNtError(Status
);
914 Status
= IntValidateWindowStationHandle(
917 0, /* FIXME - WINSTA_CREATEDESKTOP */
920 if (! NT_SUCCESS(Status
))
922 DPRINT1("Failed validation of window station handle (0x%X), cannot create desktop %wZ\n",
923 hWindowStation
, lpszDesktopName
);
924 SetLastNtError(Status
);
927 if(lpszDesktopName
!= NULL
)
929 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
930 if(!NT_SUCCESS(Status
))
932 SetLastNtError(Status
);
938 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
941 if (! IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
944 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
945 ObDereferenceObject(WinStaObject
);
947 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
951 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
952 ObDereferenceObject(WinStaObject
);
955 * Try to open already existing desktop
958 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
960 /* Initialize ObjectAttributes for the desktop object */
961 InitializeObjectAttributes(
968 Status
= ObOpenObjectByName(
974 (PVOID
)&DummyContext
,
976 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
977 if (Status
== STATUS_OBJECT_NAME_EXISTS
)
979 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
983 /* Reference the desktop */
984 Status
= ObReferenceObjectByHandle(Desktop
,
988 (PVOID
)&DesktopObject
,
990 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
992 DesktopObject
->hsectionDesktop
= NULL
;
993 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
994 &DesktopHeapSystemBase
,
996 if (DesktopObject
->pheapDesktop
== NULL
)
998 ObDereferenceObject(DesktopObject
);
999 DPRINT1("Failed to create desktop heap!\n");
1003 DesktopInfoSize
= FIELD_OFFSET(DESKTOPINFO
,
1004 szDesktopName
[(lpszDesktopName
->Length
/ sizeof(WCHAR
)) + 1]);
1006 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1010 if (DesktopObject
->pDeskInfo
== NULL
)
1012 ObDereferenceObject(DesktopObject
);
1013 DPRINT1("Failed to create the DESKTOP structure!\n");
1017 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1020 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1021 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1022 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1023 lpszDesktopName
->Buffer
,
1024 lpszDesktopName
->Length
);
1026 /* Initialize some local (to win32k) desktop state. */
1027 InitializeListHead(&DesktopObject
->PtiList
);
1028 DesktopObject
->ActiveMessageQueue
= NULL
;
1029 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1031 if (! NT_SUCCESS(Status
))
1033 DPRINT1("Failed to create desktop handle\n");
1034 SetLastNtError(Status
);
1039 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Window.
1041 * Honestly, I believe this is a cleverly written hack that allowed ReactOS
1042 * to function at the beginning of the project by ramroding the GUI into
1043 * operation and making the desktop window work from user space.
1046 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1047 Status
= CsrInsertObject(Desktop
,
1049 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1050 if (! NT_SUCCESS(Status
))
1052 DPRINT1("Failed to create desktop handle for CSRSS\n");
1054 SetLastNtError(Status
);
1058 Status
= co_CsrNotify(&Request
);
1059 if (! NT_SUCCESS(Status
))
1061 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1062 DPRINT1("Failed to notify CSRSS about new desktop\n");
1064 SetLastNtError(Status
);
1068 W32Thread
= PsGetCurrentThreadWin32Thread();
1070 if (!W32Thread
->rpdesk
) IntSetThreadDesktop(DesktopObject
,FALSE
);
1073 Based on wine/server/window.c in get_desktop_window.
1076 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1077 ClassName
.Length
= 0;
1078 RtlZeroMemory(&MenuName
, sizeof(MenuName
));
1079 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1081 RtlZeroMemory(&Cs
, sizeof(Cs
));
1082 Cs
.cx
= Cs
.cy
= 100;
1083 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1084 Cs
.hInstance
= hModClient
;
1085 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1086 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1088 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
);
1091 DPRINT1("Failed to create Message window handle\n");
1095 DesktopObject
->spwndMessage
= pWnd
;
1101 DPRINT("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1109 * Opens an existing desktop.
1113 * Name of the existing desktop.
1116 * Interaction flags.
1119 * Requested type of access.
1122 * Handle to the desktop or zero on failure.
1130 PUNICODE_STRING lpszDesktopName
,
1132 ACCESS_MASK dwDesiredAccess
)
1134 OBJECT_ATTRIBUTES ObjectAttributes
;
1136 PWINSTATION_OBJECT WinStaObject
;
1137 UNICODE_STRING DesktopName
;
1138 UNICODE_STRING SafeDesktopName
;
1142 DECLARE_RETURN(HDESK
);
1144 DPRINT("Enter NtUserOpenDesktop: %wZ\n", lpszDesktopName
);
1145 UserEnterExclusive();
1148 * Validate the window station handle and compose the fully
1149 * qualified desktop name
1152 WinSta
= UserGetProcessWindowStation();
1153 Status
= IntValidateWindowStationHandle(
1159 if (!NT_SUCCESS(Status
))
1161 DPRINT1("Failed validation of window station handle (0x%X)\n", WinSta
);
1162 SetLastNtError(Status
);
1166 if(lpszDesktopName
!= NULL
)
1168 Status
= IntSafeCopyUnicodeString(&SafeDesktopName
, lpszDesktopName
);
1169 if(!NT_SUCCESS(Status
))
1171 SetLastNtError(Status
);
1177 RtlInitUnicodeString(&SafeDesktopName
, NULL
);
1180 Result
= IntGetFullWindowStationName(&DesktopName
, &WinStaObject
->Name
,
1183 if (lpszDesktopName
)
1184 ExFreePoolWithTag(SafeDesktopName
.Buffer
, TAG_STRING
);
1185 ObDereferenceObject(WinStaObject
);
1190 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1195 DPRINT("Trying to open desktop (%wZ)\n", &DesktopName
);
1197 /* Initialize ObjectAttributes for the desktop object */
1198 InitializeObjectAttributes(
1205 Status
= ObOpenObjectByName(
1207 ExDesktopObjectType
,
1214 if (!NT_SUCCESS(Status
))
1216 SetLastNtError(Status
);
1217 ExFreePool(DesktopName
.Buffer
);
1221 DPRINT("Successfully opened desktop (%wZ)\n", &DesktopName
);
1222 ExFreePool(DesktopName
.Buffer
);
1227 DPRINT("Leave NtUserOpenDesktop, ret=%i\n",_ret_
);
1233 * NtUserOpenInputDesktop
1235 * Opens the input (interactive) desktop.
1239 * Interaction flags.
1242 * Inheritance option.
1245 * Requested type of access.
1248 * Handle to the input desktop or zero on failure.
1255 NtUserOpenInputDesktop(
1258 ACCESS_MASK dwDesiredAccess
)
1263 DECLARE_RETURN(HDESK
);
1265 DPRINT("Enter NtUserOpenInputDesktop\n");
1266 UserEnterExclusive();
1268 DPRINT("About to open input desktop\n");
1270 /* Get a pointer to the desktop object */
1272 Status
= IntValidateDesktopHandle(
1278 if (!NT_SUCCESS(Status
))
1280 DPRINT("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1284 /* Create a new handle to the object */
1286 Status
= ObOpenObjectByPointer(
1291 ExDesktopObjectType
,
1295 ObDereferenceObject(Object
);
1297 if (NT_SUCCESS(Status
))
1299 DPRINT("Successfully opened input desktop\n");
1300 RETURN((HDESK
)Desktop
);
1303 SetLastNtError(Status
);
1307 DPRINT("Leave NtUserOpenInputDesktop, ret=%i\n",_ret_
);
1313 * NtUserCloseDesktop
1315 * Closes a desktop handle.
1319 * Handle to the desktop.
1325 * The desktop handle can be created with NtUserCreateDesktop or
1326 * NtUserOpenDesktop. This function will fail if any thread in the calling
1327 * process is using the specified desktop handle or if the handle refers
1328 * to the initial desktop of the calling process.
1335 NtUserCloseDesktop(HDESK hDesktop
)
1339 DECLARE_RETURN(BOOL
);
1341 DPRINT("Enter NtUserCloseDesktop\n");
1342 UserEnterExclusive();
1344 DPRINT("About to close desktop handle (0x%X)\n", hDesktop
);
1346 Status
= IntValidateDesktopHandle(
1352 if (!NT_SUCCESS(Status
))
1354 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1358 ObDereferenceObject(Object
);
1360 DPRINT("Closing desktop handle (0x%X)\n", hDesktop
);
1362 Status
= ZwClose(hDesktop
);
1363 if (!NT_SUCCESS(Status
))
1365 SetLastNtError(Status
);
1372 DPRINT("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1381 * NtUserPaintDesktop
1383 * The NtUserPaintDesktop function fills the clipping region in the
1384 * specified device context with the desktop pattern or wallpaper. The
1385 * function is provided primarily for shell desktops.
1389 * Handle to the device context.
1396 NtUserPaintDesktop(HDC hDC
)
1399 HBRUSH DesktopBrush
, PreviousBrush
;
1401 BOOL doPatBlt
= TRUE
;
1407 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
1408 PWINSTATION_OBJECT WinSta
= pti
->rpdesk
->rpwinstaParent
;
1409 DECLARE_RETURN(BOOL
);
1411 UserEnterExclusive();
1412 DPRINT("Enter NtUserPaintDesktop\n");
1414 GdiGetClipBox(hDC
, &Rect
);
1416 hWndDesktop
= IntGetDesktopWindow();
1418 WndDesktop
= UserGetWindowObject(hWndDesktop
);
1424 DesktopBrush
= (HBRUSH
)WndDesktop
->pcls
->hbrBackground
;
1428 * Paint desktop background
1431 if (WinSta
->hbmWallpaper
!= NULL
)
1435 DeskWin
= UserGetWindowObject(hWndDesktop
);
1443 sz
.cx
= DeskWin
->rcWindow
.right
- DeskWin
->rcWindow
.left
;
1444 sz
.cy
= DeskWin
->rcWindow
.bottom
- DeskWin
->rcWindow
.top
;
1446 if (WinSta
->WallpaperMode
== wmStretch
||
1447 WinSta
->WallpaperMode
== wmTile
)
1454 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
1455 x
= (sz
.cx
/ 2) - (WinSta
->cxWallpaper
/ 2);
1456 y
= (sz
.cy
/ 2) - (WinSta
->cyWallpaper
/ 2);
1459 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
1460 if(hWallpaperDC
!= NULL
)
1464 /* fill in the area that the bitmap is not going to cover */
1467 /* FIXME - clip out the bitmap
1468 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
1469 once we support DSTINVERT */
1470 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1471 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1472 NtGdiSelectBrush(hDC
, PreviousBrush
);
1475 /*Do not fill the background after it is painted no matter the size of the picture */
1478 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, WinSta
->hbmWallpaper
);
1480 if (WinSta
->WallpaperMode
== wmStretch
)
1482 if(Rect
.right
&& Rect
.bottom
)
1483 NtGdiStretchBlt(hDC
,
1491 WinSta
->cxWallpaper
,
1492 WinSta
->cyWallpaper
,
1497 else if (WinSta
->WallpaperMode
== wmTile
)
1499 /* paint the bitmap across the screen then down */
1500 for(y
= 0; y
< Rect
.bottom
; y
+= WinSta
->cyWallpaper
)
1502 for(x
= 0; x
< Rect
.right
; x
+= WinSta
->cxWallpaper
)
1507 WinSta
->cxWallpaper
,
1508 WinSta
->cyWallpaper
,
1523 WinSta
->cxWallpaper
,
1524 WinSta
->cyWallpaper
,
1532 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
1533 NtGdiDeleteObjectApp(hWallpaperDC
);
1538 /* Back ground is set to none, clear the screen */
1541 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
1542 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
1543 NtGdiSelectBrush(hDC
, PreviousBrush
);
1547 * Display system version on the desktop background
1550 if (g_PaintDesktopVersion
)
1552 static WCHAR s_wszVersion
[256] = {0};
1557 len
= wcslen(s_wszVersion
);
1561 len
= GetSystemVersionString(s_wszVersion
);
1566 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
1568 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
1569 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
1572 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
1573 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
1574 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
1576 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
1578 IntGdiSetBkMode(hDC
, mode_old
);
1579 IntGdiSetTextAlign(hDC
, align_old
);
1580 IntGdiSetTextColor(hDC
, color_old
);
1587 DPRINT("Leave NtUserPaintDesktop, ret=%i\n",_ret_
);
1594 * NtUserSwitchDesktop
1596 * Sets the current input (interactive) desktop.
1600 * Handle to desktop.
1610 NtUserSwitchDesktop(HDESK hDesktop
)
1612 PDESKTOP DesktopObject
;
1614 DECLARE_RETURN(BOOL
);
1616 UserEnterExclusive();
1617 DPRINT("Enter NtUserSwitchDesktop\n");
1619 DPRINT("About to switch desktop (0x%X)\n", hDesktop
);
1621 Status
= IntValidateDesktopHandle(
1627 if (!NT_SUCCESS(Status
))
1629 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1634 * Don't allow applications switch the desktop if it's locked, unless the caller
1635 * is the logon application itself
1637 if((DesktopObject
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1638 LogonProcess
!= NULL
&& LogonProcess
!= PsGetCurrentProcessWin32Process())
1640 ObDereferenceObject(DesktopObject
);
1641 DPRINT1("Switching desktop 0x%x denied because the work station is locked!\n", hDesktop
);
1645 if(DesktopObject
->rpwinstaParent
!= InputWindowStation
)
1647 ObDereferenceObject(DesktopObject
);
1648 DPRINT1("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hDesktop
);
1652 /* FIXME: Fail if the process is associated with a secured
1653 desktop such as Winlogon or Screen-Saver */
1654 /* FIXME: Connect to input device */
1656 /* Set the active desktop in the desktop's window station. */
1657 InputWindowStation
->ActiveDesktop
= DesktopObject
;
1659 /* Set the global state. */
1660 InputDesktop
= DesktopObject
;
1661 InputDesktopHandle
= hDesktop
;
1663 ObDereferenceObject(DesktopObject
);
1668 DPRINT("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1674 * NtUserResolveDesktopForWOW
1681 NtUserResolveDesktopForWOW(DWORD Unknown0
)
1688 * NtUserGetThreadDesktop
1695 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1699 PDESKTOP DesktopObject
;
1700 HDESK Ret
, hThreadDesktop
;
1701 OBJECT_HANDLE_INFORMATION HandleInformation
;
1702 DECLARE_RETURN(HDESK
);
1704 UserEnterExclusive();
1705 DPRINT("Enter NtUserGetThreadDesktop\n");
1709 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1713 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1714 if(!NT_SUCCESS(Status
))
1716 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1720 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1722 /* just return the handle, we queried the desktop handle of a thread running
1723 in the same context */
1724 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1725 ObDereferenceObject(Thread
);
1729 /* get the desktop handle and the desktop of the thread */
1730 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1731 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1733 ObDereferenceObject(Thread
);
1734 DPRINT1("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1738 /* we could just use DesktopObject instead of looking up the handle, but latter
1739 may be a bit safer (e.g. when the desktop is being destroyed */
1740 /* switch into the context of the thread we're trying to get the desktop from,
1741 so we can use the handle */
1742 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1743 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1745 ExDesktopObjectType
,
1747 (PVOID
*)&DesktopObject
,
1748 &HandleInformation
);
1751 /* the handle couldn't be found, there's nothing to get... */
1752 if(!NT_SUCCESS(Status
))
1754 ObDereferenceObject(Thread
);
1758 /* lookup our handle table if we can find a handle to the desktop object,
1759 if not, create one */
1760 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1762 /* all done, we got a valid handle to the desktop */
1763 ObDereferenceObject(DesktopObject
);
1764 ObDereferenceObject(Thread
);
1768 DPRINT("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1774 IntUnmapDesktopView(IN PDESKTOP DesktopObject
)
1777 PPROCESSINFO CurrentWin32Process
;
1778 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1779 NTSTATUS Status
= STATUS_SUCCESS
;
1783 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1784 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1786 /* unmap if we're the last thread using the desktop */
1787 HeapMapping
= *PrevLink
;
1788 while (HeapMapping
!= NULL
)
1790 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1792 if (--HeapMapping
->Count
== 0)
1794 *PrevLink
= HeapMapping
->Next
;
1796 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1797 HeapMapping
->UserMapping
);
1799 ObDereferenceObject(DesktopObject
);
1801 UserHeapFree(HeapMapping
);
1806 PrevLink
= &HeapMapping
->Next
;
1807 HeapMapping
= HeapMapping
->Next
;
1810 ti
= GetW32ThreadInfo();
1813 GetWin32ClientInfo()->pDeskInfo
= NULL
;
1815 GetWin32ClientInfo()->ulClientDelta
= 0;
1821 IntMapDesktopView(IN PDESKTOP DesktopObject
)
1824 PPROCESSINFO CurrentWin32Process
;
1825 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1826 PVOID UserBase
= NULL
;
1827 SIZE_T ViewSize
= 0;
1828 LARGE_INTEGER Offset
;
1831 CurrentWin32Process
= PsGetCurrentProcessWin32Process();
1832 PrevLink
= &CurrentWin32Process
->HeapMappings
.Next
;
1834 /* find out if another thread already mapped the desktop heap */
1835 HeapMapping
= *PrevLink
;
1836 while (HeapMapping
!= NULL
)
1838 if (HeapMapping
->KernelMapping
== (PVOID
)DesktopObject
->pheapDesktop
)
1840 HeapMapping
->Count
++;
1841 return STATUS_SUCCESS
;
1844 PrevLink
= &HeapMapping
->Next
;
1845 HeapMapping
= HeapMapping
->Next
;
1848 /* we're the first, map the heap */
1849 DPRINT("Noone mapped the desktop heap %p yet, so - map it!\n", DesktopObject
->pheapDesktop
);
1850 Offset
.QuadPart
= 0;
1851 Status
= MmMapViewOfSection(DesktopObject
->hsectionDesktop
,
1852 PsGetCurrentProcess(),
1860 PAGE_EXECUTE_READ
); /* would prefer PAGE_READONLY, but thanks to RTL heaps... */
1861 if (!NT_SUCCESS(Status
))
1863 DPRINT1("Failed to map desktop\n");
1867 /* add the mapping */
1868 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1869 if (HeapMapping
== NULL
)
1871 MmUnmapViewOfSection(PsGetCurrentProcess(),
1873 DPRINT1("UserHeapAlloc() failed!\n");
1874 return STATUS_NO_MEMORY
;
1877 HeapMapping
->Next
= NULL
;
1878 HeapMapping
->KernelMapping
= (PVOID
)DesktopObject
->pheapDesktop
;
1879 HeapMapping
->UserMapping
= UserBase
;
1880 HeapMapping
->Limit
= ViewSize
;
1881 HeapMapping
->Count
= 1;
1882 *PrevLink
= HeapMapping
;
1884 ObReferenceObject(DesktopObject
);
1886 /* create a W32THREADINFO structure if not already done, or update it */
1887 ti
= GetW32ThreadInfo();
1888 GetWin32ClientInfo()->ulClientDelta
= DesktopHeapGetUserDelta();
1891 if (GetWin32ClientInfo()->pDeskInfo
== NULL
)
1893 GetWin32ClientInfo()->pDeskInfo
=
1894 (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
-
1895 GetWin32ClientInfo()->ulClientDelta
);
1899 return STATUS_SUCCESS
;
1903 IntSetThreadDesktop(IN PDESKTOP DesktopObject
,
1904 IN BOOL FreeOnFailure
)
1906 PDESKTOP OldDesktop
;
1907 PTHREADINFO W32Thread
;
1911 DPRINT("IntSetThreadDesktop() DO=%p, FOF=%d\n", DesktopObject
, FreeOnFailure
);
1912 MapHeap
= (PsGetCurrentProcess() != PsInitialSystemProcess
);
1913 W32Thread
= PsGetCurrentThreadWin32Thread();
1915 if (W32Thread
->rpdesk
!= DesktopObject
)
1917 OldDesktop
= W32Thread
->rpdesk
;
1919 if (!IsListEmpty(&W32Thread
->WindowListHead
))
1921 DPRINT1("Attempted to change thread desktop although the thread has windows!\n");
1922 SetLastWin32Error(ERROR_BUSY
);
1926 W32Thread
->rpdesk
= DesktopObject
;
1928 if (MapHeap
&& DesktopObject
!= NULL
)
1930 Status
= IntMapDesktopView(DesktopObject
);
1931 if (!NT_SUCCESS(Status
))
1933 SetLastNtError(Status
);
1938 /* Hack for system threads */
1941 PCLIENTINFO pci
= GetWin32ClientInfo();
1942 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1945 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)DesktopObject
->pDeskInfo
- pci
->ulClientDelta
);
1949 if (OldDesktop
!= NULL
&&
1950 !IntCheckProcessDesktopClasses(OldDesktop
,
1953 DPRINT1("Failed to move process classes to shared heap!\n");
1955 /* failed to move desktop classes to the shared heap,
1956 unmap the view and return the error */
1957 if (MapHeap
&& DesktopObject
!= NULL
)
1958 IntUnmapDesktopView(DesktopObject
);
1963 /* Remove the thread from the old desktop's list */
1964 RemoveEntryList(&W32Thread
->PtiLink
);
1966 if (DesktopObject
!= NULL
)
1968 ObReferenceObject(DesktopObject
);
1969 /* Insert into new desktop's list */
1970 InsertTailList(&DesktopObject
->PtiList
, &W32Thread
->PtiLink
);
1973 if (OldDesktop
!= NULL
)
1977 IntUnmapDesktopView(OldDesktop
);
1980 ObDereferenceObject(OldDesktop
);
1988 * NtUserSetThreadDesktop
1995 NtUserSetThreadDesktop(HDESK hDesktop
)
1997 PDESKTOP DesktopObject
;
1999 DECLARE_RETURN(BOOL
);
2001 UserEnterExclusive();
2002 DPRINT("Enter NtUserSetThreadDesktop\n");
2004 /* Validate the new desktop. */
2005 Status
= IntValidateDesktopHandle(
2011 if (!NT_SUCCESS(Status
))
2013 DPRINT("Validation of desktop handle (0x%X) failed\n", hDesktop
);
2017 /* FIXME: Should check here to see if the thread has any windows. */
2019 if (!IntSetThreadDesktop(DesktopObject
,
2028 DPRINT("Leave NtUserSetThreadDesktop, ret=%i\n",_ret_
);