惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 比尔盖房

USACO: Section 1.5 -- PROB Prime Palindromes USACO: Section 1.5 -- PROB Number Triangles USACO: Section 1.4 -- PROB Arithmetic Progressions USACO: Section 1.3 -- PROB Prime Cryptarithm USACO: Section 1.3 -- PROB Barn Repair USACO: Section 1.3 -- PROB Mixing Milk USACO: Section 1.2 -- PROB Dual Palindromes USACO: Section 1.2 -- PROB Palindromic Squares Programming Pearls: Chatper3 Problem6 [Form letter generator] Programming Pearls: Chatper3 Problem5 [Hyphenation Words] Programming Pearls: Chatper3 Problem4 [Dates Caculation] Programming Pearls: Chatper3 Problem3 [Print Banner] Studying Probability Theory Studying "Concrete Mathematics" Studying "Introduction to Algorithms" Testing SEH tips How DebuggerRCThread is lauched? Public Symbols vs Private Symbols[zt] .Net Windows Service
The magic of NativeWindow-- How does .Net Winform manage Win32 controls
比尔盖房 · 2006-08-12 · via 博客园 - 比尔盖房

1. Every .Net winform control inherits from System.Windows.Forms.Control class. In its constructor, you will see this key statement:

public Control()
{

      
this.window = new Control.ControlNativeWindow(this);

}


This statement will assign the control's reference to System.Windows.Forms.Control.ControlNativeWindow class.

ControlNativeWindow inherits from NativeWindow class and is designed to manage the messages of the assigned control.

2. Whenever a handle is needed for that control, Control.CreateControl method is called. And it internally will invoke its associated ControlNativeWindow.CreateHandle method with prepared CreateParams as parameter.

ControlNativeWindow.CreateHandle method first invokes System.Windows.Forms.NativeWindow.WindowClass.Create static method, which internally calls RegisterClass win32 API to register the native control class. The key point here is that the WindowClass.Callback method is stored in WNDCLASS structure as the default WndProc of registed class. Then it invokes CreateWindowEx win32 API to create the underlying win32 control.

3. When the WindowClass.Callback is called the first time, it will immediately call SetWindowLong to native DefWindowProc and then call its parent NativeWindow.AssignHandle method to start the subclass again.(NativeWindow.AssignHandle again first stores the

DefWindowProc address and invokes SetWindowLong to set native control's wndproc to NativeMethods.Callback or NativeWindow.DebuggableCallback). Finally, it calls NativeMethods.Callback to handle this message.

4. NativeMethods.Callback just calls ControlNativeWindow.WndProc(override NativeWindow.WndProc) method. ControlNativeWindow.WndProc invokes ControlNativeWindow.OnMessage method, which only calls its associated Control's WndProc method. The message control is passed to Control class now!!

5. Control.WndProc acts as a .Net message filter which triggers most of the .Net control events in Winform control model. After the message processing, the message is finally passed to DefWndProc.