?
Solved

PreTranslateMessage or Message Maps in CWinAp derived classes

Posted on 2003-03-31
6
Medium Priority
?
1,224 Views
Last Modified: 2013-11-20
I'm currently trying to sort out some historic code which has something like this:

BOOL CMyWinApp2::PreTranslateMessage(MSG* pMsg)
{
  if (pMsg->message == WM_DRIVER_FIRSTNOTE)
  {
    OnFirstNote(pMsg->wParam, pMsg->lParam);
  }
  return CMyWinApp1::PreTranslateMessage(pMsg);
}

WM_DRIVER_FIRSTNOTE is a custom registered windows message.
CMyWinApp2 is derived from a class (CMyWinApp1) that is derived from CWinApp. All the inheritance seems fine.

There is also a message map for WM_DRIVER_FIRSTNOTE:

BEGIN_MESSAGE_MAP(CMyWinApp2, CMyWinApp1)
  //{{AFX_MSG_MAP(CMyWinApp2)
     ON_REGISTERED_MESSAGE(WM_DRIVER_FIRSTNOTE, OnFirstNote)
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()

The prototype for OnFirstNote is:

afx_msg LRESULT OnFirstNote(WPARAM, LPARAM);

The message in question originates from a list control on a property page on a modal dialog. The property sheet and the dialog both have the 'No parent notify' option disabled in the resource, if that's of significance. I assume that option would if enabled stop the message being passed back to the app?

An now for my question:

As I understand it PreTranslateMessage is not the correct way to map messages like this. (I'm not bothered about disputing this, there are several topics out there to support my claim, unless someone truely knows what they're talking about). Given this when I remove the PreTranslateMessage it doesn't call OnFirstNote?!? The message isn't handled anywhere else apart from in the main ap code, and as I understand it, it should get passed to my CMyWinApp2 class and map to OnFirstNote.

What am I missing/not understanding correctly?




0
Comment
Question by:jfstephe
[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
6 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8238988
BOOL CMyWinApp2::PreTranslateMessage(MSG* pMsg)
{
 if (pMsg->message == WM_DRIVER_FIRSTNOTE)
 {
   OnFirstNote(pMsg->wParam, pMsg->lParam);
   return TRUE;
 }
 return CMyWinApp1::PreTranslateMessage(pMsg);
}

Adding line
return TRUE;
stops handling the message. Without this line message may be handled in one of program classes.

PreTranslateMessage is usually used for the messages which cannot be handled by other way or to prevent standard MFC handling of some messages.
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8239712

BEGIN_MESSAGE_MAP(CMyWinApp2, CMyWinApp1)
 //{{AFX_MSG_MAP(CMyWinApp2)
    ON_REGISTERED_MESSAGE(WM_DRIVER_FIRSTNOTE, OnFirstNote)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

Take the Registerd Message out of the AFX_MSG_MAP Block

BEGIN_MESSAGE_MAP(CMyWinApp2, CMyWinApp1)
 //{{AFX_MSG_MAP(CMyWinApp2)
 //}}AFX_MSG_MAP
    ON_REGISTERED_MESSAGE(WM_DRIVER_FIRSTNOTE, OnFirstNote)
END_MESSAGE_MAP()






0
 
LVL 9

Assisted Solution

by:Priyesh
Priyesh earned 375 total points
ID: 8242511
try mapping the ON_REGISTERED_MESSAGE in your CMainFrame or the mainwindow class of your app whatsoever.

0
 

Author Comment

by:jfstephe
ID: 8254853
williamcampbell - I will do when I get a chance. I doubt that it will resolve it but it's a good point.

Priyesh - Why would this change anything? If the PreTranslateMessage in CMyWinApp2 can see the message then why isn't it getting map across?

Is my general understanding correct or am I missing something?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 375 total points
ID: 8258809
ON_REGISTERED_MESSAGE should be used in some CWnd-derived class and not in CWinApp-derived class. Move this handler to the window to which this message is posted (CMainFrame?)
On the other way, CWinApp::PreTranslateMessage is the place where you can catch any message posted to any window in the application.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
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 …
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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