Solved

Message routing

Posted on 1998-10-16
2
173 Views
Last Modified: 2013-11-20
Hi,
I want rout a message to a CCmdTarget derived class.
I tried something like that (in the Main-App):

BOOL CMyApp::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
   if ((m_pMyCmdDerivedClass != NULL)&& m_pMessageController->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
   return TRUE;

   return CWinApp::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

m_pMyCmdDerivedClass is a pointer to my class (derived from CCmdTarget).
This works fine for commands in the menu (e.g. file open).
But if I post a message to my Main-App thread like
#define WM_MY_MESSAGE WM_USER + 1

::PostThreadMessage( AfxGetApp( )->m_nThreadID, WM_MY_MESSAGE, 0, 0 );

the message is posted to the main thread object (I can catch it with ON_MESSAGE(WM_MY_MESSAGE, MyMethod)    )
BUT IT IS NOT ROUTED TO THE m_pMyCmdDerivedClass OBJECT!!!!!!!!!
any ideas?
dib
0
Comment
Question by:dib
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:dib
ID: 1323438
Edited text of question
0
 
LVL 3

Accepted Solution

by:
plaroche earned 200 total points
ID: 1323439
As you can see in the name of the handler "OnCmdMsg" this is for commande messages, namely WM_COMMAND.

What you might want to do is define new WM_COMMAND messages and post them to your app, they will be routed correctly and be catchable by any object in the food chain.

You can check the doc for a command message, but BEWARE that command message notifications might interfere with your own.

Something like:

pWnd->PostMessage(WM_COMMAND, (WPARAM)MAKELONG(0,USER_DEFINED_NOTIF), (LPARAM)hWnd);


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question