. Net hook type

Source: Internet
Author: User
From now on, we will introduce 15 types of all hook types. Since I am using C # Now, it is more accurate to translate all functions in the original text into "methods" and actually translate them into "functions. In the original text, "callback function" is translated as "callback function ".

Each type of hook enables an application to monitor a different aspect of the system's message-handling mechanic.

Apply each type of hookProgramMonitors different aspects of the system's message processing mechanism.

Hook type 1-2: wh_callwndproc and wh_callwndprocret hooks

The wh_callwndproc and wh_callwndprocret hooks
Enable you to monitor messages sent to window procedures. The system
Calla wh_callwndproc hook procedure before passing the message to
Processing window procedure, and callthe wh_callwndprocret hook
Procedure after the window procedure has processed the message.

Wh_callwndproc and
The wh_callwndprocret hook enables you to monitor messages sent to the window program. The system calls
Wh_callwndproc hook Child Program; after the window program finishes processing the message, it calls the wh_callwndprocret hook Child Program.

The wh_callwndprocret hook passes a pointer
A cwpretstruct structure to the hook procedure. The structure contains
The return value from the window procedure that processed the message,
As well as the message parameters associated with the message.
Subclassing the window does not work for messages set between processes.

The wh_callwndprocret hook transmits a pointer to the cwpretstruct structure to the hook Child Program. This structure contains the returned values from the window program that processes the message and the parameters in the message. The subclass form cannot process Message sets between processes.

Hook Type 3: wh_cbt hook

The system calla wh_cbt hook procedure
Before activating, creating, destroying, minimizing, maximizing,
Moving, or sizing a window; before completing a system command; before
Removing a mouse or keyboard event from the system message queue;
Before setting the input focus; or before synchronizing with the System
Message Queue. The value the hook procedure returns determines whether
The system allows or prevents one of these operations. The wh_cbt hook
Is intended primarily for computer-based training (CBT) applications.

Before the following events occur, the system will call the wh_cbt hook program:

1. The windowsill is activated, created, destroyed, minimized, maximized, moved, or changed;

2. Execute the system command;

3. Remove mouse or Keyboard Events from the system message queue;

4. Set the input focus;

5. Synchronize system message queues;

The Return Value of the hook determines whether the system permits or blocks one of these operations. Wh_cbt hooks are mainly used in computer-based exercises (CBT) programs.

Hook type 4: wh_debug hook

The system calla wh_debug hook procedure
Before calling hook procedures associated with any other hook in
System. You can use this hook to determine whether to allow the system
To call hook procedures associated with other types of hooks.

Before calling the hook program associated with any other hooks in the system, the system calls the wh_debug hook program. You can use this hook to determine whether to allow the system to call hook programs associated with other types of hooks.

Hook type 5: wh_foregroundidle hook

The wh_foregroundidle hook enables you
Perform low priority tasks during times when its foreground thread is
Idle. The system calla wh_foregroundidle hook procedure when
Application's foreground thread is about to become idle.

The wh_foregroundidle hook allows the current thread to run tasks with low permissions when idle. The system calls the wh_foregroundidle hook when the foreground thread of the application is about to be idle.

Hook type 6: wh_getmessage hook

The wh_getmessage hook enables an application
To monitor messages about to be returned by the getmessage or
Peekmessage function. You can use the wh_getmessage hook to monitor
Mouse and keyboard input and other messages posted to the message queue.

The wh_getmessage program allows applications to monitor messages that will be returned by the method getmessage or peekmessage. You can use the wh_getmessage hook to monitor mouse and keyboard input and other messages passed to the message queue.

Hook type 7: wh_journalplayback hook

The wh_journalplayback hook enables
Application to insert messages into the system message queue. You can
Use this hook to play back a series of mouse and keyboard events
Recorded earlier by using the wh_journalrecord hook. Regular mouse and
Keyboard input is disabled as long as a wh_journalplayback hook is
Installed. A wh_journalplayback hook is a global hook-it cannot be
Used as a thread-specific hook.

The wh_journalplayback hook returns a time-out
Value. This value tells the system how does milliseconds to wait before
Processing the current message from the playback hook. This enables
Hook to control the timing of the events it plays back.

The wh_journalplayback hook allows applications to insert messages to the system message queue. Use this hook to play back previously used wh_journalrecord
Hook records a series of mouse and keyboard events. After wh_journalplayback is installed, regular mouse and keyboard inputs are disabled. Wh_journalplayback
A hook is a global hook and cannot be used as a thread hook. The wh_journalplayback hook returns a timeout value. This value indicates that the system has waited much before processing the current message from the playback hook.
Milliseconds. This allows the hook to control the speed of event playback.

Hook type 8: wh_journalrecord hook

The wh_journalrecord hook enables you
Monitor and record input events. Typically, you use this hook to record
A sequence of mouse and keyboard events to play back later by using
Wh_journalplayback hook. The wh_journalrecord hook is a global hook-
It cannot be used as a thread-specific hook.

The wh_journalrecord hook allows monitoring and recording input events. Typically, this hook is used to record the mouse and keyboard events in sequence. You can use the wh_journalplayback. Hook for playback later. This is a global hook and cannot be used as a process hook.

Hook type 9: wh_keyboard_ll hook

The wh_keyboard_ll hook enables you to monitor keyboard input events about to be posted in a thread input queue.

The wh_keyboard_ll hook monitors keyboard input events to be passed in the thread input queue.

Hook type 10: wh_keyboard hook

The wh_keyboard hook enables an application
Monitor message traffic for wm_keydown and wm_keyup messages about
Be returned by the getmessage or peekmessage function. You can use
Wh_keyboard hook to monitor keyboard input posted to a message queue.

The wh_keyboard hook allows applications to monitor wm_keydown or wm_keyup messages that will be returned by the getmessage or peekmessage method. You can use the wh_keyboard hook to monitor keyboard input transmitted to the message queue.

Hook Type 11: wh_mouse_ll hook

The wh_mouse_ll hook enables you to monitor mouse input events about to be posted in a thread input queue.

The wh_mouse_ll hook monitors mouse input events that will be passed in the thread input queue.

Hook Type 12: wh_mouse hook

The wh_mouse hook enables you to monitor mouse
Messages about to be returned by the getmessage or peekmessage
Function. You can use the wh_mouse hook to monitor mouse input posted
To a message queue.

The wh_mouse hook allows you to monitor mouse messages that will be returned by the getmessage or peekmessage method. Use this hook to monitor the mouse input passed to the thread input queue.


Hook type 13, 14: wh_msgfilter and wh_sysmsgfilter hooks

The
Wh_msgfilter and wh_sysmsgfilter hooks enable you to monitor messages
About to be processed by a menu, scroll bar, message box, or dialog
Box, and to detect when a different window is about to be activated
A result of the user's pressing the Alt + TAB or Alt + ESC key combination.
The wh_msgfilter Hook can only monitor messages passed to a menu,
Scroll bar, message box, or dialog box created by the application that
Installed the hook procedure. The wh_sysmsgfilter hook monitors such
Messages for all applications.

The wh_msgfilter and wh_sysmsgfilter hooks allow you to monitor messages to be processed by menus, scroll bars, message boxes, and dialog boxes. After you press Alt + TAB or Alt + ESC, checks when a different window is activated. The wh_msgfilter Hook can only monitor messages transmitted to the menu, scroll bar, message box, or the dialog box created by the application with the hook sub-program installed. The wh_sysmsgfilter hook monitors messages of this type in all applications.

the
wh_msgfilter and wh_sysmsgfilter hooks enable you to perform message
filtering during modal loops that is equivalent to the filtering done
in the main message loop. for example, an application often examines a
New message in the main loop between the time it retrieves the message
from the queue and the time it dispatches the message, discovery Ming
special processing as appropriate. however, during a modal loop, the
system retrieves and dispatches messages without allowing an
application the chance to filter the messages in its main message loop.
If an application installa wh_msgfilter or wh_sysmsgfilter hook
procedure, the system callthe procedure during the modal loop.

Wh_msgfilter and wh_sysmsgfilter
The sub-filter allows message filtering during the mode loop, which is equivalent to filtering in the main message loop. For example, when an application receives a message from a queue to a dispatch message, it often checks the new message in the main loop.
. However, during the pattern loop, the system will receive and dispatch messages, but it does not give the application the opportunity to filter messages in the main message loop. If the wh_msgfilter or wh_sysmsgfilter hook sub-program is installed in the application, the system will call the hook sub-program during the pattern loop.

An
Application can call the wh_msgfilter hook directly by calling
Callmsgfilter function. By using this function, the application can use
The same Code to filter messages during modal loops as it uses in
Main message loop. To do so, encapsulate the filtering operations in
Wh_msgfilter hook procedure and call callmsgfilter between the callto the getmessage and dispatchmessage functions.

Applications can call the wh_msgfilter hook by calling the callmsgfilter method. By using this method, the application can use the sameCodeTo filter messages. In this case, you can encapsulate the filtering operation in the wh_msgfilter hook sub-program and call callmsgfilter during the getmessage and dispatchmessage methods.

While (getmessage (& MSG, (hwnd) null, 0, 0 ))

{

If (! Callmsgfilter (& qmsg, 0 ))

Dispatchmessage (& qmsg );

}

The last argument of callmsgfilter
Is simply passed to the hook procedure; you can enter any value.
Hook procedure, by defining a constant such as msgf_mainloop, can use
This value to determine where the procedure was called from.

The last parameter of callmsgfilter is simply passed to the hook program. You can enter any value. By defining constants like msgf_mainloop, you can use this value to determine where the hooks are called.

Hook type 15: wh_shell hook

A
Shell application can use the wh_shell hook to receive important
Events. The system cils a wh_shell hook procedure when
Shell application is about to be activated and when a top-level window
Is created or destroyed.

The shell program can use the wh_shell hook to receive important notifications. When the shelling program is about to be activated and the window at the top level is created or destroyed, the system will call the wh_shell hook sub-program.

Note
That custom shell applications do not receive wh_shell messages.
Therefore, any application that registers itself as the default shell
Must call the systemparametersinfo function
Spi_setminimizedmetrics before it (or any other application) can
Receive wh_shell messages.

Note: regular shelling programs do not receive wh_shell messages. Therefore, any application that registers itself as the default shell must call the systemparametersinfo method with spi_setminimizedmetrics before it (or any other application) can receive the wh_shell message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.