Wndproc function (conversion)

Source: Internet
Author: User

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)

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.