网站首页  词典首页

请输入您要查询的函数:

 

术语 setwindowshookex
释义 SetWindowsHookEx
语法:
HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
SetWindowsHookEx函数
在SetWindowsHookEx函数安装一个应用程序定义成一个钩子链钩子程序。您会安装一个钩子程序,以监测为特定类型的事件系统。这些事件相关或者与特定的线程或与调用线程的同一桌面的所有线程。
参数
idHook
[in]指定钩子程序类型的安装。此参数可以是下列值之一。
WH_CALLWNDPROC
安装一个钩子程序,监控信息系统之前,将它们发送到目的地的窗口过程。有关详细信息,请参阅CallWndProc挂钩过程。
WH_CALLWNDPROCRET
安装一个钩子程序,监控后,就由目标窗口过程处理的邮件。有关详细信息,请参阅CallWndRetProc挂钩过程。
WH_CBT
安装一个钩子程序,接收通知有用的基于计算机的培训(CBT)的申请。有关详细信息,请参阅CBTProc挂钩过程。
WH_DEBUG
安装一个钩子程序调试其他钩子程序有用。有关详细信息,请参阅DebugProc挂钩过程。
WH_FOREGROUNDIDLE
安装一个钩子程序时,将调用应用程序的前台线程即将成为闲置。这是很有用钩子在空闲的时间执行低优先级任务。有关详细信息,请参阅ForegroundIdleProc挂钩过程。
WH_GETMESSAGE
安装一个钩子程序,监测信息发布到消息队列。有关详细信息,请参阅GetMsgProc挂钩过程。
WH_JOURNALPLAYBACK
安装一个钩子程序,职位信息以前由WH_JOURNALRECORD挂钩过程记录下来。有关详细信息,请参阅JournalPlaybackProc挂钩过程。
WH_JOURNALRECORD
安装一个钩子程序,记录输入的信息发送到系统的消息队列。此挂钩可用于录制宏。有关详细信息,请参阅JournalRecordProc挂钩过程。
WH_KEYBOARD
安装一个钩子程序,监控击键信息。有关详细信息,请参阅KeyboardProc挂钩过程。
WH_KEYBOARD_LL
Windows NT/2000/XP的:安装一个钩子程序,监控低级键盘输入事件。有关详细信息,请参阅LowLevelKeyboardProc挂钩过程。
WH_MOUSE
安装一个钩子程序,监视鼠标消息。有关详细信息,请参阅MouseProc挂钩过程。
WH_MOUSE_LL
Windows NT/2000/XP的:安装一个钩子程序,监控低级别鼠标输入事件。有关详细信息,请参阅LowLevelMouseProc挂钩过程。
WH_MSGFILTER
安装一个钩子程序,监控信息,作为一个输入事件在对话框中产生的结果,消息框,菜单或滚动条。有关详细信息,请参阅MessageProc挂钩过程。
WH_SHELL
安装一个钩子程序,接收通知有用的外壳应用程序。有关详细信息,请参阅ShellProc挂钩过程。
WH_SYSMSGFILTER
安装一个钩子程序,监控信息,作为一个输入事件在对话框中产生的结果,消息框,菜单或滚动条。挂钩过程监视在与调用线程的应用程序相同的桌面上所有这些消息。有关详细信息,请参阅SysMsgProc挂钩过程。
lpfn
[in]指向挂钩过程。如果dwThreadId参数为零或指定一个不同的进程创建一个线程标识符,lpfn参数必须指向一个钩子程序的DLL。否则,lpfn可以指向一个与当前进程关联的代码挂钩过程。
hMod
[in]句柄的DLL包含钩子程序指向的lpfn参数。该hMod参数必须设置为NULL,如果dwThreadId参数指定的当前进程创建一个线程,如果挂钩过程中与当前进程相关的代码。
dwThreadId
[in]指定的线程与该挂钩过程要关联的标识符。如果此参数为0,钩子程序与在与同一桌面调用线程运行的所有现有的线程。
返回值
如果函数成功,返回值是句柄挂钩过程。
如果函数失败,返回值为NULL。为了获得更多错误信息,调用GetLastError。
备注
SetWindowsHookEx函数可用于另一个进程中注入一个DLL。 32位元DLL不能注射到64位进程,和64位DLL不能成为一个32位进程注入。如果应用程序需要使用其他进程挂钩,它需要一个32位应用程序调用SetWindowsHookEx注入32 1 32位DLL位进程,和64位应用程序调用SetWindowsHookEx注入64位DLL文件到64位进程。 32位和64位DLL必须有不同的名字。
可能会出现错误,如果hMod参数为NULL和dwThreadId参数是零,或者指定由另一个进程创建的线程标识符。
调用CallNextHookEx函数链的下一个钩子程序是可选的,但强烈建议,否则,已安装的其他应用程序挂钩钩将不会收到通知,并可能表现为一个结果不正确。您应该调用CallNextHookEx,除非您绝对需要,以防止被其他应用程序的通知。
终止前,应用程序必须调用UnhookWindowsHookEx函数来释放系统,与此挂钩关联的资源。
一个钩的范围取决于挂钩类型。有些挂钩只能与全球范围的设置,其他人也可以设置只特定的线程,如下表所示。
HookScope
WH_CALLWNDPROCThread或全球
WH_CALLWNDPROCRETThread或全球
WH_CBTThread或全球
WH_DEBUGThread或全球
WH_FOREGROUNDIDLEThread或全球
WH_GETMESSAGEThread或全球
WH_JOURNALPLAYBACKGlobal只
WH_JOURNALRECORDGlobal只
WH_KEYBOARDThread或全球
WH_KEYBOARD_LLGlobal只
WH_MOUSEThread或全球
WH_MOUSE_LLGlobal只
WH_MSGFILTERThread或全球
WH_SHELLThread或全球
WH_SYSMSGFILTERGlobal只
指定钩子钩型,线钩被称为第一次,那么全球。
全球挂钩是一个共享资源,并安装一个影响与调用线程相同的桌面上所有的应用程序。全球所有的钩子函数必须是在库。全球钩应仅限于特殊用途的应用程序,或将应用程序调试期间的发展援助。库不再需要一个钩子应该删除其挂钩过程。
在Windows 95/98/Me:SetWindowsHookEx函数是支持的Unicode(MSLU)微软层。然而,它不会使转换。要查看Unicode的消息,通知等等,您必须子窗口。要使用此API的版本,您必须添加一些文件到您的应用程序,在安装和释放钩子程序概述。
例如
有关示例,请参阅安装和释放钩子程序。
功能信息
最低DLL版本 user32.dll
在Winuser.h中HeaderDeclared,头文件:winuser.h
import libraryUser32.lib
最低操作系统Windows 95,Windows NT 3.1时,Windows 7
UnicodeImplemented为ANSI和Unicode版本。
参见
钩概述,CallNextHookEx,CallWndProc,CallWndRetProc,CBTProc,DebugProc,ForegroundIdleProc,GetMsgProc,JournalPlaybackProc,JournalRecordProc,LowLevelKeyboardProc,LowLevelMouseProc,KeyboardProc,MouseProc,MessageProc,ShellProc,SysMsgProc,UnhookWindowsHookEx
==英文原文==SetWindowsHookEx Function
The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.
Syntax
HHOOK SetWindowsHookEx( int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
Parameters
idHook
[in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
WH_CALLWNDPROC
Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
WH_CALLWNDPROCRET
Installs a hook procedure that monitors messages after they have been processed by the destination window procedure. For more information, see the CallWndRetProc hook procedure.
WH_CBT
Installs a hook procedure that receives notifications useful to a computer-based training (CBT) application. For more information, see the CBTProc hook procedure.
WH_DEBUG
Installs a hook procedure useful for debugging other hook procedures. For more information, see the DebugProc hook procedure.
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
Installs a hook procedure that monitors messages posted to a message queue. For more information, see the GetMsgProc hook procedure.
WH_JOURNALPLAYBACK
Installs a hook procedure that posts messages previously recorded by a WH_JOURNALRECORD hook procedure. For more information, see the JournalPlaybackProc hook procedure.
WH_JOURNALRECORD
Installs a hook procedure that records input messages posted to the system message queue. This hook is useful for recording macros. For more information, see the JournalRecordProc hook procedure.
WH_KEYBOARD
Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
WH_KEYBOARD_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
WH_MOUSE
Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
WH_MOUSE_LL
Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.
WH_MSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. For more information, see the MessageProc hook procedure.
WH_SHELL
Installs a hook procedure that receives notifications useful to shell applications. For more information, see the ShellProc hook procedure.
WH_SYSMSGFILTER
Installs a hook procedure that monitors messages generated as a result of an input event in a dialog box, message box, menu, or scroll bar. The hook procedure monitors these messages for all applications in the same desktop as the calling thread. For more information, see the SysMsgProc hook procedure.
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a DLL. Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
Return Value
If the function succeeds, the return value is the handle to the hook procedure.
If the function fails, the return value is NULL. To get extended error information, call GetLastError .
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.
HookScope
WH_CALLWNDPROCThread or global
WH_CALLWNDPROCRETThread or global
WH_CBTThread or global
WH_DEBUGThread or global
WH_FOREGROUNDIDLEThread or global
WH_GETMESSAGEThread or global
WH_JOURNALPLAYBACKGlobal only
WH_JOURNALRECORDGlobal only
WH_KEYBOARDThread or global
WH_KEYBOARD_LLGlobal only
WH_MOUSEThread or global
WH_MOUSE_LLGlobal only
WH_MSGFILTERThread or global
WH_SHELLThread or global
WH_SYSMSGFILTERGlobal 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 .
Example
For an example, see Installing and Releasing Hook Procedures .
Function Information
Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systemsWindows 95, Windows NT 3.1, Windows 7
UnicodeImplemented as ANSI and Unicode versions.
See Also
Hooks Overview , CallNextHookEx , CallWndProc , CallWndRetProc , CBTProc , DebugProc , ForegroundIdleProc , GetMsgProc , JournalPlaybackProc , JournalRecordProc , LowLevelKeyboardProc , LowLevelMouseProc , KeyboardProc , MouseProc , MessageProc , ShellProc , SysMsgProc , UnhookWindowsHookEx
==原始网址==http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:17:48