MFC Message handlers - Sender available?

Khanmots

Gawd
Joined
May 12, 2007
Messages
905
Consider the following:
Code:
BEGIN_MESSAGE_MAP(CMyHandlerThread, CWinThread)
    ON_THREAD_MESSAGE(UDM_MY_MESSAGE, OnMyMessage)
END_MESSAGE_MAP()

void CMyHandlerThread::OnMyMessage(WPARAM fizz, LPARAM buzz)
{
   // do stuff
}

Multiple threads can post UDM_MY_MESSAGE to my handler thread. Is there a way to obtain information on the originator of the message? Or am I going to need to embed a threadId or some such identifier in the information passed through in the message parameters?
 
I wound up implementing via passing a pointer to the object sending the message.

However, I'm still curious if any sender information is available... although if there is I'm suspecting that I'd have to override the message loop to gain access to it and can't do it via message maps.
 
Sending information isn't available in Windows messages, period. You have to pass whatever context you want as a parameter in the message.
 
User defined messages support sending 2 pointer-sized parameters by value (WPARAM and LPARAM). That's information.

However, you're right in that anything beyond those isn't passed by the message. Typically I use LPARAM for a pointer to a sync object and WPARAM for a pointer to a shared structure. Although sometimes I'll simply just cast an integer of float or something and pass directly as the WPARAM or LPARAM.

In any case, I wound up embedded a pointer to the sending object in the structure whose pointer I send as the the messages WPARAM parameter.

I'm still curious if it's possible to gain any information on the sender. Other messaging systems I've worked with have had this be possible, although to be fair, they required you to create logical linkages that don't seem to be present in the way MFC works.
 
By "sending information", I mean information about the sender.

Again, Windows doesn't make information about the sender available. If you want the recipient to know something about the context, you have to send it along win lParam or wParam.
 
By "sending information", I mean information about the sender.

Again, Windows doesn't make information about the sender available. If you want the recipient to know something about the context, you have to send it along win lParam or wParam.

Gotcha, thought you were speaking about information in general. Thanks.
 
Back
Top