Functions of wndproc:
It is mainly used to intercept and process system messages and custom messages.
For example:
Windows programs generate many messages. For example, if you click the mouse and move the window, messages are generated. This function is the default message processing function. You can reload this function to develop your own message processing process.
In CS, You can override the wndproc function to capture all window messages.
In this way, we can "tamper" the incoming message, and manually change the window behavior.
Code example:
Public partial class form1: FORM {public form1 () {initializecomponent ();} private demo = NULL; private void form1_load (Object sender, eventargs E) {demo = new demo (this. handle. toint32 ();} private void button#click (Object sender, eventargs e) {demo. test ();} protected override void wndproc (ref message m) {If (M. MSG = demo. my_msg_begin) {MessageBox. show ("demo for loop starts. ");} else if (M. MSG = demo. my_msg_end) {MessageBox. show ("demo for loop ends. ");} base. wndproc (ref m );}}
public class Demo { private int m_hWnd = 0; public Demo(int hWnd) { m_hWnd = hWnd; } private const int WM_USER = 0x0400; public static int MY_MSG_BEGIN = WM_USER + 100; public static int MY_MSG_END = WM_USER + 101; [DllImport("User32.DLL")] public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam); public void Test() { SendMessage(m_hWnd, MY_MSG_BEGIN, 0, 0); for (int i = 0; i < 100000; i++) { Application.DoEvents(); } SendMessage(m_hWnd, MY_MSG_END, 0, 0); } }
Wndproc function (conversion)