3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
32 #include <user32/callback.h>
36 /* FUNCTIONS *****************************************************************/
46 return NtUserUnhookWindowsHookEx(Hook
);
100 return NtUserCallNextHookEx(Hook
, Code
, wParam
, lParam
);
113 WCHAR ModuleName
[MAX_PATH
];
114 UNICODE_STRING USModuleName
;
118 if (0 == GetModuleFileNameW(hMod
, ModuleName
, MAX_PATH
))
122 RtlInitUnicodeString(&USModuleName
, ModuleName
);
126 RtlInitUnicodeString(&USModuleName
, NULL
);
129 return NtUserSetWindowsHookEx(hMod
, &USModuleName
, dwThreadId
, idHook
, lpfn
, bAnsi
);
137 SetWindowsHookW(int idHook
, HOOKPROC lpfn
)
139 return IntSetWindowsHook(idHook
, lpfn
, NULL
, 0, FALSE
);
147 SetWindowsHookA(int idHook
, HOOKPROC lpfn
)
149 return IntSetWindowsHook(idHook
, lpfn
, NULL
, 0, TRUE
);
157 DeregisterShellHookWindow(HWND hWnd
)
159 return NtUserCallHwnd(HWND_ROUTINE_DEREGISTERSHELLHOOKWINDOW
, (DWORD
)hWnd
);
167 RegisterShellHookWindow(HWND hWnd
)
169 return NtUserCallHwnd(HWND_ROUTINE_REGISTERSHELLHOOKWINDOW
, (DWORD
)hWnd
);
177 UnhookWindowsHook ( int nCode
, HOOKPROC pfnFilterProc
)
206 HMODULE hmodWinEventProc
,
207 WINEVENTPROC pfnWinEventProc
,
222 UnhookWinEvent ( HWINEVENTHOOK hWinEventHook
)
233 IsWinEventHookInstalled(
252 return IntSetWindowsHook(idHook
, lpfn
, hMod
, dwThreadId
, TRUE
);
267 return IntSetWindowsHook(idHook
, lpfn
, hMod
, dwThreadId
, FALSE
);
271 User32CallHookProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
273 PHOOKPROC_CALLBACK_ARGUMENTS Common
;
276 CBT_CREATEWNDW CbtCreatewndw
;
277 UNICODE_STRING UString
;
279 CBT_CREATEWNDA CbtCreatewnda
;
281 PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS CbtCreatewndExtra
;
284 PKBDLLHOOKSTRUCT KeyboardLlData
;
285 PMSLLHOOKSTRUCT MouseLlData
;
287 Common
= (PHOOKPROC_CALLBACK_ARGUMENTS
) Arguments
;
289 switch(Common
->HookId
)
295 CbtCreatewndExtra
= (PHOOKPROC_CBT_CREATEWND_EXTRA_ARGUMENTS
)
296 ((PCHAR
) Common
+ Common
->lParam
);
297 Csw
= CbtCreatewndExtra
->Cs
;
298 if (NULL
!= CbtCreatewndExtra
->Cs
.lpszName
)
300 Csw
.lpszName
= (LPCWSTR
)((PCHAR
) CbtCreatewndExtra
301 + (ULONG
) CbtCreatewndExtra
->Cs
.lpszName
);
303 if (0 != HIWORD(CbtCreatewndExtra
->Cs
.lpszClass
))
305 Csw
.lpszClass
= (LPCWSTR
)((PCHAR
) CbtCreatewndExtra
306 + LOWORD((ULONG
) CbtCreatewndExtra
->Cs
.lpszClass
));
308 wParam
= Common
->wParam
;
311 memcpy(&Csa
, &Csw
, sizeof(CREATESTRUCTW
));
312 if (NULL
!= Csw
.lpszName
)
314 RtlInitUnicodeString(&UString
, Csw
.lpszName
);
315 RtlUnicodeStringToAnsiString(&AString
, &UString
, TRUE
);
316 Csa
.lpszName
= AString
.Buffer
;
318 if (0 != HIWORD(Csw
.lpszClass
))
320 RtlInitUnicodeString(&UString
, Csw
.lpszClass
);
321 RtlUnicodeStringToAnsiString(&AString
, &UString
, TRUE
);
322 Csa
.lpszClass
= AString
.Buffer
;
324 CbtCreatewnda
.lpcs
= &Csa
;
325 CbtCreatewnda
.hwndInsertAfter
= CbtCreatewndExtra
->WndInsertAfter
;
326 lParam
= (LPARAM
) &CbtCreatewnda
;
330 CbtCreatewndw
.lpcs
= &Csw
;
331 CbtCreatewndw
.hwndInsertAfter
= CbtCreatewndExtra
->WndInsertAfter
;
332 lParam
= (LPARAM
) &CbtCreatewndw
;
336 return ZwCallbackReturn(NULL
, 0, STATUS_NOT_SUPPORTED
);
339 Result
= Common
->Proc(Common
->Code
, wParam
, lParam
);
346 if (0 != HIWORD(Csa
.lpszClass
))
348 RtlFreeHeap(GetProcessHeap(), 0, (LPSTR
) Csa
.lpszClass
);
350 if (NULL
!= Csa
.lpszName
)
352 RtlFreeHeap(GetProcessHeap(), 0, (LPSTR
) Csa
.lpszName
);
359 KeyboardLlData
= (PKBDLLHOOKSTRUCT
)((PCHAR
) Common
+ Common
->lParam
);
360 Result
= Common
->Proc(Common
->Code
, Common
->wParam
, (LPARAM
) KeyboardLlData
);
363 MouseLlData
= (PMSLLHOOKSTRUCT
)((PCHAR
) Common
+ Common
->lParam
);
364 Result
= Common
->Proc(Common
->Code
, Common
->wParam
, (LPARAM
) MouseLlData
);
367 return ZwCallbackReturn(NULL
, 0, STATUS_NOT_SUPPORTED
);
370 return ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
);