Solved

Message routing

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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