相关联

Syntax

HHOOK SetWindowsHookEx(      

    int idHook,     HOOKPROC lpfn,     HINSTANCE hMod,     DWORD dwThreadId );

Parameters

idHook
[in] 指定要安装的钩子的类型.可以是以下一个值:
WH_CALLWNDPROC
过程
WH_CALLWNDPROCRET
过程
WH_CBT
过程
WH_DEBUG
DebugProc
WH_FOREGROUNDIDLE
Installs a hook procedure that will be called when the application's foreground thread is about to become idle. This hook is useful for performing low priority tasks during idle time. For more information, see the ForegroundIdleProc hook procedure.
WH_GETMESSAGE
过程
WH_JOURNALPLAYBACK
程序
WH_JOURNALRECORD
过程
WH_KEYBOARD
过程
WH_KEYBOARD_LL
Windows NT/2000/XP: 
过程
WH_MOUSE
过程
WH_MOUSE_LL
Windows NT/2000/XP:
过程
WH_MSGFILTER
过程
WH_SHELL
过程
WH_SYSMSGFILTER
过程
lpfn
[in] 
hMod
[in] 
NULL
dwThreadId
[in]
NULL

Return Value

如果成功,返回钩子句柄

如果失败,返回NULL



Remarks

SetWindowsHookEx can be used to inject a DLL into another process. A 32-bit DLL cannot be injected into a 64-bit process, and a 64-bit DLL cannot be injected into a 32-bit process. If an application requires the use of hooks in other processes, it is required that a 32-bit application call SetWindowsHookEx to inject a 32-bit DLL into 32-bit processes, and a 64-bit application call SetWindowsHookEx to inject a 64-bit DLL into 64-bit processes. The 32-bit and 64-bit DLLs must have different names.

An error may occur if the hMod parameter is NULL and the dwThreadId parameter is zero or specifies the identifier of a thread created by another process.

Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.

Before terminating, an application must call the UnhookWindowsHookEx function to free system resources associated with the hook.

The scope of a hook depends on the hook type. Some hooks can be set only with global scope; others can also be set for only a specific thread, as shown in the following table.

Hook Scope
WH_CALLWNDPROC Thread or global
WH_CALLWNDPROCRET Thread or global
WH_CBT Thread or global
WH_DEBUG Thread or global
WH_FOREGROUNDIDLE Thread or global
WH_GETMESSAGE Thread or global
WH_JOURNALPLAYBACK Global only
WH_JOURNALRECORD Global only
WH_KEYBOARD Thread or global
WH_KEYBOARD_LL Global only
WH_MOUSE Thread or global
WH_MOUSE_LL Global only
WH_MSGFILTER Thread or global
WH_SHELL Thread or global
WH_SYSMSGFILTER Global only

For a specified hook type, thread hooks are called first, then global hooks.

The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.

Windows 95/98/Me: SetWindowsHookEx is supported by the Microsoft Layer for Unicode (MSLU). However, it does not make conversions. To see Unicode messages, notifications, and so forth, you must subclass the window. To use this version of the API, you must add certain files to your application, as outlined in Installing and Releasing Hook Procedures.

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-08-06
  • 2021-05-31
  • 2021-04-05
  • 2021-03-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2021-11-29
  • 2022-12-23
  • 2021-09-25
  • 2021-04-11
相关资源
相似解决方案