Solved

Message routing

Posted on 1998-10-16
2
167 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
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now