Steps for customizing messages in VC and methods for intercepting messages

Source: Internet
Author: User

To customize a message, follow these steps:
1. Define a message.

  1. # Define wm_mymessage (wm_user+ 100)

Microsoft recommends that you customize the message at least wm_user + 100, because many new controls also use wm_user messages.

2. Declare the message processing function in the afx_msg block in the. h file

  1. Afx_msg lresult onmymessage (wparam, lparam );

As follows:

  1. Protected:
  2. // {Afx_msg (...)
  3. Afx_msg int oncreate (maid );
  4. Afx_msg void ontimer (uint nidevent );
  5. Afx_msg lresult onmymessage (wparam, lparam );
  6. //} Afx_msg
  7. Declare_message_map ()

3. Add a message ing macro to the. cpp file.

  1. On_message (wm_my_message, onmymessage)

As follows:

  1. Begin_message_map (...)
  2. // {Afx_msg_map (...)
  3. On_wm_create ()
  4. On_wm_timer ()
  5. On_message (wm_mymessage, onmymessage)
  6. //} Afx_msg_map
  7. End_message_map ()

4. Edit the message processing function in the. cpp File

  1. Lresult yourclass: onmymessage (wparam, lparam)
  2. {
  3. Return 0;
  4. }

Message Interception Method
Use sendmessage (wm_mymessage) or postmessage (wm_mymessage) to send messages to the Message Queue where you need to use the message processing function.
The differences between the two are as follows:
Sendmessage: After a message is sent to the message queue, it is returned only after the message is processed. continue to run the code.
Postmessage: After a message is sent to the message queue, the message is returned immediately without waiting for message processing, and the code is executed.

 

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.