?
Solved

Message routing

Posted on 1998-10-16
2
Medium Priority
?
175 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 800 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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