How to send custom messages in VC ++ 6.0

Source: Internet
Author: User

How to send custom messages in VC ++ 6.0

1. Differences between postmessage and sendmessage Functions

You can use the postmessage and sendmessage functions to send custom messages. The difference is:

Postmessage only puts the message into the queue. no matter whether the message processing program processes the message, it returns the message and continues the execution. This is an asynchronous message serving function;

Sendmessage must be returned after the message processing program processes the message and continues to be executed. This is a synchronous message serving function;

In addition, the return value of postmessage indicates whether the postmessage function is correctly executed, and the return value of sendmessage indicates the return value after other programs process messages.

2. Customize the message sending Method

(1) Add the following code to define a message in the resource. h or stdax. h file:

# Define wm_my_message wm_user + 1

(2) Add the following code to the header file of the class where the message processing function is located:

// {Afx_msg (c ...)
Afx_msg ........
Afx_msg ........
Afx_msg void onmymessage (/* wparam, lparam */);//Whether the parameter depends on the actual situation
//} Afx_msg
Declare_message_map ()

(3) Add the following code to the CPP file of the class where the message processing function is located:

Begin_message_map (...,...)
// {Afx_msg_map (cpostmessageview)
On_command .......
On_message (wm_my_message, onmymessage)
//} Afx_msg_map
......
End_message_map ()

(4) manually add the corresponding message function code to the CPP file of the class where the message processing function is located:

Void cpostmessageview: onmymessage (/* wparam, lparam */)
{
........
........

}

(5) Add the Code where the message needs to be sent:

Postmessage (wm_my_message );

Or

Sendmessage (wm_my_message );

 

3. Send custom messages from a class to the mainframe class

Directly Using the postmessage or sendmessage function can only send messages to the class where the function is located. To send messages to the mainframe class, you can use the following code:

(Cmainframe *) afxgetmainwnd ()-> postmessage (wm_xxx );

Or

(Cmainframe *) afxgetmainwnd ()-> sendmessage (wm_xxx );

 

Reprinted statement: This article from http://wmnmtm.blog.163.com/blog/static/3824571420097510938616/

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.