ReactOS  0.4.15-dev-5120-gfb68e76
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 
64 
65 typedef struct _SHELL_HOOK_WINDOW
66 {
70 
71 CODE_SEG("INIT")
73 NTAPI
75 
78 IntDesktopObjectParse(IN PVOID ParseObject,
83  IN OUT PUNICODE_STRING CompleteName,
87  OUT PVOID *Object);
88 
90 NTAPI
93 
95 NTAPI
98 
100 NTAPI
103 
104 NTSTATUS
105 NTAPI
108 
111 
114 
117 
120 
123 
126 
129 
132 
135 
136 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
137  IN BOOL FreeOnFailure);
138 
139 NTSTATUS
140 FASTCALL
143  IN PUNICODE_STRING DesktopPath,
144  IN BOOL bInherit,
145  OUT HWINSTA* phWinSta,
146  OUT HDESK* phDesktop);
147 
150  HDESK Desktop,
153  PDESKTOP *Object);
154 
155 NTSTATUS
156 FASTCALL
158  OUT HDESK* phDesktop,
161  IN PUNICODE_STRING lpszDesktopDevice OPTIONAL,
162  IN LPDEVMODEW lpdmw OPTIONAL,
163  IN DWORD dwFlags,
164  IN ACCESS_MASK dwDesiredAccess);
165 
171 
172 #define IntIsActiveDesktop(Desktop) \
173  ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
174 
177 
178 #if 0
179 static __inline BOOL
181 {
182  // return (pWnd == UserGetDesktopWindow());
183  return (pWnd && (pWnd->fnid == FNID_DESKTOP));
184 }
185 
186 static __inline BOOL
188 {
189  // return (pWnd == UserGetMessageWindow());
190  return (pWnd && (pWnd->fnid == FNID_MESSAGEWND));
191 }
192 #else
193 
194 #define UserIsDesktopWindow(pWnd) \
195  ((pWnd) && ((pWnd)->fnid == FNID_DESKTOP))
196 
197 #define UserIsMessageWindow(pWnd) \
198  ((pWnd) && ((pWnd)->fnid == FNID_MESSAGEWND))
199 
200 #endif
201 
202 
203 static __inline PVOID
205  IN SIZE_T Bytes)
206 {
207  /* Desktop heap has no lock, using global user lock instead. */
209  return RtlAllocateHeap(Desktop->pheapDesktop,
211  Bytes);
212 }
213 
214 static __inline BOOL
216  IN PVOID lpMem)
217 {
218  /* Desktop heap has no lock, using global user lock instead. */
220  return RtlFreeHeap(Desktop->pheapDesktop,
222  lpMem);
223 }
224 
225 static __inline PVOID
227  IN PVOID lpMem,
228  IN SIZE_T Bytes)
229 {
230 #if 0
231  /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
232  return RtlReAllocateHeap(Desktop->pheapDesktop,
234  lpMem,
235  Bytes);
236 #else
237  SIZE_T PrevSize;
238  PVOID pNew;
239 
240  /* Desktop heap has no lock, using global user lock instead. */
242 
243  PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
245  lpMem);
246 
247  if (PrevSize == Bytes)
248  return lpMem;
249 
250  pNew = RtlAllocateHeap(Desktop->pheapDesktop,
252  Bytes);
253  if (pNew != NULL)
254  {
255  if (PrevSize < Bytes)
256  Bytes = PrevSize;
257 
258  RtlCopyMemory(pNew,
259  lpMem,
260  Bytes);
261 
262  RtlFreeHeap(Desktop->pheapDesktop,
264  lpMem);
265  }
266 
267  return pNew;
268 #endif
269 }
270 
271 static __inline ULONG_PTR
273 {
275  PTHREADINFO pti;
276  PPROCESSINFO W32Process;
277  PWIN32HEAP pheapDesktop;
278  ULONG_PTR Delta = 0;
279 
281  if (!pti->rpdesk)
282  return 0;
283 
284  pheapDesktop = pti->rpdesk->pheapDesktop;
285 
286  W32Process = PsGetCurrentProcessWin32Process();
287 
288  /*
289  * Start the search at the next mapping: skip the first entry
290  * as it must be the global user heap mapping.
291  */
292  Mapping = W32Process->HeapMappings.Next;
293  while (Mapping != NULL)
294  {
295  if (Mapping->KernelMapping == (PVOID)pheapDesktop)
296  {
297  Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping;
298  break;
299  }
300 
301  Mapping = Mapping->Next;
302  }
303 
304  return Delta;
305 }
306 
307 static __inline PVOID
309 {
311  PPROCESSINFO W32Process;
312 
313  W32Process = PsGetCurrentProcessWin32Process();
314 
315  /*
316  * Start the search at the next mapping: skip the first entry
317  * as it must be the global user heap mapping.
318  */
319  Mapping = W32Process->HeapMappings.Next;
320  while (Mapping != NULL)
321  {
322  if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping &&
323  (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit)
324  {
325  return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) +
326  (ULONG_PTR)Mapping->UserMapping);
327  }
328 
329  Mapping = Mapping->Next;
330  }
331 
332  return NULL;
333 }
334 
341 HDESK UserOpenInputDesktop(DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess);
342 
343 /* 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:1546
#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:226
HDC FASTCALL IntGetScreenDC(VOID)
Definition: winsta.c:371
_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:194
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
NTSTATUS FASTCALL IntHideDesktop(PDESKTOP Desktop)
Definition: desktop.c:1635
PMENU spmenuDialogSys
Definition: desktop.h:15
PMENU spmenuSys
Definition: desktop.h:14
DWORD_PTR dwDesktopId
Definition: desktop.h:13
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:124
NTSTATUS NTAPI IntDesktopOkToClose(_In_ PVOID Parameters)
Definition: desktop.c:186
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:1366
static HDC
Definition: imagelist.c:92
HWND FASTCALL IntGetMessageWindow(VOID)
Definition: desktop.c:1399
LIST_ENTRY ListEntry
Definition: desktop.h:67
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:210
BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult)
Definition: desktop.c:1525
NTSTATUS FASTCALL IntValidateDesktopHandle(HDESK Desktop, KPROCESSOR_MODE AccessMode, ACCESS_MASK DesiredAccess, PDESKTOP *Object)
Definition: desktop.c:1237
struct _SHELL_HOOK_WINDOW SHELL_HOOK_WINDOW
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1692
UINT_PTR WPARAM
Definition: windef.h:207
PCLS DesktopWindowClass
PVOID hsectionDesktop
Definition: desktop.h:22
_In_ HFONT _Out_ PUINT Height
Definition: font.h:124
#define FASTCALL
Definition: nt_native.h:50
struct _DESKTOP * rpdesk
Definition: win32.h:88
WPARAM wParam
Definition: combotst.c:138
RECT rcMouseHover
Definition: desktop.h:33
BOOL IntDeRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1784
static __inline PVOID DesktopHeapAddressToUser(PVOID lpMem)
Definition: desktop.h:308
#define FNID_MESSAGEWND
Definition: ntuser.h:843
PWND spwndTooltip
Definition: desktop.h:21
uint32_t ULONG_PTR
Definition: typedefs.h:65
PTHREADINFO gptiForeground
Definition: focus.c:15
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:204
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FNID_DESKTOP
Definition: ntuser.h:841
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:2610
PMENU spmenuVScroll
Definition: desktop.h:17
#define _In_
Definition: ms_sal.h:308
Definition: ntuser.h:548
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:1307
HDC FASTCALL UserGetDesktopDC(ULONG, BOOL, BOOL)
Definition: desktop.c:1574
BOOL IntRegisterShellHookWindow(HWND hWnd)
Definition: desktop.c:1752
#define ASSERT(a)
Definition: mode.c:44
BOOL IntSetThreadDesktop(IN HDESK hDesktop, IN BOOL FreeOnFailure)
Definition: desktop.c:3252
VOID APIENTRY UserRedrawDesktop(VOID)
Definition: desktop.c:1599
HWND FASTCALL IntGetCurrentThreadDesktopWindow(VOID)
Definition: desktop.c:1424
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:252
#define UserIsMessageWindow(pWnd)
Definition: desktop.h:197
NTSTATUS FASTCALL co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height, BOOL Redraw)
Definition: desktop.c:1617
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
Definition: ntuser.h:672
PWIN32HEAP pheapDesktop
Definition: desktop.h:23
ULONG_PTR SIZE_T
Definition: typedefs.h:80
static __inline ULONG_PTR DesktopHeapGetUserDelta(VOID)
Definition: desktop.h:272
BOOL FASTCALL IntPaintDesktop(HDC)
Definition: desktop.c:1827
HWND FASTCALL IntGetDesktopWindow(VOID)
Definition: desktop.c:1374
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:227
PWND FASTCALL IntGetThreadDesktopWindow(PTHREADINFO)
Definition: desktop.c:1359
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
BOOL FASTCALL UserIsEnteredExclusive(VOID)
Definition: ntuser.c:231
BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *)
Definition: desktop.c:1439
NTSTATUS FASTCALL IntResolveDesktop(IN PEPROCESS Process, IN PUNICODE_STRING DesktopPath, IN BOOL bInherit, OUT HWINSTA *phWinSta, OUT HDESK *phDesktop)
Definition: desktop.c:551
_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:1386
#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:2667
#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:215
LONG_PTR LRESULT
Definition: windef.h:209
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
PDESKTOP FASTCALL IntGetActiveDesktop(VOID)
Definition: desktop.c:1262
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:1319
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:2344
#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:1412
_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:155
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68