174d71ebb3bd88a417b0fc9709884c4e6f0e3979
[reactos.git] / reactos / dll / win32 / user32 / include / user32.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS System Libraries
4 * FILE: lib/user32/include/user32.h
5 * PURPOSE: Win32 User Library
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 /* C Headers */
12 #include <assert.h>
13 #include <stdio.h>
14 #include <math.h>
15
16 /* SDK/NDK Headers */
17 #define _USER32_
18 #define OEMRESOURCE
19 #define NTOS_MODE_USER
20 #define WIN32_NO_STATUS
21 #include <windows.h>
22 #include <winuser.h>
23 #include <windowsx.h>
24 #include <winnls32.h>
25 #include <ndk/ntndk.h>
26 #include <ddk/ntstatus.h>
27
28 /* CSRSS Headers */
29 #include <csrss/csrss.h>
30
31 /* Public Win32K Headers */
32 #include <win32k/ntusrtyp.h>
33 #include <win32k/ntuser.h>
34 #include <win32k/callback.h>
35
36 /* WINE Headers */
37 #include <wine/unicode.h>
38
39 /* Internal User32 Headers */
40 #include "user32p.h"
41
42 /* SEH Support with PSEH */
43 #include <pseh/pseh2.h>
44
45 #define HOOKID_TO_FLAG(HookId) (1 << ((HookId) + 1))
46 #define ISITHOOKED(HookId) (GetWin32ClientInfo()->fsHooks & HOOKID_TO_FLAG(HookId))
47
48 /* Temporarily in here for now. */
49 typedef struct _USERAPIHOOKINFO
50 {
51 DWORD m_size;
52 LPCWSTR m_dllname1;
53 LPCWSTR m_funname1;
54 LPCWSTR m_dllname2;
55 LPCWSTR m_funname2;
56 } USERAPIHOOKINFO,*PUSERAPIHOOKINFO;
57
58 typedef LRESULT(CALLBACK *WNDPROC_OWP)(HWND,UINT,WPARAM,LPARAM,ULONG_PTR,PDWORD);
59
60 typedef struct _UAHOWP
61 {
62 BYTE* MsgBitArray;
63 DWORD Size;
64 } UAHOWP, *PUAHOWP;
65
66 typedef struct tagUSERAPIHOOK
67 {
68 DWORD size;
69 WNDPROC DefWindowProcA;
70 WNDPROC DefWindowProcW;
71 UAHOWP DefWndProcArray;
72 FARPROC GetScrollInfo;
73 FARPROC SetScrollInfo;
74 FARPROC EnableScrollBar;
75 FARPROC AdjustWindowRectEx;
76 FARPROC SetWindowRgn;
77 WNDPROC_OWP PreWndProc;
78 WNDPROC_OWP PostWndProc;
79 UAHOWP WndProcArray;
80 WNDPROC_OWP PreDefDlgProc;
81 WNDPROC_OWP PostDefDlgProc;
82 UAHOWP DlgProcArray;
83 FARPROC GetSystemMetrics;
84 FARPROC SystemParametersInfoA;
85 FARPROC SystemParametersInfoW;
86 FARPROC ForceResetUserApiHook;
87 FARPROC DrawFrameControl;
88 FARPROC DrawCaption;
89 FARPROC MDIRedrawFrame;
90 FARPROC GetRealWindowOwner;
91 } USERAPIHOOK, *PUSERAPIHOOK;
92
93 typedef enum _UAPIHK
94 {
95 uahLoadInit,
96 uahStop,
97 uahShutdown
98 } UAPIHK, *PUAPIHK;
99
100 extern RTL_CRITICAL_SECTION gcsUserApiHook;
101 extern USERAPIHOOK guah;
102 typedef DWORD (CALLBACK * USERAPIHOOKPROC)(UAPIHK State, ULONG_PTR Info);
103 BOOL FASTCALL BeginIfHookedUserApiHook(VOID);
104 BOOL FASTCALL EndUserApiHook(VOID);
105 BOOL FASTCALL IsInsideUserApiHook(VOID);
106 VOID FASTCALL ResetUserApiHook(PUSERAPIHOOK);
107 BOOL FASTCALL IsMsgOverride(UINT,PUAHOWP);
108
109 #define LOADUSERAPIHOOK \
110 if (!gfServerProcess && \
111 !IsInsideUserApiHook() && \
112 (gpsi->dwSRVIFlags & SRVINFO_APIHOOK) && \
113 !RtlIsThreadWithinLoaderCallout()) \
114 { \
115 NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK); \
116 } \
117
118 /* FIXME: Use ntgdi.h then cleanup... */
119 LONG WINAPI GdiGetCharDimensions(HDC, LPTEXTMETRICW, LONG *);
120 BOOL FASTCALL IsMetaFile(HDC);
121
122 extern PPROCESSINFO g_ppi;
123 extern ULONG_PTR g_ulSharedDelta;
124 extern PSERVERINFO gpsi;
125 extern BOOL gfServerProcess;
126
127 static __inline PVOID
128 SharedPtrToUser(PVOID Ptr)
129 {
130 ASSERT(Ptr != NULL);
131 ASSERT(g_ulSharedDelta != 0);
132 return (PVOID)((ULONG_PTR)Ptr - g_ulSharedDelta);
133 }
134
135 static __inline PVOID
136 DesktopPtrToUser(PVOID Ptr)
137 {
138 PCLIENTINFO pci;
139 PDESKTOPINFO pdi;
140 GetW32ThreadInfo();
141 pci = GetWin32ClientInfo();
142 pdi = pci->pDeskInfo;
143
144 ASSERT(Ptr != NULL);
145 ASSERT(pdi != NULL);
146 if ((ULONG_PTR)Ptr >= (ULONG_PTR)pdi->pvDesktopBase &&
147 (ULONG_PTR)Ptr < (ULONG_PTR)pdi->pvDesktopLimit)
148 {
149 return (PVOID)((ULONG_PTR)Ptr - pci->ulClientDelta);
150 }
151 else
152 {
153 /* NOTE: This is slow as it requires a call to win32k. This should only be
154 neccessary if a thread wants to access an object on a different
155 desktop */
156 return NtUserGetDesktopMapping(Ptr);
157 }
158 }
159
160 static __inline PVOID
161 SharedPtrToKernel(PVOID Ptr)
162 {
163 ASSERT(Ptr != NULL);
164 ASSERT(g_ulSharedDelta != 0);
165 return (PVOID)((ULONG_PTR)Ptr + g_ulSharedDelta);
166 }
167
168 static __inline BOOL
169 IsThreadHooked(PCLIENTINFO pci)
170 {
171 return pci->fsHooks != 0;
172 }
173
174 static __inline PDESKTOPINFO
175 GetThreadDesktopInfo(VOID)
176 {
177 PTHREADINFO ti;
178 PDESKTOPINFO di = NULL;
179
180 ti = GetW32ThreadInfo();
181 if (ti != NULL)
182 di = GetWin32ClientInfo()->pDeskInfo;
183
184 return di;
185 }
186
187 PCALLPROCDATA FASTCALL ValidateCallProc(HANDLE hCallProc);
188 PWND FASTCALL ValidateHwnd(HWND hwnd);
189 PWND FASTCALL ValidateHwndOrDesk(HWND hwnd);
190 PWND FASTCALL GetThreadDesktopWnd(VOID);
191 PVOID FASTCALL ValidateHandleNoErr(HANDLE handle, UINT uType);
192 PWND FASTCALL ValidateHwndNoErr(HWND hwnd);
193 VOID FASTCALL GetConnected(VOID);
194 BOOL FASTCALL DefSetText(HWND hWnd, PCWSTR String, BOOL Ansi);
195 BOOL FASTCALL TestWindowProcess(PWND);
196 VOID UserGetWindowBorders(DWORD, DWORD, SIZE *, BOOL);