Interface development (i)---hook all the forms

Source: Internet
Author: User

This beginning, I began to explain the whole process of my interface development, step-by-step explanation of the development of the interface process, this article is mainly about hook programming, hook all the forms.

Hook, for most programmers, the word is not unfamiliar. For Windows systems, message messages are passed through the entire system, which is simply an integer and has a corresponding meaning. In C + + Winuser.h, we can see a lot of the message we use. Hook and message is inseparable, it is the Chinese interpretation is "hook", is the monitoring system message transmission, that is, in messages passed to the final word processing, the specific information processing.

For hooks, the main 3 API functions are in the User32.dll file, and these three functions are:

Hook

1///<summary>
2///SetWindowsHookEx
3///</summary>
4         <param name= "Idhook" ></param>
5///<param name= "LPFN" ></PARAM>
6         <param name= "Hmod" ></param>
7///<param name= "dwThreadID" ></PARAM>
8 <returns></returns>
9 [DllImport ("User32.dll", CharSet = CharSet.Auto)]
Pub Lic static extern IntPtr SetWindowsHookEx (int idhook, hookproc lpfn, int hmod, int dwthreadid);          
One
///<summary>
///callnexthookex
///</summary>
15         <param name= "HHK" ></PARAM>
///<param name= "ncode" ></PARAM>
17         <param name= "WParam" ></PARAM>
///<param name= "LParam" ></PARAM>
19 <returns></returns>,
20 [DllImport ("User32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr CallNextHookEx Tptr hhk, int ncode, IntPtr wParam, IntPtr lParam);

///<summary>
///unhookwindowshookex
///</summary>
         ///<param name= "hhk" ></PARAM>
///<returns></returns>
28 [DllImport ("User32.dll", CharSet = CharSet.Auto)]
public static extern bool UnhookWindowsHookEx (IntPtr hhk);

The three methods are to add hooks, release hooks, and execute the next hook. The parameters of which do not need to introduce, the Internet has a lot of information on this.

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.