Custom Command Routing :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

Microsoft offers an impressive feature in MFC that routes WM_COMMAND and COMMAND_UPDATE messages via command routering using OnCmdMsg(...) in main and a function in doc to traverse through all active view. The drawback, however, is that it only works for COMMAND messages, not any messages.

I wonder if there is a technique similar to the one mentioned above for specific command type such as user commanders (WM_USER_MYCOMMAND, etc). The message map would look like this:

// ON_MESSAGE(WM_USER_MYCOMMAND, OnMyCommand)

Thanks,
Kuphryn
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
I want to make sure I understand what you need. You created your own WM_USER_XXX message, and now you want to map it to handler OnUserMsg(...) right?

If that is so you need to do a couple of things. First you need to register your custom message.

I think it's something like const int WM_USER_MESSAGE = RegisterUserMessage(....). I forgot the exact API, consult the MSDN, or if you can't find anything, I can tell you tomorrow, when I get to work.

Once this is done, all you need to do is add:

ON_REGISTERED_MESSAGE(WM_USER_MESSAGE, OnUserMessage)

Hope that helps.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

I can send and receive the custom message. I wanted to know if there is a technique similar to OnCmdMsg() for custom message. OnCmdMsg() has a unique feature in which you can view all inactive views to see if any of the views has a handle for the message.

Right now, the way the program works is I send main a message and main redirects it to an appropriate view. For example, let say a dialog box sends a message to main, but the dialog box was created in view. Main will redirect the message to view via SendMessage(...).

Kuphryn
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Realize that the base API command has a target window handle to receive the message. Windows just sends the command to the "main" parent and the that window forwards it on to the appropriate child window the message is addressed to.