Interface Development (ii)---NativeWindow

Source: Internet
Author: User

NativeWindow is a low-level class provided by the. NET Framework. Microsoft's official explanation is: NativeWindow provides a low-level encapsulation of a window handle and a window procedure. Said these also is equivalent not to say, because Nativewi What Ndow is doing is not clear, it means a lower level. A package of form handles and form procedures. Later, a lot of information was queried to understand the meaning.

Source of information:

Http://www.diybl.com/course/4_webprogram/asp.net/netjs/2007921/72804.html

This explanation is "use NativeWindow monitor WndProc message", this content is relatively long, and more pages, after their own efforts and patience, finally completed the example, the code download address: HTTP://FILES.CNBLOGS.COM/ZHJP11 /Skin/nativewindowapplication.rar

Http://www.codeproject.com/KB/dialog/OpenFileDialogEx.aspx

This article from CodeProject, foreigners write code is more level. The OpenFileDialog subclass of Windows is displayed as a custom OpenFileDialog, and many events are added. Quite a admiration.

After these two carefully read, finally understand the role of NativeWindow, NativeWindow is to provide the bottom of the package, providing the Assignhandle and realesehandle these two methods, mainly to register the form handle the form into Line hook, which processes the events of the form to the Windows processing. Using Refector.net to view the method of Assignhandle in NativeWindow, it also validates my claim. There is a section of code in Assignhandle:

Userdefwindowproc = unsafenativemethods.getprocaddress (New HandleRef (Null,unsafenativemethods.getmodulehandle (" User32.dll ")), lpprocname);

The development of Win32 may know the meaning of this code, he is also a kind of hook. It's just a more advanced way of hook. Here is not to elaborate, we now only know that he can register our registered form to hook, you can load their own code to the location we want it.

Then I use NativeWindow to get all the events of all the forms, and then output the hook to the time, the results are as follows:

This article supporting source code

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.