C # Delegate, event, message (Entry level) (continue)

Source: Internet
Author: User

The Windows operating system is graphic interface, and this is because of the credit of the information queue mechanism.

Most of the messages we talk about are broadly defined. Communication between objects is called message interaction. Through the message, the object previously established a contact.

So what is the message in our winform program? We said: messages in the winform Program often refer to messages sent from the operating system to the winform form (which is not correct here, but there is no problem in understanding it first, tell it that an event has occurred. For example, if you click the mouse, it is impossible for us to know that the form itself does not know that the mouse is clicked, but the operating system knows that the mouse is clicked, And it will send a message to the form to tell it: when the mouse is clicked, You should have responded.

After a message is obtained by the form, the form is processed. For example, if the mouse is clicked, the operating system tells the form by sending a message, the form calls the mouse click event, and the event will call the method we bind to it, we have achieved the expected results.

It is not difficult to understand, so we will explain the three stages of message generation, sending and processing.

As we provide an entry-level explanation, I will give you a brief introduction.

① Message generation: we all know that machines do not think about messages in mode, but the operating system understands that we have clicked the mouse and tapped the keyboard, so I guess (my guess) it should be powered by intermittent electric currents. Of course, we cannot do this ......

There are many types of messages, each corresponding to an operation, such as clicking the mouse, hitting the keyboard ......

② Send a message.

After a message is generated, the system encapsulates the message. As we all know, the encapsulated message becomes an object.

Namespace system. Windows. Forms
{
// Message class
Public struct message
{

//......

// Summary:
// Obtain or set the message window handle.
//
// Return result:
// Message window handle.
Public intptr hwnd {Get; set ;}
//
// Summary:
// Specify the system. Windows. Forms. Message. lparam field of the message.
//
// Return result:
// The system. Windows. Forms. Message. lparam field of the message.
Public intptr lparam {Get; set ;}
//
// Summary:
// Obtain or set the Message ID.
//
// Return result:
// Message ID.
Public int MSG {Get; set ;}
//
// Summary:
// Specify the value returned to Windows in response to message processing.
//
// Return result:
// Return value of the message.
Public intptr result {Get; set ;}
//
// Summary:
// Obtain or set the message's system. Windows. Forms. Message. wparam field.
//
// Return result:
// The system. Windows. Forms. Message. wparam field of the message.
Public intptr wparam {Get; set ;}

//......
Public override string tostring ();
}
}

The above is the form message class encapsulated by C #. I have omitted some attributes and methods.

The encapsulated message to the C # language has four attributes: Form handle, message number, parameter 1, parameter 2.

The handle is the number (dynamic and unique) of the form ). The message number is ...... Is the message number, hexadecimal data. It is generally possible to get the coordinates of the mouse in the parameter.

In Windows, messages are sent to the corresponding form through a window handle. All information is maintained by the operating system into a message queue and distributed by the operating system.

③ Message processing.

Let's take a look at how winform processes messages. First, there will be a method that gets the message first for determination, and then this method will trigger different events through the message type.

 

Let's talk about messages. We will discuss the sending and interception of messages, as well as custom messages and message queues later.

19:03:39

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.