• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Custom Command Routing :: MFC

kuphryn

Senior member
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
 
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.
 
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
 
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.
 
Back
Top