ReactOS  0.4.14-dev-599-g2d4d3f5
desktop.h
Go to the documentation of this file.
1 #pragma once
2 
3 typedef struct _DESKTOP
4 {
5  /* Must be the first member */
7 
10  /* Pointer to the associated window station. */
26 
27  /* One console input thread per desktop, maintained by CONSRV */
29 
30  /* Use for tracking mouse moves. */
35 
36  /* ReactOS */
37  /* Pointer to the active queue. */
39  /* Handle of the desktop window. */
41  /* Thread blocking input */
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 
90 
91 typedef struct _SHELL_HOOK_WINDOW
92 {
96 
97 INIT_FUNCTION
99 NTAPI
101 
102 NTSTATUS
103 APIENTRY
104 IntDesktopObjectParse(IN PVOID ParseObject,
109  IN OUT PUNICODE_STRING CompleteName,
113  OUT PVOID *Object);
114 
115 NTSTATUS
116 NTAPI
119 
120 NTSTATUS
121 NTAPI
124 
125 NTSTATUS
126 NTAPI
129 
130 NTSTATUS
131 NTAPI
134 
137 
140 
143 
146 
149 
152 
155 
157 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw);
158 
161 
162 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
163  IN BOOL FreeOnFailure);
164 
165 NTSTATUS
166 FASTCALL
169  IN PUNICODE_STRING DesktopPath,
170  IN BOOL bInherit,
171  OUT HWINSTA* phWinSta,
172  OUT HDESK* phDesktop);
173 
176  HDESK Desktop,
179  PDESKTOP *Object);
180 
181 NTSTATUS
182 FASTCALL
184  OUT HDESK* phDesktop,
187  IN PUNICODE_STRING lpszDesktopDevice OPTIONAL,
188  IN LPDEVMODEW lpdmw OPTIONAL,
189  IN DWORD dwFlags,
190  IN ACCESS_MASK dwDesiredAccess);
191 
197 
198 #define IntIsActiveDesktop(Desktop) \
199  ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
200 
203 
204 #if 0
205 static __inline BOOL
207 {
208  // return (pWnd == UserGetDesktopWindow());
209  return (pWnd && (pWnd->fnid == FNID_DESKTOP));
210 }
211 
212 static __inline BOOL
214 {
215  // return (pWnd == UserGetMessageWindow());
216  return (pWnd && (pWnd->fnid == FNID_MESSAGEWND));
217 }
218 #else
219 
220 #define UserIsDesktopWindow(pWnd) \
221  ((pWnd) && ((pWnd)->fnid == FNID_DESKTOP))
222 
223 #define UserIsMessageWindow(pWnd) \
224  ((pWnd) && ((pWnd)->fnid == FNID_MESSAGEWND))
225 
226 #endif
227 
228 
229 static __inline PVOID
231  IN SIZE_T Bytes)
232 {
233  return RtlAllocateHeap(Desktop->pheapDesktop,
235  Bytes);
236 }
237 
238 static __inline BOOL
240  IN PVOID lpMem)
241 {
242  return RtlFreeHeap(Desktop->pheapDesktop,
244  lpMem);
245 }
246 
247 static __inline PVOID
249  IN PVOID lpMem,
250  IN SIZE_T Bytes)
251 {
252 #if 0
253  /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
254  return RtlReAllocateHeap(Desktop->pheapDesktop,
256  lpMem,
257  Bytes);
258 #else
259  SIZE_T PrevSize;
260  PVOID pNew;
261 
262  PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
264  lpMem);
265 
266  if (PrevSize == Bytes)
267  return lpMem;
268 
269  pNew = RtlAllocateHeap(Desktop->pheapDesktop,
271  Bytes);
272  if (pNew != NULL)
273  {
274  if (PrevSize < Bytes)
275  Bytes = PrevSize;
276 
277  RtlCopyMemory(pNew,
278  lpMem,
279  Bytes);
280 
281  RtlFreeHeap(Desktop->pheapDesktop,
283  lpMem);
284  }
285 
286  return pNew;
287 #endif
288 }
289 
290 static __inline ULONG_PTR
292 {
294  PTHREADINFO pti;
295  PPROCESSINFO W32Process;
296  PWIN32HEAP pheapDesktop;
297  ULONG_PTR Delta = 0;
298 
300  if (!pti->rpdesk)
301  return 0;
302 
303  pheapDesktop = pti->rpdesk->pheapDesktop;
304 
305  W32Process = PsGetCurrentProcessWin32Process();
306 
307  /*
308  * Start the search at the next mapping: skip the first entry
309  * as it must be the global user heap mapping.
310  */
311  Mapping = W32Process->HeapMappings.Next;
312  while (Mapping != NULL)
313  {
314  if (Mapping->KernelMapping == (PVOID)pheapDesktop)
315  {
316  Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping;
317  break;
318  }
319 
320  Mapping = Mapping->Next;
321  }
322 
323  return Delta;
324 }
325 
326 static __inline PVOID
328 {
330  PPROCESSINFO W32Process;
331 
332  W32Process = PsGetCurrentProcessWin32Process();
333 
334  /*
335  * Start the search at the next mapping: skip the first entry
336  * as it must be the global user heap mapping.
337  */
338  Mapping = W32Process->HeapMappings.Next;
339  while (Mapping != NULL)
340  {
341  if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping &&
342  (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit)
343  {
344  return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) +
345  (ULONG_PTR)Mapping->UserMapping);
346  }
347 
348  Mapping = Mapping->Next;
349  }
350 
351  return NULL;
352 }
353 
360 HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
361 
362 /* EOF */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
ObjectType
Definition: metafile.c:80
LIST_ENTRY PtiList
Definition: desktop.h:25
VOID NTAPI DesktopThreadMain(VOID)
Definition: desktop.c:1508
#define IN
Definition: typedefs.h:38
DWORD htEx
Definition: desktop.h:32
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PDESKTOPINFO pDeskInfo
Definition: desktop.h:8
PWND spwndTrack
Definition: desktop.h:31
static __inline PVOID DesktopHeapReAlloc(IN PDESKTOP Desktop, IN PVOID lpMem, IN SIZE_T Bytes)
Definition: desktop.h:248
HDC FASTCALL IntGetScreenDC(VOID)
Definition: winsta.c:347
PMENU spmenuHScroll
Definition: desktop.h:16
#define UserIsDesktopWindow(pWnd)
Definition: desktop.h:220
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1599
PMENU spmenuDialogSys
Definition: desktop.h:15
PMENU spmenuSys
Definition: desktop.h:14
DWORD_PTR dwDesktopId
Definition: desktop.h:13
NTSTATUS NTAPI IntDesktopOkToClose(_In_ PVOID Parameters)
Definition: desktop.c:178
struct _WIN32HEAP * PWIN32HEAP
Definition: usrheap.h:3
static PVOID Mapping[EMS_PHYSICAL_PAGES]
Definition: emsdrv.c:41
DWORD dwSessionId
Definition: desktop.h:6
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
struct @1591 Msg[]
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
struct _DESKTOP * PDESKTOP
PWND FASTCALL co_GetDesktopWindow(PWND)
Definition: desktop.c:1330
static HDC
Definition: imagelist.c:92
HWND FASTCALL IntGetMessageWindow(VOID)
Definition: desktop.c:1362
LIST_ENTRY ListEntry
Definition: desktop.h:93
PWND spwndTray
Definition: desktop.h:19
PVOID BlockInputThread
Definition: desktop.h:42
HWND hWnd
Definition: settings.c:17
_In_ UINT Bytes
Definition: mmcopy.h:9
NTSTATUS NTAPI IntDesktopObjectOpen(_In_ PVOID Parameters)
Definition: desktop.c:202
BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
Definition: desktop.c:1487
NTSTATUS FASTCALL IntValidateDesktopHandle(HDESK Desktop, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PDESKTOP *Object)
Definition: desktop.c:1200
struct _SHELL_HOOK_WINDOW SHELL_HOOK_WINDOW
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1656
UINT_PTR WPARAM
Definition: windef.h:207
PCLS DesktopWindowClass
PVOID hsectionDesktop
Definition: desktop.h:22
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2561
#define FASTCALL
Definition: nt_native.h:50
struct _DESKTOP * rpdesk
Definition: win32.h:91
WPARAM wParam
Definition: combotst.c:138
RECT rcMouseHover
Definition: desktop.h:33
BOOL IntDeRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1748
static __inline PVOID DesktopHeapAddressToUser(PVOID lpMem)
Definition: desktop.h:327
#define FNID_MESSAGEWND
Definition: ntuser.h:826
PWND spwndTooltip
Definition: desktop.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:63
PTHREADINFO gptiForeground
Definition: focus.c:14
struct _USER_MESSAGE_QUEUE * ActiveMessageQueue
Definition: desktop.h:38
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static __inline PVOID DesktopHeapAlloc(IN PDESKTOP Desktop, IN SIZE_T Bytes)
Definition: desktop.h:230
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FNID_DESKTOP
Definition: ntuser.h:824
DWORD dwDTFlags
Definition: desktop.h:12
HWND DesktopWindow
Definition: desktop.h:40
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
struct _WINSTATION_OBJECT * rpwinstaParent
Definition: desktop.h:11
smooth NULL
Definition: ftsmooth.c:416
HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2572
PMENU spmenuVScroll
Definition: desktop.h:17
Definition: ntuser.h:533
LONG_PTR LPARAM
Definition: windef.h:208
W32HEAP_USER_MAPPING HeapMappings
Definition: win32.h:281
PTHREADINFO gptiDesktopThread
Definition: desktop.c:37
DWORD dwConsoleThreadId
Definition: desktop.h:28
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
PUSER_MESSAGE_QUEUE FASTCALL IntGetFocusMessageQueue(VOID)
Definition: desktop.c:1271
HDC FASTCALL UserGetDesktopDC(ULONG, BOOL, BOOL)
Definition: desktop.c:1536
BOOL IntRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1716
BOOL IntSetThreadDesktop(IN HDESK hDesktop, IN BOOL FreeOnFailure)
Definition: desktop.c:3211
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1561
HWND FASTCALL IntGetCurrentThreadDesktopWindow(VOID)
Definition: desktop.c:1386
PWND spwndMessage
Definition: desktop.h:20
unsigned long DWORD
Definition: ntddk_ex.h:95
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define UserIsMessageWindow(pWnd)
Definition: desktop.h:223
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw)
Definition: desktop.c:1581
static IUnknown Object
Definition: main.c:512
CHAR Message[80]
Definition: alive.c:5
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:414
DWORD dwMouseHoverTime
Definition: desktop.h:34
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
ULONG_PTR ulHeapSize
Definition: desktop.h:24
Definition: typedefs.h:117
NTSYSAPI SIZE_T NTAPI RtlSizeHeap(_In_ PVOID HeapHandle, _In_ ULONG Flags, _In_ PVOID MemoryPointer)
uint32_t DWORD_PTR
Definition: typedefs.h:63
PWND spwndForeground
Definition: desktop.h:18
PDESKTOP gpdeskInputDesktop
Definition: desktop.c:35
#define _In_
Definition: no_sal2.h:204
Definition: ntuser.h:657
PWIN32HEAP pheapDesktop
Definition: desktop.h:23
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
static __inline ULONG_PTR DesktopHeapGetUserDelta(VOID)
Definition: desktop.h:291
BOOL FASTCALL IntPaintDesktop(HDC)
Definition: desktop.c:1791
HWND FASTCALL IntGetDesktopWindow(VOID)
Definition: desktop.c:1338
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
static ULONG Delta
Definition: xboxvideo.c:32
PKEVENT gpDesktopThreadStartedEvent
Definition: desktop.c:39
struct _DESKTOP DESKTOP
NTSTATUS NTAPI IntDesktopObjectClose(_In_ PVOID Parameters)
Definition: desktop.c:215
PWND FASTCALL IntGetThreadDesktopWindow(PTHREADINFO)
Definition: desktop.c:1323
unsigned int UINT
Definition: ndis.h:50
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *)
Definition: desktop.c:1401
NTSTATUS FASTCALL IntResolveDesktop(IN PEPROCESS Process, IN PUNICODE_STRING DesktopPath, IN BOOL bInherit, OUT HWINSTA *phWinSta, OUT HDESK *phDesktop)
Definition: desktop.c:535
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PWND FASTCALL UserGetDesktopWindow(VOID)
Definition: desktop.c:1349
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
static __inline BOOL DesktopHeapFree(IN PDESKTOP Desktop, IN PVOID lpMem)
Definition: desktop.h:239
LONG_PTR LRESULT
Definition: windef.h:209
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1226
LPARAM lParam
Definition: combotst.c:139
HDC ScreenDeviceContext
Definition: desktop.c:36
struct _W32HEAP_USER_MAPPING * Next
Definition: win32.h:194
ULONG ACCESS_MASK
Definition: nt_native.h:40
VOID FASTCALL IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue)
Definition: desktop.c:1283
NTSTATUS FASTCALL IntCreateDesktop(OUT HDESK *phDesktop, IN POBJECT_ATTRIBUTES ObjectAttributes, IN KPROCESSOR_MODE AccessMode, IN PUNICODE_STRING lpszDesktopDevice OPTIONAL, IN LPDEVMODEW lpdmw OPTIONAL, IN DWORD dwFlags, IN ACCESS_MASK dwDesiredAccess)
Definition: desktop.c:2308
#define APIENTRY
Definition: api.h:79
LIST_ENTRY ListEntry
Definition: desktop.h:9
struct _SHELL_HOOK_WINDOW * PSHELL_HOOK_WINDOW
LIST_ENTRY ShellHookWindows
Definition: desktop.h:43
PWND FASTCALL UserGetMessageWindow(VOID)
Definition: desktop.c:1374
INIT_FUNCTION NTSTATUS NTAPI InitDesktopImpl(VOID)
Definition: desktop.c:236
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:806
NTSTATUS APIENTRY IntDesktopObjectParse(IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
Definition: desktop.c:45
NTSTATUS NTAPI IntDesktopObjectDelete(_In_ PVOID Parameters)
Definition: desktop.c:147
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68