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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!