2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: subsystems/win32/win32k/ntuser/desktop.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 /* INCLUDES ******************************************************************/
12 DBG_DEFAULT_CHANNEL(UserDesktop
);
17 IN OUT PDESKTOP Desktop
20 /* GLOBALS *******************************************************************/
22 /* Currently active desktop */
23 PDESKTOP InputDesktop
= NULL
;
24 HDESK InputDesktopHandle
= NULL
;
25 HDC ScreenDeviceContext
= NULL
;
27 /* OBJECT CALLBACKS **********************************************************/
31 IntDesktopObjectParse(IN PVOID ParseObject
,
33 IN OUT PACCESS_STATE AccessState
,
34 IN KPROCESSOR_MODE AccessMode
,
36 IN OUT PUNICODE_STRING CompleteName
,
37 IN OUT PUNICODE_STRING RemainingName
,
38 IN OUT PVOID Context OPTIONAL
,
39 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL
,
44 OBJECT_ATTRIBUTES ObjectAttributes
;
45 PLIST_ENTRY NextEntry
, ListHead
;
46 PWINSTATION_OBJECT WinStaObject
= (PWINSTATION_OBJECT
)ParseObject
;
47 PUNICODE_STRING DesktopName
;
48 PBOOLEAN pContext
= (PBOOLEAN
) Context
;
53 /* Set the list pointers and loop the window station */
54 ListHead
= &WinStaObject
->DesktopListHead
;
55 NextEntry
= ListHead
->Flink
;
56 while (NextEntry
!= ListHead
)
58 /* Get the current desktop */
59 Desktop
= CONTAINING_RECORD(NextEntry
, DESKTOP
, ListEntry
);
62 DesktopName
= GET_DESKTOP_NAME(Desktop
);
65 /* Compare the name */
66 if (RtlEqualUnicodeString(RemainingName
,
68 (Attributes
& OBJ_CASE_INSENSITIVE
)))
70 /* We found a match. Did this come from a create? */
73 /* Unless OPEN_IF was given, fail with an error */
74 if (!(Attributes
& OBJ_OPENIF
))
77 return STATUS_OBJECT_NAME_COLLISION
;
81 /* Otherwise, return with a warning only */
82 Status
= STATUS_OBJECT_NAME_EXISTS
;
87 /* This was a real open, so this is OK */
88 Status
= STATUS_SUCCESS
;
91 /* Reference the desktop and return it */
92 ObReferenceObject(Desktop
);
98 /* Go to the next desktop */
99 NextEntry
= NextEntry
->Flink
;
102 /* If we got here but this isn't a create, then fail */
103 if (!Context
) return STATUS_OBJECT_NAME_NOT_FOUND
;
105 /* Create the desktop object */
106 InitializeObjectAttributes(&ObjectAttributes
, RemainingName
, 0, NULL
, NULL
);
107 Status
= ObCreateObject(KernelMode
,
116 if (!NT_SUCCESS(Status
)) return Status
;
118 /* Initialize shell hook window list and set the parent */
119 RtlZeroMemory(Desktop
, sizeof(DESKTOP
));
120 InitializeListHead(&Desktop
->ShellHookWindows
);
121 Desktop
->rpwinstaParent
= (PWINSTATION_OBJECT
)ParseObject
;
123 /* Put the desktop on the window station's list of associated desktops */
124 InsertTailList(&Desktop
->rpwinstaParent
->DesktopListHead
,
125 &Desktop
->ListEntry
);
127 /* Set the desktop object and return success */
130 return STATUS_SUCCESS
;
134 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters
)
136 PDESKTOP Desktop
= (PDESKTOP
)Parameters
->Object
;
138 TRACE("Deleting desktop object 0x%x\n", Desktop
);
140 /* Remove the desktop from the window station's list of associcated desktops */
141 RemoveEntryList(&Desktop
->ListEntry
);
143 IntFreeDesktopHeap(Desktop
);
147 IntDesktopOkToClose(PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters
)
151 pti
= PsGetCurrentThreadWin32Thread();
155 /* This happens when we leak desktop handles */
156 return STATUS_SUCCESS
;
159 /* Do not allow the current desktop or the initial desktop to be closed */
160 if( Parameters
->Handle
== pti
->ppi
->hdeskStartup
||
161 Parameters
->Handle
== pti
->hdesk
)
163 return STATUS_ACCESS_DENIED
;
166 return STATUS_SUCCESS
;
169 /* PRIVATE FUNCTIONS **********************************************************/
174 InitDesktopImpl(VOID
)
176 GENERIC_MAPPING IntDesktopMapping
= { DESKTOP_READ
,
181 /* Set Desktop Object Attributes */
182 ExDesktopObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
= sizeof(DESKTOP
);
183 ExDesktopObjectType
->TypeInfo
.GenericMapping
= IntDesktopMapping
;
184 ExDesktopObjectType
->TypeInfo
.ValidAccessMask
= DESKTOP_ALL_ACCESS
;
185 return STATUS_SUCCESS
;
188 static int GetSystemVersionString(LPWSTR buffer
)
190 RTL_OSVERSIONINFOEXW versionInfo
;
193 versionInfo
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
195 if (!NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&versionInfo
)))
198 if (versionInfo
.dwMajorVersion
<= 4)
199 len
= swprintf(buffer
,
200 L
"ReactOS Version %d.%d %s Build %d",
201 versionInfo
.dwMajorVersion
, versionInfo
.dwMinorVersion
,
202 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
204 len
= swprintf(buffer
,
205 L
"ReactOS %s (Build %d)",
206 versionInfo
.szCSDVersion
, versionInfo
.dwBuildNumber
&0xFFFF);
213 IntParseDesktopPath(PEPROCESS Process
,
214 PUNICODE_STRING DesktopPath
,
218 OBJECT_ATTRIBUTES ObjectAttributes
;
219 UNICODE_STRING ObjectName
;
221 WCHAR wstrWinstaFullName
[MAX_PATH
], *pwstrWinsta
= NULL
, *pwstrDesktop
= NULL
;
230 if(DesktopPath
->Buffer
!= NULL
&& DesktopPath
->Length
> sizeof(WCHAR
))
233 * Parse the desktop path string which can be in the form "WinSta\Desktop"
234 * or just "Desktop". In latter case WinSta0 will be used.
237 pwstrDesktop
= wcschr(DesktopPath
->Buffer
, L
'\\');
238 if(pwstrDesktop
!= NULL
)
242 pwstrWinsta
= DesktopPath
->Buffer
;
246 pwstrDesktop
= DesktopPath
->Buffer
;
250 TRACE("IntParseDesktopPath pwstrWinsta:%S pwstrDesktop:%S\n", pwstrWinsta
, pwstrDesktop
);
254 /* Search the process handle table for (inherited) window station
255 handles, use a more appropriate one than WinSta0 if possible. */
256 if (!ObFindHandleForObject(Process
,
258 ExWindowStationObjectType
,
263 /* We had no luck searching for opened handles, use WinSta0 now */
265 pwstrWinsta
= L
"WinSta0";
269 /* Search the process handle table for (inherited) desktop
270 handles, use a more appropriate one than Default if possible. */
271 if (!ObFindHandleForObject(Process
,
278 /* We had no luck searching for opened handles, use Desktop now */
280 pwstrDesktop
= L
"Default";
285 swprintf(wstrWinstaFullName
, L
"%wZ\\%ws", &gustrWindowStationsDir
, pwstrWinsta
);
286 RtlInitUnicodeString( &ObjectName
, wstrWinstaFullName
);
288 TRACE("parsed initial winsta: %wZ\n", &ObjectName
);
290 /* Open the window station */
291 InitializeObjectAttributes(&ObjectAttributes
,
293 OBJ_CASE_INSENSITIVE
,
297 Status
= ObOpenObjectByName(&ObjectAttributes
,
298 ExWindowStationObjectType
,
305 if(!NT_SUCCESS(Status
))
307 SetLastNtError(Status
);
308 ERR("Failed to reference window station %wZ PID: %d!\n", &ObjectName
);
313 if(*hDesktop
== NULL
)
315 RtlInitUnicodeString(&ObjectName
, pwstrDesktop
);
317 TRACE("parsed initial desktop: %wZ\n", &ObjectName
);
319 /* Open the desktop object */
320 InitializeObjectAttributes(&ObjectAttributes
,
322 OBJ_CASE_INSENSITIVE
,
326 Status
= ObOpenObjectByName(&ObjectAttributes
,
334 if(!NT_SUCCESS(Status
))
339 SetLastNtError(Status
);
340 ERR("Failed to reference desktop %wZ PID: %d!\n", &ObjectName
);
344 return STATUS_SUCCESS
;
348 * IntValidateDesktopHandle
350 * Validates the desktop handle.
353 * If the function succeeds, the handle remains referenced. If the
354 * fucntion fails, last error is set.
358 IntValidateDesktopHandle(
360 KPROCESSOR_MODE AccessMode
,
361 ACCESS_MASK DesiredAccess
,
366 Status
= ObReferenceObjectByHandle(
374 TRACE("IntValidateDesktopHandle: handle:0x%x obj:0x%x access:0x%x Status:0x%x\n",
375 Desktop
, *Object
, DesiredAccess
, Status
);
377 if (!NT_SUCCESS(Status
))
378 SetLastNtError(Status
);
384 IntGetActiveDesktop(VOID
)
390 * Returns or creates a handle to the desktop object
393 IntGetDesktopObjectHandle(PDESKTOP DesktopObject
)
398 ASSERT(DesktopObject
);
400 if (!ObFindHandleForObject(PsGetCurrentProcess(),
406 Status
= ObOpenObjectByPointer(DesktopObject
,
413 if(!NT_SUCCESS(Status
))
415 /* Unable to create a handle */
416 ERR("Unable to create a desktop handle\n");
422 ERR("Got handle: %lx\n", Ret
);
428 PUSER_MESSAGE_QUEUE FASTCALL
429 IntGetFocusMessageQueue(VOID
)
431 PDESKTOP pdo
= IntGetActiveDesktop();
434 TRACE("No active desktop\n");
437 return (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
441 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue
)
443 PUSER_MESSAGE_QUEUE Old
;
444 PDESKTOP pdo
= IntGetActiveDesktop();
447 TRACE("No active desktop\n");
452 if(NewQueue
->Desktop
!= NULL
)
454 TRACE("Message Queue already attached to another desktop!\n");
457 IntReferenceMessageQueue(NewQueue
);
458 (void)InterlockedExchangePointer((PVOID
*)&NewQueue
->Desktop
, pdo
);
460 Old
= (PUSER_MESSAGE_QUEUE
)InterlockedExchangePointer((PVOID
*)&pdo
->ActiveMessageQueue
, NewQueue
);
463 (void)InterlockedExchangePointer((PVOID
*)&Old
->Desktop
, 0);
464 IntDereferenceMessageQueue(Old
);
465 gpqForegroundPrev
= Old
;
467 // Only one Q can have active foreground even when there are more than one desktop.
468 if (NewQueue
) gpqForeground
= pdo
->ActiveMessageQueue
;
471 HWND FASTCALL
IntGetDesktopWindow(VOID
)
473 PDESKTOP pdo
= IntGetActiveDesktop();
476 TRACE("No active desktop\n");
479 return pdo
->DesktopWindow
;
482 PWND FASTCALL
UserGetDesktopWindow(VOID
)
484 PDESKTOP pdo
= IntGetActiveDesktop();
488 TRACE("No active desktop\n");
491 // return pdo->pDeskInfo->spwnd;
492 return UserGetWindowObject(pdo
->DesktopWindow
);
495 HWND FASTCALL
IntGetMessageWindow(VOID
)
497 PDESKTOP pdo
= IntGetActiveDesktop();
501 TRACE("No active desktop\n");
504 return pdo
->spwndMessage
->head
.h
;
507 PWND FASTCALL
UserGetMessageWindow(VOID
)
509 PDESKTOP pdo
= IntGetActiveDesktop();
513 TRACE("No active desktop\n");
516 return pdo
->spwndMessage
;
519 HWND FASTCALL
IntGetCurrentThreadDesktopWindow(VOID
)
521 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
522 PDESKTOP pdo
= pti
->rpdesk
;
525 ERR("Thread doesn't have a desktop\n");
528 return pdo
->DesktopWindow
;
531 /* PUBLIC FUNCTIONS ***********************************************************/
534 UserGetDesktopDC(ULONG DcType
, BOOL EmptyDC
, BOOL ValidatehWnd
)
536 PWND DesktopObject
= 0;
539 if (DcType
== DC_TYPE_DIRECT
)
541 DesktopObject
= UserGetDesktopWindow();
542 DesktopHDC
= (HDC
)UserGetWindowDC(DesktopObject
);
546 PMONITOR pMonitor
= UserGetPrimaryMonitor();
547 DesktopHDC
= IntGdiCreateDisplayDC(pMonitor
->hDev
, DcType
, EmptyDC
);
559 Window
= UserGetDesktopWindow();
560 hRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
562 IntInvalidateWindows( Window
,
569 GreDeleteObject(hRgn
);
574 co_IntShowDesktop(PDESKTOP Desktop
, ULONG Width
, ULONG Height
)
577 CSR_API_MESSAGE Request
;
579 Request
.Type
= MAKE_CSR_API(SHOW_DESKTOP
, CSR_GUI
);
580 Request
.Data
.ShowDesktopRequest
.DesktopWindow
= Desktop
->DesktopWindow
;
581 Request
.Data
.ShowDesktopRequest
.Width
= Width
;
582 Request
.Data
.ShowDesktopRequest
.Height
= Height
;
584 return co_CsrNotify(&Request
);
586 #if 0 // DESKTOPWNDPROC
589 Window
= IntGetWindowObject(Desktop
->DesktopWindow
);
593 ERR("No Desktop window.\n");
594 return STATUS_UNSUCCESSFUL
;
596 co_WinPosSetWindowPos(Window
, NULL
, 0, 0, Width
, Height
, SWP_NOACTIVATE
|SWP_NOZORDER
|SWP_SHOWWINDOW
);
598 co_UserRedrawWindow( Window
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
599 return STATUS_SUCCESS
;
604 IntHideDesktop(PDESKTOP Desktop
)
608 DesktopWnd
= IntGetWindowObject(Desktop
->DesktopWindow
);
611 return ERROR_INVALID_WINDOW_HANDLE
;
613 DesktopWnd
->style
&= ~WS_VISIBLE
;
615 return STATUS_SUCCESS
;
620 UserBuildShellHookHwndList(PDESKTOP Desktop
)
623 PSHELL_HOOK_WINDOW Current
;
626 /* FIXME: If we save nb elements in desktop, we dont have to loop to find nb entries */
627 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
630 if (!entries
) return NULL
;
632 list
= ExAllocatePoolWithTag(PagedPool
, sizeof(HWND
) * (entries
+ 1), USERTAG_WINDOWLIST
); /* alloc one extra for nullterm */
637 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
638 *cursor
++ = Current
->hWnd
;
640 *cursor
= NULL
; /* Nullterm list */
647 * Send the Message to the windows registered for ShellHook
648 * notifications. The lParam contents depend on the Message. See
649 * MSDN for more details (RegisterShellHookWindow)
651 VOID
co_IntShellHookNotify(WPARAM Message
, LPARAM lParam
)
653 PDESKTOP Desktop
= IntGetActiveDesktop();
656 if (!gpsi
->uiShellMsg
)
658 gpsi
->uiShellMsg
= IntAddAtom(L
"SHELLHOOK");
660 TRACE("MsgType = %x\n", gpsi
->uiShellMsg
);
661 if (!gpsi
->uiShellMsg
)
662 ERR("LastError: %x\n", EngGetLastError());
667 TRACE("IntShellHookNotify: No desktop!\n");
671 HwndList
= UserBuildShellHookHwndList(Desktop
);
674 HWND
* cursor
= HwndList
;
676 for (; *cursor
; cursor
++)
678 TRACE("Sending notify\n");
679 co_IntPostOrSendMessage(*cursor
,
685 ExFreePool(HwndList
);
691 * Add the window to the ShellHookWindows list. The windows
692 * on that list get notifications that are important to shell
695 * TODO: Validate the window? I'm not sure if sending these messages to
696 * an unsuspecting application that is not your own is a nice thing to do.
698 BOOL
IntRegisterShellHookWindow(HWND hWnd
)
700 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
701 PDESKTOP Desktop
= pti
->rpdesk
;
702 PSHELL_HOOK_WINDOW Entry
;
704 TRACE("IntRegisterShellHookWindow\n");
706 /* First deregister the window, so we can be sure it's never twice in the
709 IntDeRegisterShellHookWindow(hWnd
);
711 Entry
= ExAllocatePoolWithTag(PagedPool
,
712 sizeof(SHELL_HOOK_WINDOW
),
720 InsertTailList(&Desktop
->ShellHookWindows
, &Entry
->ListEntry
);
726 * Remove the window from the ShellHookWindows list. The windows
727 * on that list get notifications that are important to shell
730 BOOL
IntDeRegisterShellHookWindow(HWND hWnd
)
732 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
733 PDESKTOP Desktop
= pti
->rpdesk
;
734 PSHELL_HOOK_WINDOW Current
;
736 LIST_FOR_EACH(Current
, &Desktop
->ShellHookWindows
, SHELL_HOOK_WINDOW
, ListEntry
)
738 if (Current
->hWnd
== hWnd
)
740 RemoveEntryList(&Current
->ListEntry
);
750 IntFreeDesktopHeap(IN OUT PDESKTOP Desktop
)
752 if (Desktop
->hsectionDesktop
!= NULL
)
754 ObDereferenceObject(Desktop
->hsectionDesktop
);
755 Desktop
->hsectionDesktop
= NULL
;
760 IntPaintDesktop(HDC hDC
)
763 HBRUSH DesktopBrush
, PreviousBrush
;
765 BOOL doPatBlt
= TRUE
;
767 static WCHAR s_wszSafeMode
[] = L
"Safe Mode";
773 GdiGetClipBox(hDC
, &Rect
);
775 hWndDesktop
= IntGetDesktopWindow(); // rpdesk->DesktopWindow;
777 WndDesktop
= UserGetWindowObject(hWndDesktop
); // rpdesk->pDeskInfo->spwnd;
783 if (!UserGetSystemMetrics(SM_CLEANBOOT
))
785 DesktopBrush
= (HBRUSH
)WndDesktop
->pcls
->hbrBackground
;
788 * Paint desktop background
790 if (gspv
.hbmWallpaper
!= NULL
)
796 sz
.cx
= WndDesktop
->rcWindow
.right
- WndDesktop
->rcWindow
.left
;
797 sz
.cy
= WndDesktop
->rcWindow
.bottom
- WndDesktop
->rcWindow
.top
;
799 if (gspv
.WallpaperMode
== wmStretch
||
800 gspv
.WallpaperMode
== wmTile
)
807 /* Find the upper left corner, can be negtive if the bitmap is bigger then the screen */
808 x
= (sz
.cx
/ 2) - (gspv
.cxWallpaper
/ 2);
809 y
= (sz
.cy
/ 2) - (gspv
.cyWallpaper
/ 2);
812 hWallpaperDC
= NtGdiCreateCompatibleDC(hDC
);
813 if(hWallpaperDC
!= NULL
)
817 /* Fill in the area that the bitmap is not going to cover */
820 /* FIXME: Clip out the bitmap
821 can be replaced with "NtGdiPatBlt(hDC, x, y, WinSta->cxWallpaper, WinSta->cyWallpaper, PATCOPY | DSTINVERT);"
822 once we support DSTINVERT */
823 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
824 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
825 NtGdiSelectBrush(hDC
, PreviousBrush
);
828 /*Do not fill the background after it is painted no matter the size of the picture */
831 hOldBitmap
= NtGdiSelectBitmap(hWallpaperDC
, gspv
.hbmWallpaper
);
833 if (gspv
.WallpaperMode
== wmStretch
)
835 if(Rect
.right
&& Rect
.bottom
)
850 else if (gspv
.WallpaperMode
== wmTile
)
852 /* Paint the bitmap across the screen then down */
853 for(y
= 0; y
< Rect
.bottom
; y
+= gspv
.cyWallpaper
)
855 for(x
= 0; x
< Rect
.right
; x
+= gspv
.cxWallpaper
)
885 NtGdiSelectBitmap(hWallpaperDC
, hOldBitmap
);
886 NtGdiDeleteObjectApp(hWallpaperDC
);
892 /* Black desktop background in Safe Mode */
893 DesktopBrush
= StockObjects
[BLACK_BRUSH
];
896 /* Back ground is set to none, clear the screen */
899 PreviousBrush
= NtGdiSelectBrush(hDC
, DesktopBrush
);
900 NtGdiPatBlt(hDC
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
, PATCOPY
);
901 NtGdiSelectBrush(hDC
, PreviousBrush
);
905 * Display system version on the desktop background
908 if (g_PaintDesktopVersion
||UserGetSystemMetrics(SM_CLEANBOOT
))
910 static WCHAR s_wszVersion
[256] = {0};
915 len
= wcslen(s_wszVersion
);
919 len
= GetSystemVersionString(s_wszVersion
);
924 if (!UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &rect
, 0))
926 rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
927 rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
930 color_old
= IntGdiSetTextColor(hDC
, RGB(255,255,255));
931 align_old
= IntGdiSetTextAlign(hDC
, TA_RIGHT
);
932 mode_old
= IntGdiSetBkMode(hDC
, TRANSPARENT
);
934 if(!UserGetSystemMetrics(SM_CLEANBOOT
))
936 GreExtTextOutW(hDC
, rect
.right
-16, rect
.bottom
-48, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
941 /* Version information text in top center */
942 IntGdiSetTextAlign(hDC
, TA_CENTER
|TA_TOP
);
943 GreExtTextOutW(hDC
, (rect
.right
+rect
.left
)/2, rect
.top
, 0, NULL
, s_wszVersion
, len
, NULL
, 0);
944 /* Safe Mode text in corners */
945 len
= wcslen(s_wszSafeMode
);
946 IntGdiSetTextAlign(hDC
, TA_RIGHT
|TA_TOP
);
947 GreExtTextOutW(hDC
, rect
.right
, rect
.top
, 0, NULL
, s_wszSafeMode
, len
, NULL
, 0);
948 IntGdiSetTextAlign(hDC
, TA_RIGHT
|TA_BASELINE
);
949 GreExtTextOutW(hDC
, rect
.right
, rect
.bottom
, 0, NULL
, s_wszSafeMode
, len
, NULL
, 0);
950 IntGdiSetTextAlign(hDC
, TA_LEFT
|TA_TOP
);
951 GreExtTextOutW(hDC
, rect
.left
, rect
.top
, 0, NULL
, s_wszSafeMode
, len
, NULL
, 0);
952 IntGdiSetTextAlign(hDC
, TA_LEFT
|TA_BASELINE
);
953 GreExtTextOutW(hDC
, rect
.left
, rect
.bottom
, 0, NULL
, s_wszSafeMode
, len
, NULL
, 0);
958 IntGdiSetBkMode(hDC
, mode_old
);
959 IntGdiSetTextAlign(hDC
, align_old
);
960 IntGdiSetTextColor(hDC
, color_old
);
968 /* SYSCALLS *******************************************************************/
971 * NtUserCreateDesktop
973 * Creates a new desktop.
980 * Name of the device.
989 * Requested type of access.
993 * If the function succeeds, the return value is a handle to the newly
994 * created desktop. If the specified desktop already exists, the function
995 * succeeds and returns a handle to the existing desktop. When you are
996 * finished using the handle, call the CloseDesktop function to close it.
997 * If the function fails, the return value is NULL.
1004 NtUserCreateDesktop(
1005 POBJECT_ATTRIBUTES ObjectAttributes
,
1006 PUNICODE_STRING lpszDesktopDevice
,
1009 ACCESS_MASK dwDesiredAccess
)
1011 PDESKTOP DesktopObject
;
1012 UNICODE_STRING DesktopName
;
1013 NTSTATUS Status
= STATUS_SUCCESS
;
1015 CSR_API_MESSAGE Request
;
1016 PVOID DesktopHeapSystemBase
= NULL
;
1017 SIZE_T DesktopInfoSize
;
1019 ULONG_PTR HeapSize
= 4 * 1024 * 1024; /* FIXME */
1020 UNICODE_STRING ClassName
;
1021 LARGE_STRING WindowName
;
1022 BOOL NoHooks
= FALSE
;
1026 PTHREADINFO ptiCurrent
;
1027 DECLARE_RETURN(HDESK
);
1029 TRACE("Enter NtUserCreateDesktop\n");
1030 UserEnterExclusive();
1032 ptiCurrent
= PsGetCurrentThreadWin32Thread();
1035 /* Turn off hooks when calling any CreateWindowEx from inside win32k. */
1036 NoHooks
= (ptiCurrent
->TIF_flags
& TIF_DISABLEHOOKS
);
1037 ptiCurrent
->TIF_flags
|= TIF_DISABLEHOOKS
;
1038 ptiCurrent
->pClientInfo
->dwTIFlags
= ptiCurrent
->TIF_flags
;
1040 DesktopName
.Buffer
= NULL
;
1043 * Try to open already existing desktop
1046 Status
= ObOpenObjectByName(
1048 ExDesktopObjectType
,
1054 if (!NT_SUCCESS(Status
)) RETURN(NULL
);
1056 /* In case the object was not created (eg if it existed), return now */
1057 if (Context
== FALSE
)
1059 TRACE("NtUserCreateDesktop opened desktop %wZ\n", ObjectAttributes
->ObjectName
);
1063 /* Capture desktop name */
1066 ProbeForRead( ObjectAttributes
, sizeof(OBJECT_ATTRIBUTES
), 1);
1068 Status
= IntSafeCopyUnicodeStringTerminateNULL(&DesktopName
, ObjectAttributes
->ObjectName
);
1070 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1072 Status
= _SEH2_GetExceptionCode();
1076 if (! NT_SUCCESS(Status
))
1078 ERR("Failed reading Object Attributes from user space.\n");
1079 SetLastNtError(Status
);
1083 /* Reference the desktop */
1084 Status
= ObReferenceObjectByHandle(Desktop
,
1086 ExDesktopObjectType
,
1088 (PVOID
)&DesktopObject
,
1090 if (!NT_SUCCESS(Status
))
1092 ERR("Failed to reference desktop object\n");
1096 TRACE("NtUserCreateDesktop created desktop 0x%x with name %wZ\n", DesktopObject
, &DesktopName
);
1098 DesktopObject
->hsectionDesktop
= NULL
;
1099 DesktopObject
->pheapDesktop
= UserCreateHeap(&DesktopObject
->hsectionDesktop
,
1100 &DesktopHeapSystemBase
,
1102 if (DesktopObject
->pheapDesktop
== NULL
)
1104 ObDereferenceObject(DesktopObject
);
1105 ERR("Failed to create desktop heap!\n");
1109 DesktopInfoSize
= sizeof(DESKTOPINFO
) + DesktopName
.Length
+ sizeof(WCHAR
);
1111 DesktopObject
->pDeskInfo
= RtlAllocateHeap(DesktopObject
->pheapDesktop
,
1115 if (DesktopObject
->pDeskInfo
== NULL
)
1117 ObDereferenceObject(DesktopObject
);
1118 ERR("Failed to create the DESKTOP structure!\n");
1122 RtlZeroMemory(DesktopObject
->pDeskInfo
,
1125 DesktopObject
->pDeskInfo
->pvDesktopBase
= DesktopHeapSystemBase
;
1126 DesktopObject
->pDeskInfo
->pvDesktopLimit
= (PVOID
)((ULONG_PTR
)DesktopHeapSystemBase
+ HeapSize
);
1127 RtlCopyMemory(DesktopObject
->pDeskInfo
->szDesktopName
,
1129 DesktopName
.Length
+ sizeof(WCHAR
));
1131 /* Initialize some local (to win32k) desktop state. */
1132 InitializeListHead(&DesktopObject
->PtiList
);
1133 DesktopObject
->ActiveMessageQueue
= NULL
;
1135 /* Setup Global Hooks. */
1136 for (i
= 0; i
< NB_HOOKS
; i
++)
1138 InitializeListHead(&DesktopObject
->pDeskInfo
->aphkStart
[i
]);
1142 * Create a handle for CSRSS and notify CSRSS for Creating Desktop Background Window.
1144 Request
.Type
= MAKE_CSR_API(CREATE_DESKTOP
, CSR_GUI
);
1145 Status
= CsrInsertObject(Desktop
,
1147 (HANDLE
*)&Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1148 if (! NT_SUCCESS(Status
))
1150 ERR("Failed to create desktop handle for CSRSS\n");
1152 SetLastNtError(Status
);
1156 Status
= co_CsrNotify(&Request
);
1157 if (! NT_SUCCESS(Status
))
1159 CsrCloseHandle(Request
.Data
.CreateDesktopRequest
.DesktopHandle
);
1160 ERR("Failed to notify CSRSS about new desktop\n");
1162 SetLastNtError(Status
);
1166 if (!ptiCurrent
->rpdesk
) IntSetThreadDesktop(Desktop
,FALSE
);
1169 Based on wine/server/window.c in get_desktop_window.
1172 #if 0 // DESKTOPWNDPROC from Revision 6908 Dedicated to GvG!
1173 // Turn on when server side proc is ready.
1175 // Create desktop window.
1178 Currently this works but it hangs in
1179 co_IntShowDesktop->co_UserRedrawWindow->co_IntPaintWindows->co_IntSendMessage
1180 Commenting out co_UserRedrawWindow will allow it to run with gui issues.
1182 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_DESKTOP
])));
1183 ClassName
.Length
= 0;
1184 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1186 RtlZeroMemory(&Cs
, sizeof(Cs
));
1187 Cs
.x
= UserGetSystemMetrics(SM_XVIRTUALSCREEN
);
1188 Cs
.y
= UserGetSystemMetrics(SM_YVIRTUALSCREEN
);
1189 Cs
.cx
= UserGetSystemMetrics(SM_CXVIRTUALSCREEN
);
1190 Cs
.cy
= UserGetSystemMetrics(SM_CYVIRTUALSCREEN
);
1191 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1192 Cs
.hInstance
= hModClient
; // Experimental mode... hModuleWin; // Server side winproc!
1193 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1194 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1196 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
, NULL
);
1199 ERR("Failed to create Desktop window handle\n");
1202 { // Should be set in window.c, Justin Case,
1203 if (!DesktopObject
->DesktopWindow
)
1205 DesktopObject
->pDeskInfo
->spwnd
= pWnd
;
1206 DesktopObject
->DesktopWindow
= UserHMGetHandle(pWnd
);
1210 ClassName
.Buffer
= ((PWSTR
)((ULONG_PTR
)(WORD
)(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
])));
1211 ClassName
.Length
= 0;
1212 RtlZeroMemory(&WindowName
, sizeof(WindowName
));
1214 RtlZeroMemory(&Cs
, sizeof(Cs
));
1215 Cs
.cx
= Cs
.cy
= 100;
1216 Cs
.style
= WS_POPUP
|WS_CLIPCHILDREN
;
1217 Cs
.hInstance
= hModClient
; // hModuleWin; // Server side winproc! Leave it to Timo to not pass on notes!
1218 Cs
.lpszName
= (LPCWSTR
) &WindowName
;
1219 Cs
.lpszClass
= (LPCWSTR
) &ClassName
;
1221 pWnd
= co_UserCreateWindowEx(&Cs
, &ClassName
, &WindowName
, NULL
);
1224 ERR("Failed to create Message window handle\n");
1228 DesktopObject
->spwndMessage
= pWnd
;
1232 if !(WinStaObject->Flags & WSF_NOIO) is (not set) for desktop input output mode (see wiki)
1233 Create Tooltip. Saved in DesktopObject->spwndTooltip.
1234 Tooltip dwExStyle: WS_EX_TOOLWINDOW|WS_EX_TOPMOST
1235 hWndParent are spwndMessage. Use hModuleWin for server side winproc!
1236 The rest is same as message window.
1237 http://msdn.microsoft.com/en-us/library/bb760250(VS.85).aspx
1242 if(DesktopName
.Buffer
!= NULL
)
1244 ExFreePoolWithTag(DesktopName
.Buffer
, TAG_STRING
);
1246 if (!NoHooks
&& ptiCurrent
)
1248 ptiCurrent
->TIF_flags
&= ~TIF_DISABLEHOOKS
;
1249 ptiCurrent
->pClientInfo
->dwTIFlags
= ptiCurrent
->TIF_flags
;
1251 TRACE("Leave NtUserCreateDesktop, ret=%i\n",_ret_
);
1259 * Opens an existing desktop.
1263 * Name of the existing desktop.
1266 * Interaction flags.
1269 * Requested type of access.
1272 * Handle to the desktop or zero on failure.
1280 POBJECT_ATTRIBUTES ObjectAttributes
,
1282 ACCESS_MASK dwDesiredAccess
)
1287 Status
= ObOpenObjectByName(
1289 ExDesktopObjectType
,
1296 if (!NT_SUCCESS(Status
))
1298 ERR("Failed to open desktop\n");
1299 SetLastNtError(Status
);
1303 TRACE("Opened desktop %S with handle 0x%x\n", ObjectAttributes
->ObjectName
->Buffer
, Desktop
);
1309 * NtUserOpenInputDesktop
1311 * Opens the input (interactive) desktop.
1315 * Interaction flags.
1318 * Inheritance option.
1321 * Requested type of access.
1324 * Handle to the input desktop or zero on failure.
1331 NtUserOpenInputDesktop(
1334 ACCESS_MASK dwDesiredAccess
)
1340 TRACE("Enter NtUserOpenInputDesktop\n");
1342 /* Get a pointer to the desktop object */
1343 Status
= IntValidateDesktopHandle(InputDesktopHandle
, UserMode
, 0, &pdesk
);
1344 if (!NT_SUCCESS(Status
))
1346 TRACE("Validation of input desktop handle (0x%X) failed\n", InputDesktop
);
1350 /* Create a new handle to the object */
1351 Status
= ObOpenObjectByPointer(
1356 ExDesktopObjectType
,
1360 ObDereferenceObject(pdesk
);
1362 if (!NT_SUCCESS(Status
))
1364 ERR("Failed to open input desktop object\n");
1365 SetLastNtError(Status
);
1369 TRACE("NtUserOpenInputDesktop returning 0x%x\n",hdesk
);
1374 * NtUserCloseDesktop
1376 * Closes a desktop handle.
1380 * Handle to the desktop.
1386 * The desktop handle can be created with NtUserCreateDesktop or
1387 * NtUserOpenDesktop. This function will fail if any thread in the calling
1388 * process is using the specified desktop handle or if the handle refers
1389 * to the initial desktop of the calling process.
1396 NtUserCloseDesktop(HDESK hDesktop
)
1401 DECLARE_RETURN(BOOL
);
1403 pti
= PsGetCurrentThreadWin32Thread();
1405 TRACE("NtUserCloseDesktop called (0x%x)\n", hDesktop
);
1406 UserEnterExclusive();
1408 if( hDesktop
== pti
->hdesk
|| hDesktop
== pti
->ppi
->hdeskStartup
)
1410 ERR("Attempted to close thread desktop\n");
1411 EngSetLastError(ERROR_BUSY
);
1415 Status
= IntValidateDesktopHandle( hDesktop
, UserMode
, 0, &pdesk
);
1416 if (!NT_SUCCESS(Status
))
1418 ERR("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1422 ObDereferenceObject(pdesk
);
1424 Status
= ZwClose(hDesktop
);
1425 if (!NT_SUCCESS(Status
))
1427 ERR("Failed to close desktop handle 0x%x\n", hDesktop
);
1428 SetLastNtError(Status
);
1435 TRACE("Leave NtUserCloseDesktop, ret=%i\n",_ret_
);
1441 * NtUserPaintDesktop
1443 * The NtUserPaintDesktop function fills the clipping region in the
1444 * specified device context with the desktop pattern or wallpaper. The
1445 * function is provided primarily for shell desktops.
1449 * Handle to the device context.
1456 NtUserPaintDesktop(HDC hDC
)
1459 UserEnterExclusive();
1460 TRACE("Enter NtUserPaintDesktop\n");
1461 Ret
= IntPaintDesktop(hDC
);
1462 TRACE("Leave NtUserPaintDesktop, ret=%i\n",Ret
);
1468 * NtUserSwitchDesktop
1470 * Sets the current input (interactive) desktop.
1474 * Handle to desktop.
1484 NtUserSwitchDesktop(HDESK hdesk
)
1488 DECLARE_RETURN(BOOL
);
1490 UserEnterExclusive();
1491 TRACE("Enter NtUserSwitchDesktop(0x%x)\n", hdesk
);
1493 Status
= IntValidateDesktopHandle( hdesk
, UserMode
, 0, &pdesk
);
1494 if (!NT_SUCCESS(Status
))
1496 ERR("Validation of desktop handle (0x%X) failed\n", hdesk
);
1501 * Don't allow applications switch the desktop if it's locked, unless the caller
1502 * is the logon application itself
1504 if((pdesk
->rpwinstaParent
->Flags
& WSS_LOCKED
) &&
1505 LogonProcess
!= PsGetCurrentProcessWin32Process())
1507 ObDereferenceObject(pdesk
);
1508 ERR("Switching desktop 0x%x denied because the window station is locked!\n", hdesk
);
1512 if(pdesk
->rpwinstaParent
!= InputWindowStation
)
1514 ObDereferenceObject(pdesk
);
1515 ERR("Switching desktop 0x%x denied because desktop doesn't belong to the interactive winsta!\n", hdesk
);
1519 /* FIXME: Fail if the process is associated with a secured
1520 desktop such as Winlogon or Screen-Saver */
1521 /* FIXME: Connect to input device */
1523 /* Set the active desktop in the desktop's window station. */
1524 InputWindowStation
->ActiveDesktop
= pdesk
;
1526 /* Set the global state. */
1527 InputDesktop
= pdesk
;
1528 InputDesktopHandle
= hdesk
;
1530 ObDereferenceObject(pdesk
);
1535 TRACE("Leave NtUserSwitchDesktop, ret=%i\n",_ret_
);
1541 * NtUserGetThreadDesktop
1548 NtUserGetThreadDesktop(DWORD dwThreadId
, DWORD Unknown1
)
1552 PDESKTOP DesktopObject
;
1553 HDESK Ret
, hThreadDesktop
;
1554 OBJECT_HANDLE_INFORMATION HandleInformation
;
1555 DECLARE_RETURN(HDESK
);
1557 UserEnterExclusive();
1558 TRACE("Enter NtUserGetThreadDesktop\n");
1562 EngSetLastError(ERROR_INVALID_PARAMETER
);
1566 Status
= PsLookupThreadByThreadId((HANDLE
)(DWORD_PTR
)dwThreadId
, &Thread
);
1567 if(!NT_SUCCESS(Status
))
1569 EngSetLastError(ERROR_INVALID_PARAMETER
);
1573 if(Thread
->ThreadsProcess
== PsGetCurrentProcess())
1575 /* Just return the handle, we queried the desktop handle of a thread running
1576 in the same context */
1577 Ret
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
;
1578 ObDereferenceObject(Thread
);
1582 /* Get the desktop handle and the desktop of the thread */
1583 if(!(hThreadDesktop
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->hdesk
) ||
1584 !(DesktopObject
= ((PTHREADINFO
)Thread
->Tcb
.Win32Thread
)->rpdesk
))
1586 ObDereferenceObject(Thread
);
1587 ERR("Desktop information of thread 0x%x broken!?\n", dwThreadId
);
1591 /* We could just use DesktopObject instead of looking up the handle, but latter
1592 may be a bit safer (e.g. when the desktop is being destroyed */
1593 /* Switch into the context of the thread we're trying to get the desktop from,
1594 so we can use the handle */
1595 KeAttachProcess(&Thread
->ThreadsProcess
->Pcb
);
1596 Status
= ObReferenceObjectByHandle(hThreadDesktop
,
1598 ExDesktopObjectType
,
1600 (PVOID
*)&DesktopObject
,
1601 &HandleInformation
);
1604 /* The handle couldn't be found, there's nothing to get... */
1605 if(!NT_SUCCESS(Status
))
1607 ObDereferenceObject(Thread
);
1611 /* Lookup our handle table if we can find a handle to the desktop object,
1612 if not, create one */
1613 Ret
= IntGetDesktopObjectHandle(DesktopObject
);
1615 /* All done, we got a valid handle to the desktop */
1616 ObDereferenceObject(DesktopObject
);
1617 ObDereferenceObject(Thread
);
1621 TRACE("Leave NtUserGetThreadDesktop, ret=%i\n",_ret_
);
1627 IntUnmapDesktopView(IN PDESKTOP pdesk
)
1630 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1631 NTSTATUS Status
= STATUS_SUCCESS
;
1633 TRACE("IntUnmapDesktopView called for desktop object %p\n", pdesk
);
1635 ppi
= PsGetCurrentProcessWin32Process();
1636 PrevLink
= &ppi
->HeapMappings
.Next
;
1638 /* Unmap if we're the last thread using the desktop */
1639 HeapMapping
= *PrevLink
;
1640 while (HeapMapping
!= NULL
)
1642 if (HeapMapping
->KernelMapping
== (PVOID
)pdesk
->pheapDesktop
)
1644 if (--HeapMapping
->Count
== 0)
1646 *PrevLink
= HeapMapping
->Next
;
1648 TRACE("ppi 0x%x unmapped heap of desktop 0x%x\n", ppi
, pdesk
);
1649 Status
= MmUnmapViewOfSection(PsGetCurrentProcess(),
1650 HeapMapping
->UserMapping
);
1652 ObDereferenceObject(pdesk
);
1654 UserHeapFree(HeapMapping
);
1659 PrevLink
= &HeapMapping
->Next
;
1660 HeapMapping
= HeapMapping
->Next
;
1667 IntMapDesktopView(IN PDESKTOP pdesk
)
1670 PW32HEAP_USER_MAPPING HeapMapping
, *PrevLink
;
1671 PVOID UserBase
= NULL
;
1672 SIZE_T ViewSize
= 0;
1673 LARGE_INTEGER Offset
;
1676 TRACE("IntMapDesktopView called for desktop object 0x%x\n", pdesk
);
1678 ppi
= PsGetCurrentProcessWin32Process();
1679 PrevLink
= &ppi
->HeapMappings
.Next
;
1681 /* Find out if another thread already mapped the desktop heap */
1682 HeapMapping
= *PrevLink
;
1683 while (HeapMapping
!= NULL
)
1685 if (HeapMapping
->KernelMapping
== (PVOID
)pdesk
->pheapDesktop
)
1687 HeapMapping
->Count
++;
1688 return STATUS_SUCCESS
;
1691 PrevLink
= &HeapMapping
->Next
;
1692 HeapMapping
= HeapMapping
->Next
;
1695 /* We're the first, map the heap */
1696 Offset
.QuadPart
= 0;
1697 Status
= MmMapViewOfSection(pdesk
->hsectionDesktop
,
1698 PsGetCurrentProcess(),
1706 PAGE_EXECUTE_READ
); /* Would prefer PAGE_READONLY, but thanks to RTL heaps... */
1707 if (!NT_SUCCESS(Status
))
1709 ERR("Failed to map desktop\n");
1713 TRACE("ppi 0x%x mapped heap of desktop 0x%x\n", ppi
, pdesk
);
1715 /* Add the mapping */
1716 HeapMapping
= UserHeapAlloc(sizeof(W32HEAP_USER_MAPPING
));
1717 if (HeapMapping
== NULL
)
1719 MmUnmapViewOfSection(PsGetCurrentProcess(), UserBase
);
1720 ERR("UserHeapAlloc() failed!\n");
1721 return STATUS_NO_MEMORY
;
1724 HeapMapping
->Next
= NULL
;
1725 HeapMapping
->KernelMapping
= (PVOID
)pdesk
->pheapDesktop
;
1726 HeapMapping
->UserMapping
= UserBase
;
1727 HeapMapping
->Limit
= ViewSize
;
1728 HeapMapping
->Count
= 1;
1729 *PrevLink
= HeapMapping
;
1731 ObReferenceObject(pdesk
);
1733 return STATUS_SUCCESS
;
1737 IntSetThreadDesktop(IN HDESK hDesktop
,
1738 IN BOOL FreeOnFailure
)
1740 PDESKTOP pdesk
= NULL
, pdeskOld
;
1744 PCLIENTTHREADINFO pctiOld
, pctiNew
= NULL
;
1747 ASSERT(NtCurrentTeb());
1749 TRACE("IntSetThreadDesktop hDesktop:0x%x, FOF:%d\n",hDesktop
, FreeOnFailure
);
1751 pti
= PsGetCurrentThreadWin32Thread();
1752 pci
= pti
->pClientInfo
;
1754 /* If the caller gave us a desktop, ensure it is valid */
1755 if(hDesktop
!= NULL
)
1757 /* Validate the new desktop. */
1758 Status
= IntValidateDesktopHandle( hDesktop
, UserMode
, 0, &pdesk
);
1759 if (!NT_SUCCESS(Status
))
1761 ERR("Validation of desktop handle (0x%X) failed\n", hDesktop
);
1765 if (pti
->rpdesk
== pdesk
)
1768 ObDereferenceObject(pdesk
);
1773 /* Make sure that we don't own any window in the current desktop */
1774 if (!IsListEmpty(&pti
->WindowListHead
))
1777 ObDereferenceObject(pdesk
);
1778 ERR("Attempted to change thread desktop although the thread has windows!\n");
1779 EngSetLastError(ERROR_BUSY
);
1783 /* Before doing the switch, map the new desktop heap and allocate the new pcti */
1786 Status
= IntMapDesktopView(pdesk
);
1787 if (!NT_SUCCESS(Status
))
1789 ERR("Failed to map desktop heap!\n");
1790 ObDereferenceObject(pdesk
);
1791 SetLastNtError(Status
);
1795 pctiNew
= DesktopHeapAlloc( pdesk
, sizeof(CLIENTTHREADINFO
));
1798 ERR("Failed to allocate new pcti\n");
1799 IntUnmapDesktopView(pdesk
);
1800 ObDereferenceObject(pdesk
);
1801 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1806 /* free all classes or move them to the shared heap */
1807 if(pti
->rpdesk
!= NULL
)
1809 if(!IntCheckProcessDesktopClasses(pti
->rpdesk
, FreeOnFailure
))
1811 ERR("Failed to move process classes to shared heap!\n");
1814 DesktopHeapFree(pdesk
, pctiNew
);
1815 IntUnmapDesktopView(pdesk
);
1816 ObDereferenceObject(pdesk
);
1822 pdeskOld
= pti
->rpdesk
;
1823 hdeskOld
= pti
->hdesk
;
1824 if (pti
->pcti
!= &pti
->cti
)
1825 pctiOld
= pti
->pcti
;
1832 pti
->rpdesk
= pdesk
;
1833 pti
->hdesk
= hDesktop
;
1834 pti
->pDeskInfo
= pti
->rpdesk
->pDeskInfo
;
1835 pti
->pcti
= pctiNew
;
1837 pci
->ulClientDelta
= DesktopHeapGetUserDelta();
1838 pci
->pDeskInfo
= (PVOID
)((ULONG_PTR
)pti
->pDeskInfo
- pci
->ulClientDelta
);
1839 pci
->pClientThreadInfo
= (PVOID
)((ULONG_PTR
)pti
->pcti
- pci
->ulClientDelta
);
1841 /* initialize the new pcti */
1844 RtlCopyMemory(pctiNew
, pctiOld
, sizeof(CLIENTTHREADINFO
));
1848 RtlZeroMemory(pctiNew
, sizeof(CLIENTTHREADINFO
));
1855 pti
->pDeskInfo
= NULL
;
1856 pti
->pcti
= &pti
->cti
; // Always point inside so there will be no crash when posting or sending msg's!
1857 pci
->ulClientDelta
= 0;
1858 pci
->pDeskInfo
= NULL
;
1859 pci
->pClientThreadInfo
= NULL
;
1862 /* clean up the old desktop */
1863 if(pdeskOld
!= NULL
)
1865 RemoveEntryList(&pti
->PtiLink
);
1866 if (pctiOld
) DesktopHeapFree(pdeskOld
, pctiOld
);
1867 IntUnmapDesktopView(pdeskOld
);
1868 ObDereferenceObject(pdeskOld
);
1874 InsertTailList(&pdesk
->PtiList
, &pti
->PtiLink
);
1877 TRACE("IntSetThreadDesktop: pti 0x%x ppi 0x%x switched from object 0x%x to 0x%x\n", pti
, pti
->ppi
, pdeskOld
, pdesk
);
1883 * NtUserSetThreadDesktop
1890 NtUserSetThreadDesktop(HDESK hDesktop
)
1894 UserEnterExclusive();
1896 // FIXME: IntSetThreadDesktop validates the desktop handle, it should happen
1897 // here too and set the NT error level. Q. Is it necessary to have the validation
1898 // in IntSetThreadDesktop? Is it needed there too?
1899 if (hDesktop
|| (!hDesktop
&& CsrProcess
== PsGetCurrentProcess()))
1900 ret
= IntSetThreadDesktop(hDesktop
, FALSE
);