Introduction
When we write a program, maybe we need several modules, but how a module worked with each other? We always export some funcion, and maybe we need some callback function or virtual function deal with user input. Sometimes it is very anoying to do that, so I wrote this code for it.
Using the code
Before you using this code, you must insert all files in the path KUCMD, and include the file KuCOMMAND.h
Every class you want it can sent or get message must like this:
class CSend
{
DECLARE_COMMAND(CSend)
public:
CSend();
};
now, this class can get a message. and you must add this function:
bool CPost::OnKuCmd(UINT msgID, DWORD hParam, DWORD lParam)
{
switch(msgID) {
case TEST_SEND:
::MessageBox(NULL, (LPCSTR)hParam, "TEST_SEND", MB_OK);
return true;
}
return false;
}
Now, in any class that like CPost
, you can send message TEST_SEND
by this code
KUMSG msg;
msg.msgID = TEST_SEND;
msg.hParam = (DWORD)(LPCSTR)strMessage;
SendCmd(msg);
The sent message will return when it has be deal or
KUMSG msg;
msg.msgID = TEST_POST;
msg.hParam = (DWORD)(LPCSTR)strMessage;
SendCmd(msg);
To post the message. post message will return immediately. The message could define in KuCOMMAND.h, like this:
#define TEST_SEND 0x01
#define TEST_POST 0x02