1 #pragma once 2 3 typedef struct _DESKTOP 4 { 5 /* Must be the first member */ 6 DWORD dwSessionId; 7 8 PDESKTOPINFO pDeskInfo; 9 LIST_ENTRY ListEntry; 10 /* Pointer to the associated window station. */ 11 struct _WINSTATION_OBJECT *rpwinstaParent; 12 DWORD dwDTFlags; 13 DWORD_PTR dwDesktopId; 14 PMENU spmenuSys; 15 PMENU spmenuDialogSys; 16 PMENU spmenuHScroll; 17 PMENU spmenuVScroll; 18 PWND spwndForeground; 19 PWND spwndTray; 20 PWND spwndMessage; 21 PWND spwndTooltip; 22 PVOID hsectionDesktop; 23 PWIN32HEAP pheapDesktop; 24 ULONG_PTR ulHeapSize; 25 LIST_ENTRY PtiList; 26 27 /* One console input thread per desktop, maintained by CONSRV */ 28 DWORD dwConsoleThreadId; 29 30 /* Use for tracking mouse moves. */ 31 PWND spwndTrack; 32 DWORD htEx; 33 RECT rcMouseHover; 34 DWORD dwMouseHoverTime; 35 36 /* ReactOS */ 37 /* Pointer to the active queue. */ 38 struct _USER_MESSAGE_QUEUE *ActiveMessageQueue; 39 /* Handle of the desktop window. */ 40 HWND DesktopWindow; 41 /* Thread blocking input */ 42 PVOID BlockInputThread; 43 LIST_ENTRY ShellHookWindows; 44 } DESKTOP, *PDESKTOP; 45 46 // Desktop flags 47 #define DF_TME_HOVER 0x00000400 48 #define DF_TME_LEAVE 0x00000800 49 #define DF_HOTTRACK 0x00004000 50 #define DF_DESTROYED 0x00008000 51 #define DF_DESKWNDDESTROYED 0x00010000 52 #define DF_DYING 0x00020000 53 54 // Index offset for Desktop data. Should these be global? 55 #define DT_GWL_PROCESSID 0 56 #define DT_GWL_THREADID 4 57 58 #define DESKTOP_READ STANDARD_RIGHTS_READ | \ 59 DESKTOP_ENUMERATE | \ 60 DESKTOP_READOBJECTS 61 62 #define DESKTOP_WRITE STANDARD_RIGHTS_WRITE | \ 63 DESKTOP_CREATEMENU | \ 64 DESKTOP_CREATEWINDOW | \ 65 DESKTOP_HOOKCONTROL | \ 66 DESKTOP_JOURNALPLAYBACK | \ 67 DESKTOP_JOURNALRECORD | \ 68 DESKTOP_WRITEOBJECTS 69 70 #define DESKTOP_EXECUTE STANDARD_RIGHTS_EXECUTE | \ 71 DESKTOP_SWITCHDESKTOP 72 73 #define DESKTOP_ALL_ACCESS STANDARD_RIGHTS_REQUIRED | \ 74 DESKTOP_CREATEMENU | \ 75 DESKTOP_CREATEWINDOW | \ 76 DESKTOP_ENUMERATE | \ 77 DESKTOP_HOOKCONTROL | \ 78 DESKTOP_JOURNALPLAYBACK | \ 79 DESKTOP_JOURNALRECORD | \ 80 DESKTOP_READOBJECTS | \ 81 DESKTOP_SWITCHDESKTOP | \ 82 DESKTOP_WRITEOBJECTS 83 84 extern PDESKTOP gpdeskInputDesktop; 85 extern PCLS DesktopWindowClass; 86 extern HDC ScreenDeviceContext; 87 extern PTHREADINFO gptiForeground; 88 extern PTHREADINFO gptiDesktopThread; 89 extern PKEVENT gpDesktopThreadStartedEvent; 90 91 typedef struct _SHELL_HOOK_WINDOW 92 { 93 LIST_ENTRY ListEntry; 94 HWND hWnd; 95 } SHELL_HOOK_WINDOW, *PSHELL_HOOK_WINDOW; 96 97 NTSTATUS 98 NTAPI 99 InitDesktopImpl(VOID); 100 101 NTSTATUS 102 APIENTRY 103 IntDesktopObjectParse(IN PVOID ParseObject, 104 IN PVOID ObjectType, 105 IN OUT PACCESS_STATE AccessState, 106 IN KPROCESSOR_MODE AccessMode, 107 IN ULONG Attributes, 108 IN OUT PUNICODE_STRING CompleteName, 109 IN OUT PUNICODE_STRING RemainingName, 110 IN OUT PVOID Context OPTIONAL, 111 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, 112 OUT PVOID *Object); 113 114 NTSTATUS 115 NTAPI 116 IntDesktopObjectDelete( 117 _In_ PVOID Parameters); 118 119 NTSTATUS 120 NTAPI 121 IntDesktopOkToClose( 122 _In_ PVOID Parameters); 123 124 NTSTATUS 125 NTAPI 126 IntDesktopObjectOpen( 127 _In_ PVOID Parameters); 128 129 NTSTATUS 130 NTAPI 131 IntDesktopObjectClose( 132 _In_ PVOID Parameters); 133 134 HDC FASTCALL 135 IntGetScreenDC(VOID); 136 137 HWND FASTCALL 138 IntGetDesktopWindow (VOID); 139 140 PWND FASTCALL 141 UserGetDesktopWindow(VOID); 142 143 HWND FASTCALL 144 IntGetCurrentThreadDesktopWindow(VOID); 145 146 PUSER_MESSAGE_QUEUE FASTCALL 147 IntGetFocusMessageQueue(VOID); 148 149 VOID FASTCALL 150 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue); 151 152 PDESKTOP FASTCALL 153 IntGetActiveDesktop(VOID); 154 155 NTSTATUS FASTCALL 156 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw); 157 158 NTSTATUS FASTCALL 159 IntHideDesktop(PDESKTOP Desktop); 160 161 BOOL IntSetThreadDesktop(IN HDESK hDesktop, 162 IN BOOL FreeOnFailure); 163 164 NTSTATUS 165 FASTCALL 166 IntResolveDesktop( 167 IN PEPROCESS Process, 168 IN PUNICODE_STRING DesktopPath, 169 IN BOOL bInherit, 170 OUT HWINSTA* phWinSta, 171 OUT HDESK* phDesktop); 172 173 NTSTATUS FASTCALL 174 IntValidateDesktopHandle( 175 HDESK Desktop, 176 KPROCESSOR_MODE AccessMode, 177 ACCESS_MASK DesiredAccess, 178 PDESKTOP *Object); 179 180 NTSTATUS 181 FASTCALL 182 IntCreateDesktop( 183 OUT HDESK* phDesktop, 184 IN POBJECT_ATTRIBUTES ObjectAttributes, 185 IN KPROCESSOR_MODE AccessMode, 186 IN PUNICODE_STRING lpszDesktopDevice OPTIONAL, 187 IN LPDEVMODEW lpdmw OPTIONAL, 188 IN DWORD dwFlags, 189 IN ACCESS_MASK dwDesiredAccess); 190 191 VOID APIENTRY UserRedrawDesktop(VOID); 192 BOOL IntRegisterShellHookWindow(HWND hWnd); 193 BOOL IntDeRegisterShellHookWindow(HWND hWnd); 194 VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam); 195 HDC FASTCALL UserGetDesktopDC(ULONG,BOOL,BOOL); 196 197 #define IntIsActiveDesktop(Desktop) \ 198 ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop)) 199 200 HWND FASTCALL IntGetMessageWindow(VOID); 201 PWND FASTCALL UserGetMessageWindow(VOID); 202 203 #if 0 204 static __inline BOOL 205 UserIsDesktopWindow(IN PWND pWnd) 206 { 207 // return (pWnd == UserGetDesktopWindow()); 208 return (pWnd && (pWnd->fnid == FNID_DESKTOP)); 209 } 210 211 static __inline BOOL 212 UserIsMessageWindow(IN PWND pWnd) 213 { 214 // return (pWnd == UserGetMessageWindow()); 215 return (pWnd && (pWnd->fnid == FNID_MESSAGEWND)); 216 } 217 #else 218 219 #define UserIsDesktopWindow(pWnd) \ 220 ((pWnd) && ((pWnd)->fnid == FNID_DESKTOP)) 221 222 #define UserIsMessageWindow(pWnd) \ 223 ((pWnd) && ((pWnd)->fnid == FNID_MESSAGEWND)) 224 225 #endif 226 227 228 static __inline PVOID 229 DesktopHeapAlloc(IN PDESKTOP Desktop, 230 IN SIZE_T Bytes) 231 { 232 return RtlAllocateHeap(Desktop->pheapDesktop, 233 HEAP_NO_SERIALIZE, 234 Bytes); 235 } 236 237 static __inline BOOL 238 DesktopHeapFree(IN PDESKTOP Desktop, 239 IN PVOID lpMem) 240 { 241 return RtlFreeHeap(Desktop->pheapDesktop, 242 HEAP_NO_SERIALIZE, 243 lpMem); 244 } 245 246 static __inline PVOID 247 DesktopHeapReAlloc(IN PDESKTOP Desktop, 248 IN PVOID lpMem, 249 IN SIZE_T Bytes) 250 { 251 #if 0 252 /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */ 253 return RtlReAllocateHeap(Desktop->pheapDesktop, 254 HEAP_NO_SERIALIZE, 255 lpMem, 256 Bytes); 257 #else 258 SIZE_T PrevSize; 259 PVOID pNew; 260 261 PrevSize = RtlSizeHeap(Desktop->pheapDesktop, 262 HEAP_NO_SERIALIZE, 263 lpMem); 264 265 if (PrevSize == Bytes) 266 return lpMem; 267 268 pNew = RtlAllocateHeap(Desktop->pheapDesktop, 269 HEAP_NO_SERIALIZE, 270 Bytes); 271 if (pNew != NULL) 272 { 273 if (PrevSize < Bytes) 274 Bytes = PrevSize; 275 276 RtlCopyMemory(pNew, 277 lpMem, 278 Bytes); 279 280 RtlFreeHeap(Desktop->pheapDesktop, 281 HEAP_NO_SERIALIZE, 282 lpMem); 283 } 284 285 return pNew; 286 #endif 287 } 288 289 static __inline ULONG_PTR 290 DesktopHeapGetUserDelta(VOID) 291 { 292 PW32HEAP_USER_MAPPING Mapping; 293 PTHREADINFO pti; 294 PPROCESSINFO W32Process; 295 PWIN32HEAP pheapDesktop; 296 ULONG_PTR Delta = 0; 297 298 pti = PsGetCurrentThreadWin32Thread(); 299 if (!pti->rpdesk) 300 return 0; 301 302 pheapDesktop = pti->rpdesk->pheapDesktop; 303 304 W32Process = PsGetCurrentProcessWin32Process(); 305 306 /* 307 * Start the search at the next mapping: skip the first entry 308 * as it must be the global user heap mapping. 309 */ 310 Mapping = W32Process->HeapMappings.Next; 311 while (Mapping != NULL) 312 { 313 if (Mapping->KernelMapping == (PVOID)pheapDesktop) 314 { 315 Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping; 316 break; 317 } 318 319 Mapping = Mapping->Next; 320 } 321 322 return Delta; 323 } 324 325 static __inline PVOID 326 DesktopHeapAddressToUser(PVOID lpMem) 327 { 328 PW32HEAP_USER_MAPPING Mapping; 329 PPROCESSINFO W32Process; 330 331 W32Process = PsGetCurrentProcessWin32Process(); 332 333 /* 334 * Start the search at the next mapping: skip the first entry 335 * as it must be the global user heap mapping. 336 */ 337 Mapping = W32Process->HeapMappings.Next; 338 while (Mapping != NULL) 339 { 340 if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping && 341 (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit) 342 { 343 return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) + 344 (ULONG_PTR)Mapping->UserMapping); 345 } 346 347 Mapping = Mapping->Next; 348 } 349 350 return NULL; 351 } 352 353 PWND FASTCALL IntGetThreadDesktopWindow(PTHREADINFO); 354 PWND FASTCALL co_GetDesktopWindow(PWND); 355 BOOL FASTCALL IntPaintDesktop(HDC); 356 BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *); 357 BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult); 358 VOID NTAPI DesktopThreadMain(VOID); 359 HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess); 360 361 /* EOF */ 362