Simulate message of MFC in web script

Source: Internet
Author: User

Messages in MFC (custom ):
Define the message Response Function in. h
Afx void onmymessage ();
. Define a message in CPP to establish a message ing and implement a message function body
# Define wm_mymessage wm_user + 1
On_message (wm_mymessage, onmymessage)
Void cmyclass: onmymessage ()
{
// Code here ......
}

In fact, the final goal is to execute the onmymessage () function when wm_mymessage ()

Script: (assume that the name of the message response function is always on + [Message]. If there is only one response function for a few messages, modify it a little)

Function postmessage (message, ARG, func)
// Message: Message name (string), for example, "wm_mymessage"
// Arg: List of function parameters separated by commas (,), such as: "1, str1, 'const string', OBJ"
// FUNC: the name of the response function, for example, "onmymessage". If it is null, the default value is on + [Message].
{
VaR flag = true;
VaR evalstr;
If (func)
{
If (typeof (func )! = "Undefined ")
{
Evalstr = func;
Flag = false;
}
}
If (FLAG)
{
If (typeof ("On" + message) = "undefined ")
{
Alert ("message" + message + "no response function! ");
Return;
}
}
Evalstr = "on" + message;
Evalstr + = "(";
If (ARG) evalstr + = ARG;
Evalstr + = ");";
Eval (evalstr );
}

Compilation of response functions:

Function onmymessage (constintarg, intarg, conststring, stringarg, OBJ)
{
Alert ("" + constintarg + intarg + constring + stringarg + typeof (OBJ ));
}

Call location:

VaR STR = "string123456 ";
VaR ntemp = 100;
VaR OBJ = {};
Postmessage ("mymessage", "1, ntemp, 'confstring', STR, OBJ ");

Execution result:

Alert string: 1100conststringstring123456 [object]

Very simple !!!!!!!!!!!!!!!!!!!!!!!!!!!!

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.