Value range of three custom messages

Source: Internet
Author: User
Tags ranges

On csdn, we can see a discussion about custom messages:
[Callback]

The first method is to use wm_user to customize messages. This method is common and easy to know. The following five steps are taken:
1. # After define wm_user_message wm_user + int (shift) statement, ";" cannot be added;
2. The above shift is 1 ~ Integer of less than 1000;
3. The selection of this value is irrelevant to system messages, window messages, and control messages;
4. Message ing must be within begin_message_maps () and end_message_maps;
5. Message Processing statement andCodeMust be added to the specified class.
Yes, but it also indicates that the author has not systematically studied MFC and is not very familiar with MFC. If you are not familiar with MFC, defining Your own messages in MFC is not a good solution.

The second method is wm_app. I have never used this message. Check msdn:

Wm_app

The wm_app constant is used by applications to help define private messages, usually of the form wm_app + X, where X is an integer value. (The wm_app constant is used in the ApplicationProgramHelps to define private messages. wm_app + X is commonly used, where X is an integer)
# Define wm_app 0x8000

In this article, we will also extract the message range to facilitate your understanding:
There are five ranges of message numbers: Five message range values

Range Meaning
0 through wm_user-1 Messages reserved for use by the system. The system retains the message
Wm_user through 0x7fff Integer messages for use by private window classes. Private defined window class integer message
Wm_app through 0 xbfff Messages available for use by applications. The application can obtain messages.
0xc000 through 0 xFFFF String messages for use by applications. Application string message
Greater than 0 xFFFF Reserved by the system for future use. Retain the message

From this point, we can see that the author's integer description is not very accurate, and the use range of wm_user and wm_app is also different, and its application scope is also different. Wm_user is used in window messages, while wm_app is used in program messages. Of course, because it is a custom message, you can use it whenever you like. However, if you want to manage your own code, we recommend that you follow the msdn recommendation method.

Method 3: registerwindowmessage
Registerwindowmessage

TheRegisterwindowmessageFunction defines a new window message that is guaranteed to be unique throughout the system. The returned message value can be used when callingSendmessageOrPostmessageFunction. (The registerwindowmessage function defines a new unique window message in the system. This message can be used in sendmessage and postmessage functions)

 
Uint registerwindowmessage (lpctstrLpstring// Address of message string);
Parameters
Lpstring

Pointer to a null-terminated string that specifies the message to be registered. (The string that points to the specified message registration at the end of null) return values

If the message is successfully registered, the return value is a message identifier in the range 0xc000 through 0xffff. (if the message is successfully registered, the return value is between 0xc000 and 0xffff.
If the function fails, the return value is zero. To get extended error information, call

Getlasterror .
If the function fails, the return value is 0. Obtain the extended message information and call getlasterror,

In the preceding message value range table, we can know that the message is in the string message range.

To sum up, all three custom messages can be used, and they are three messages with different value ranges.

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.