ReactOS  0.4.15-dev-1397-g19779b3
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 
98 NTAPI
100 
101 NTSTATUS
102 APIENTRY
103 IntDesktopObjectParse(IN PVOID ParseObject,
108  IN OUT PUNICODE_STRING CompleteName,
112  OUT PVOID *Object);
113 
114 NTSTATUS
115 NTAPI
118 
119 NTSTATUS
120 NTAPI
123 
124 NTSTATUS
125 NTAPI
128 
129 NTSTATUS
130 NTAPI
133 
136 
139 
142 
145 
148 
151 
154 
156 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw);
157 
160 
161 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
162  IN BOOL FreeOnFailure);
163 
164 NTSTATUS
165 FASTCALL
168  IN PUNICODE_STRING DesktopPath,
169  IN BOOL bInherit,
170  OUT HWINSTA* phWinSta,
171  OUT HDESK* phDesktop);
172 
175  HDESK Desktop,
178  PDESKTOP *Object);
179 
180 NTSTATUS
181 FASTCALL
183  OUT HDESK* phDesktop,
186  IN PUNICODE_STRING lpszDesktopDevice OPTIONAL,
187  IN LPDEVMODEW lpdmw OPTIONAL,
188  IN DWORD dwFlags,
189  IN ACCESS_MASK dwDesiredAccess);
190 
196 
197 #define IntIsActiveDesktop(Desktop) \
198  ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
199 
202 
203 #if 0
204 static __inline BOOL
206 {
207  // return (pWnd == UserGetDesktopWindow());
208  return (pWnd && (pWnd->fnid == FNID_DESKTOP));
209 }
210 
211 static __inline BOOL
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
230  IN SIZE_T Bytes)
231 {
232  return RtlAllocateHeap(Desktop->pheapDesktop,
234  Bytes);
235 }
236 
237 static __inline BOOL
239  IN PVOID lpMem)
240 {
241  return RtlFreeHeap(Desktop->pheapDesktop,
243  lpMem);
244 }
245 
246 static __inline PVOID
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,
255  lpMem,
256  Bytes);
257 #else
258  SIZE_T PrevSize;
259  PVOID pNew;
260 
261  PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
263  lpMem);
264 
265  if (PrevSize == Bytes)
266  return lpMem;
267 
268  pNew = RtlAllocateHeap(Desktop->pheapDesktop,
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,
282  lpMem);
283  }
284 
285  return pNew;
286 #endif
287 }
288 
289 static __inline ULONG_PTR
291 {
293  PTHREADINFO pti;
294  PPROCESSINFO W32Process;
295  PWIN32HEAP pheapDesktop;
296  ULONG_PTR Delta = 0;
297 
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
327 {
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 
359 HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
360 
361 /* 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:39
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
DWORD htEx
Definition: desktop.h:32
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:247
HDC FASTCALL IntGetScreenDC(VOID)
Definition: winsta.c:347
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
PMENU spmenuHScroll
Definition: desktop.h:16
#define UserIsDesktopWindow(pWnd)
Definition: desktop.h:219
#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
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
#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:326
#define FNID_MESSAGEWND
Definition: ntuser.h:826
PWND spwndTooltip
Definition: desktop.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:65
PTHREADINFO gptiForeground
Definition: focus.c:14
struct _USER_MESSAGE_QUEUE * ActiveMessageQueue
Definition: desktop.h:38
struct @1620 Msg[]
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:229
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:395
struct _WINSTATION_OBJECT * rpwinstaParent
Definition: desktop.h:11
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:282
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
NTSTATUS NTAPI InitDesktopImpl(VOID)
Definition: desktop.c:236
#define UserIsMessageWindow(pWnd)
Definition: desktop.h:222
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw)
Definition: desktop.c:1581
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_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
ULONG_PTR ulHeapSize
Definition: desktop.h:24
Definition: typedefs.h:119
NTSYSAPI SIZE_T NTAPI RtlSizeHeap(_In_ PVOID HeapHandle, _In_ ULONG Flags, _In_ PVOID MemoryPointer)
uint32_t DWORD_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
PWND spwndForeground
Definition: desktop.h:18
PDESKTOP gpdeskInputDesktop
Definition: desktop.c:35
#define _In_
Definition: no_sal2.h:158
Definition: ntuser.h:657
PWIN32HEAP pheapDesktop
Definition: desktop.h:23
ULONG_PTR SIZE_T
Definition: typedefs.h:80
static __inline ULONG_PTR DesktopHeapGetUserDelta(VOID)
Definition: desktop.h:290
BOOL FASTCALL IntPaintDesktop(HDC)
Definition: desktop.c:1791
HWND FASTCALL IntGetDesktopWindow(VOID)
Definition: desktop.c:1338
static ULONG Delta
Definition: xboxvideo.c:33
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
#define NULL
Definition: types.h:112
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:40
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2622
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
static __inline BOOL DesktopHeapFree(IN PDESKTOP Desktop, IN PVOID lpMem)
Definition: desktop.h:238
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:195
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
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:801
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