Well in order to use custom messages, they need to be defined as a value greater than WM_USER. So, if I wanted a message like WM_MYMESSAGE:-
Code:
#define WM_MYMESSAGE (WM_USER + 1)
The only problem is: what's stopping another program from doing the same thing for its own messages?
The answer: RegisterWindowMessage.
Code:
unsigned int uiMessage;
uiMessage = RegisterWindowMessage("WM_MYMESSAGE");
The return value of RegisterWindowMessage is guaranteed to be unique across the entire system and within the range WM_USER to 0x7FFF. As many applications that use the message may call RegisterWindowMessage, they will all get the same value to use.
So, you've done all that, now what about passing stuff? Passing an integer here and there is easily done, wParam and lParam are at your disposal...
Code:
LRESULT WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
...
case WM_MYMESSAGE:
{
if (wParam == 1)
MessageBox(hwnd, "Woot!", "Hello!", MB_ICONEXCLAMATION);
break;
}
}
return FALSE;
}
BUT... what if you want to pass a string, or a pointer to a structure? Then things get tougher. The thing is, each process's memory is protected from other processes. They can't just pop inside each other's address space and compare notes. What you need is, specifically for messaging, some shared memory. This is known as custom marshalling.
And it's not something I know how to do.