[MFC Entry 1] Message-based, event-driven)

Source: Internet
Author: User
I have learned some C ++ and have a basic understanding of the C ++ syntax. I have been using C ++ for many times. net operating system, there is no chance to run on Linux and other systems. Therefore, VC ++ is my goal. I like games and plug-ins, but I always feel uncomfortable using. net. c ++ is a good choice. This series will record a process of learning MFC, also known as notes. Let's take a look at the messages in MFC today.
MFCProgramUse event-driven based on messages. That is to say, MFC is an endless loop with many conditions, each of which corresponds to a method. These conditions are defined by the message class. When an event is triggered, a message is sent to the response window. When the program receives the message, it parses and determines that if the condition is met, it will run the processing method of the current event. MSG;
While (Getmessage ( & MSG, null ))
{
Translatemessage ( & MSG );
Dispatchmessage ( & MSG );
}

Each program has the preceding loop, while MSG is a structure and a data format in windows. It can be found in winuser. h, Code As follows: /*
* Message structure
  */
Typedef Struct Tagmsg {
Hwnd;
Uint message;
Wparam;
Lparam;
DWORD time;
Point pt;
# Ifdef _ Mac
DWORD lprivate;
# Endif
} MSG, * PMSG, near * Npmsg, far * Lpmsg;

The main character of receiving and processing a message is the window. Each window must have a method that can process the message, called window procedure/function ). After receiving a message in the window, you must determine the type of the message, convert the message (translatemessage (& MSG) to the keyboard message), and then pass the message to (dispatchmessage (& MSG )) window functions.
A window function is a callback function (a user-defined function is used for a function called by a Windows operating system) in the following format. Lresult callback winproc (hwnd, uint message, wparam, lparam)

The meanings of wparam and lparam vary with messages, but we can know that the number of BITs varies with the number of bits in the operating system, in a 32-bit operating system, the value is 32-bit. Of course, the value of 64-bit is 64-bit. After knowing this function, If You Want To map each message to the processing function of the response, you need to determine it in the switch/case structure. In order to make the program more modular, you need to understand the principle of message map. Today, we will first get a preliminary understanding of what the message is.

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.