SetWindowsHookEx 详解(四)所有结构体

MOUSEHOOKSTRUCT structure

Contains information about a mouse event passed to a WH_MOUSE hook procedure, MouseProc.

Syntax

C++
typedef struct tagMOUSEHOOKSTRUCT {
  POINT     pt;
  HWND      hwnd;
  UINT      wHitTestCode;
  ULONG_PTR dwExtraInfo;
} MOUSEHOOKSTRUCT, *PMOUSEHOOKSTRUCT, *LPMOUSEHOOKSTRUCT;

Members

pt

Type: POINT

The x- and y-coordinates of the cursor, in screen coordinates.

hwnd

Type: HWND

A handle to the window that will receive the mouse message corresponding to the mouse event.

wHitTestCode

Type: UINT

The hit-test value. For a list of hit-test values, see the description of the WM_NCHITTEST message.

dwExtraInfo

Type: ULONG_PTR

Additional information associated with the message.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

MSLLHOOKSTRUCT structure

Contains information about a low-level mouse input event.

Syntax

C++
typedef struct tagMSLLHOOKSTRUCT {
  POINT     pt;
  DWORD     mouseData;
  DWORD     flags;
  DWORD     time;
  ULONG_PTR dwExtraInfo;
} MSLLHOOKSTRUCT, *PMSLLHOOKSTRUCT, *LPMSLLHOOKSTRUCT;

Members

pt

Type: POINT

The x- and y-coordinates of the cursor, in screen coordinates.

mouseData

Type: DWORD

If the message is WM_MOUSEWHEEL, the high-order word of this member is the wheel delta. The low-order word is reserved. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.

If the message is WM_XBUTTONDOWNWM_XBUTTONUPWM_XBUTTONDBLCLK,WM_NCXBUTTONDOWNWM_NCXBUTTONUP, or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released, and the low-order word is reserved. This value can be one or more of the following values. Otherwise, mouseData is not used.

ValueMeaning
XBUTTON1 0x0001

The first X button was pressed or released.

XBUTTON2 0x0002

The second X button was pressed or released.

 

flags

Type: DWORD

The event-injected flags. An application can use the following values to test the flags. Testing LLMHF_INJECTED (bit 0) will tell you whether the event was injected. If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the event was injected from a process running at lower integrity level.

ValueMeaning
LLMHF_INJECTED 0x00000001

Test the event-injected (from any process) flag.

LLMHF_LOWER_IL_INJECTED 0x00000002

Test the event-injected (from a process running at lower integrity level) flag.

 

time

Type: DWORD

The time stamp for this message.

dwExtraInfo

Type: ULONG_PTR

Additional information associated with the message.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

MSG structure

Contains message information from a thread's message queue.

Syntax

C++
typedef struct tagMSG {
  HWND   hwnd;
  UINT   message;
  WPARAM wParam;
  LPARAM lParam;
  DWORD  time;
  POINT  pt;
} MSG, *PMSG, *LPMSG;

Members

hwnd

Type: HWND

A handle to the window whose window procedure receives the message. This member is NULL when the message is a thread message.

message

Type: UINT

The message identifier. Applications can only use the low word; the high word is reserved by the system.

wParam

Type: WPARAM

Additional information about the message. The exact meaning depends on the value of the messagemember.

lParam

Type: LPARAM

Additional information about the message. The exact meaning depends on the value of the messagemember.

time

Type: DWORD

The time at which the message was posted.

pt

Type: POINT

The cursor position, in screen coordinates, when the message was posted.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps | Windows Store apps]

Minimum supported server

Windows 2000 Server [desktop apps | Windows Store apps]

Header

Winuser.h (include Windows.h)

RECT structure

The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

Syntax

C++
typedef struct _RECT {
  LONG left;
  LONG top;
  LONG right;
  LONG bottom;
} RECT, *PRECT;

Members

left

The x-coordinate of the upper-left corner of the rectangle.

top

The y-coordinate of the upper-left corner of the rectangle.

right

The x-coordinate of the lower-right corner of the rectangle.

bottom

The y-coordinate of the lower-right corner of the rectangle.

Remarks

By convention, the right and bottom edges of the rectangle are normally considered exclusive. In other words, the pixel whose coordinates are ( rightbottom ) lies immediately outside of the rectangle. For example, whenRECT is passed to the FillRect function, the rectangle is filled up to, but not including, the right column and bottom row of pixels. This structure is identical to the RECTL structure.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Windef.h (include Windows.h)

EVENTMSG structure

Contains information about a hardware message sent to the system message queue. This structure is used to store message information for the JournalPlaybackProc callback function.

Syntax

C++
typedef struct tagEVENTMSG {
  UINT  message;
  UINT  paramL;
  UINT  paramH;
  DWORD time;
  HWND  hwnd;
} EVENTMSG, *PEVENTMSG, *LPEVENTMSG;

Members

message

Type: UINT

The message.

paramL

Type: UINT

Additional information about the message. The exact meaning depends on the message value.

paramH

Type: UINT

Additional information about the message. The exact meaning depends on the message value.

time

Type: DWORD

The time at which the message was posted.

hwnd

Type: HWND

A handle to the window to which the message was posted.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

KBDLLHOOKSTRUCT structure

Contains information about a low-level keyboard input event.

Syntax

C++
typedef struct tagKBDLLHOOKSTRUCT {
  DWORD     vkCode;
  DWORD     scanCode;
  DWORD     flags;
  DWORD     time;
  ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT, *LPKBDLLHOOKSTRUCT;

Members

vkCode

Type: DWORD

virtual-key code. The code must be a value in the range 1 to 254.

scanCode

Type: DWORD

A hardware scan code for the key.

flags

Type: DWORD

The extended-key flag, event-injected flags, context code, and transition-state flag. This member is specified as follows. An application can use the following values to test the keystroke flags. Testing LLKHF_INJECTED (bit 4) will tell you whether the event was injected. If it was, then testing LLKHF_LOWER_IL_INJECTED (bit 1) will tell you whether or not the event was injected from a process running at lower integrity level.

ValueMeaning
LLKHF_EXTENDED (KF_EXTENDED >> 8)

Test the extended-key flag.

LLKHF_LOWER_IL_INJECTED 0x00000002

Test the event-injected (from a process running at lower integrity level) flag.

LLKHF_INJECTED 0x00000010

Test the event-injected (from any process) flag.

LLKHF_ALTDOWN (KF_ALTDOWN >> 8)

Test the context code.

LLKHF_UP (KF_UP >> 8)

Test the transition-state flag.

 

The following table describes the layout of this value.

BitsDescription
0Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
1Specifies whether the event was injected from a process running at lower integrity level. The value is 1 if that is the case; otherwise, it is 0. Note that bit 4 is also set whenever bit 1 is set.
2-3Reserved.
4Specifies whether the event was injected. The value is 1 if that is the case; otherwise, it is 0. Note that bit 1 is not necessarily set when bit 4 is set.
5The context code. The value is 1 if the ALT key is pressed; otherwise, it is 0.
6Reserved.
7The transition state. The value is 0 if the key is pressed and 1 if it is being released.

 

time

Type: DWORD

The time stamp for this message, equivalent to what GetMessageTime would return for this message.

dwExtraInfo

Type: ULONG_PTR

Additional information associated with the message.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

CWPSTRUCT structure

Defines the message parameters passed to a WH_CALLWNDPROC hook procedure, CallWndProc.

Syntax

C++
typedef struct tagCWPSTRUCT {
  LPARAM lParam;
  WPARAM wParam;
  UINT   message;
  HWND   hwnd;
} CWPSTRUCT, *PCWPSTRUCT, *LPCWPSTRUCT;

Members

lParam

Type: LPARAM

Additional information about the message. The exact meaning depends on the message value.

wParam

Type: WPARAM

Additional information about the message. The exact meaning depends on the message value.

message

Type: UINT

The message.

hwnd

Type: HWND

A handle to the window to receive the message.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

CWPRETSTRUCT structure

Defines the message parameters passed to a WH_CALLWNDPROCRET hook procedure, CallWndRetProc.

Syntax

C++
typedef struct tagCWPRETSTRUCT {
  LRESULT lResult;
  LPARAM  lParam;
  WPARAM  wParam;
  UINT    message;
  HWND    hwnd;
} CWPRETSTRUCT, *PCWPRETSTRUCT, *LPCWPRETSTRUCT;

Members

lResult

Type: LRESULT

The return value of the window procedure that processed the message specified by the message value.

lParam

Type: LPARAM

Additional information about the message. The exact meaning depends on the message value.

wParam

Type: WPARAM

Additional information about the message. The exact meaning depends on the message value.

message

Type: UINT

The message.

hwnd

Type: HWND

A handle to the window that processed the message specified by the message value.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

CBT_CREATEWND structure

Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.

Syntax

C++
typedef struct tagCBT_CREATEWND {
  LPCREATESTRUCT lpcs;
  HWND           hwndInsertAfter;
} CBT_CREATEWND, *LPCBT_CREATEWND;

Members

lpcs

Type: LPCREATESTRUCT

A pointer to a CREATESTRUCT structure that contains initialization parameters for the window about to be created.

hwndInsertAfter

Type: HWND

A handle to the window whose position in the Z order precedes that of the window being created. This member can also be NULL.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Unicode and ANSI names

CBT_CREATEWNDW (Unicode) and CBT_CREATEWNDA (ANSI)

CBTACTIVATESTRUCT structure

Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is activated.

Syntax

C++
typedef struct tagCBTACTIVATESTRUCT {
  BOOL fMouse;
  HWND hWndActive;
} CBTACTIVATESTRUCT, *LPCBTACTIVATESTRUCT;

Members

fMouse

Type: BOOL

This member is TRUE if a mouse click is causing the activation or FALSE if it is not.

hWndActive

Type: HWND

A handle to the active window.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

CBT_CREATEWND structure

Contains information passed to a WH_CBT hook procedure, CBTProc, before a window is created.

Syntax

C++
typedef struct tagCBT_CREATEWND {
  LPCREATESTRUCT lpcs;
  HWND           hwndInsertAfter;
} CBT_CREATEWND, *LPCBT_CREATEWND;

Members

lpcs

Type: LPCREATESTRUCT

A pointer to a CREATESTRUCT structure that contains initialization parameters for the window about to be created.

hwndInsertAfter

Type: HWND

A handle to the window whose position in the Z order precedes that of the window being created. This member can also be NULL.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Unicode and ANSI names

CBT_CREATEWNDW (Unicode) and CBT_CREATEWNDA (ANSI)

DEBUGHOOKINFO structure

Contains debugging information passed to a WH_DEBUG hook procedure, DebugProc.

Syntax

C++
typedef struct tagDEBUGHOOKINFO {
  DWORD  idThread;
  DWORD  idThreadInstaller;
  LPARAM lParam;
  WPARAM wParam;
  int    code;
} DEBUGHOOKINFO, *PDEBUGHOOKINFO, *LPDEBUGHOOKINFO;

Members

idThread

Type: DWORD

A handle to the thread containing the filter function.

idThreadInstaller

Type: DWORD

A handle to the thread that installed the debugging filter function.

lParam

Type: LPARAM

The value to be passed to the hook in the lParam parameter of the DebugProc callback function.

wParam

Type: WPARAM

The value to be passed to the hook in the wParam parameter of the DebugProc callback function.

code

Type: int

The value to be passed to the hook in the nCode parameter of the DebugProc callback function.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`SetWindowsHookEx`是一个Windows API函数,用于安装一个全局的或局部的钩子函数。该函数可以用于截获和处理系统和应用程序的消息和事件,比如键盘、鼠标、消息等。使用钩子函数可以实现一些高级的功能,如键盘记录、鼠标跟踪、窗口监控等。 `SetWindowsHookEx`的函数原型如下: ```c++ HHOOK SetWindowsHookEx( int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId ); ``` 其中,参数含义如下: - `idHook`:指定需要安装的钩子类型,可以使用以下常量中的一个或多个来指定钩子类型: - `WH_KEYBOARD`:键盘钩子。 - `WH_MOUSE`:鼠标钩子。 - `WH_CALLWNDPROC`:消息钩子。 - `WH_CBT`:窗口钩子。 - `WH_GETMESSAGE`:获取消息钩子。 - `WH_JOURNALRECORD`:记录钩子。 - `WH_KEYBOARD_LL`:低级键盘钩子。 - `WH_MOUSE_LL`:低级鼠标钩子。 - `lpfn`:指定钩子函数的地址,该函数的原型为`LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)`,其中`nCode`表示钩子类型,`wParam`和`lParam`表示传递给钩子函数的消息和事件参数。钩子函数必须返回一个值,具体取决于钩子类型。 - `hMod`:指定包含钩子函数的模块的句柄,通常可以设置为NULL。 - `dwThreadId`:指定需要安装钩子的线程ID,如果为0,则表示钩子函数将被安装到系统的所有线程中,为全局钩子。 例如,以下代码安装一个键盘钩子: ```c++ HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD, HookProc, NULL, 0); ``` 需要注意的是,安装钩子函数需要有足够的权限,并且需要谨慎使用,不当的使用可能会对系统和应用程序的稳定性产生不良影响。同时,安装钩子函数后,需要在使用完毕后及时卸载,否则可能会导致钩子函数一直运行,耗费系统资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值