Solved

mydefineddialog::PreTranslateMessage doesn't get called

Posted on 2003-10-21
8
1,179 Views
Last Modified: 2013-11-20
I'm tryng to capture keydown events in a dialog by overriding the CDialog::PreTranslateMessage method. My code is:

BOOL ControlDialog::PreTranslateMessage(MSG* pMsg)
{
      if (pMsg->message==WM_KEYDOWN)
      {
            MessageBox("I did it!");
      }
      return CDialog::PreTranslateMessage(pMsg);
}

but it never gets called. Anybody knows why?
0
Comment
Question by:hammet
  • 3
  • 3
  • 2
8 Comments
 
LVL 4

Expert Comment

by:inox
Comment Utility
Modal dialog messages are handled by IsDialogMessage so if the message is for that modal dialog, PretranslateMessage is not called, because the message is completely handled by IsDialogMessage.

Is a ordinary message-handler (onKeydown) not suitable?

0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
This must work. Search for typo or something else which prevents this function to be called. Check whether function is called at all:

BOOL ControlDialog::PreTranslateMessage(MSG* pMsg)
{
    TRACE(_T("PreTranslateMessage\n"));

    if (pMsg->message==WM_KEYDOWN)
    {
         TRACE(_T("WM_KEYDOWN\n"));
    }
    return CDialog::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:hammet
Comment Utility
It is not a modal dialog and the ordinary message-handler (onKeydown) doesn't work but for example the left mouse button message-handler works. Function isn't called, i've checked it.
0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
Try to overwrite CWinApp::PreTranslateMessage and catch message there.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:hammet
Comment Utility
Overwriting CWinApp::PreTranslateMessage doesn't work.
More tips about my problem:
   - the dialog's parent window is an opengl window
   - the opengl window has its own windowproc event handler.
   - the opengl window windowproc don't catch that keydown event.
   - I can't get called ControlDialog::PreTranslateMessage or ControlDialog::OnKeyDown but I can catch ControlDialog::OnMouseWheel for example.
0
 
LVL 4

Accepted Solution

by:
inox earned 250 total points
Comment Utility

If CWinApp::PreTranslateMessage there seems to be another modal dialog however there seems to be someting modal but not the mainapp.
Maybe
http://search.microsoft.com/search/results.aspx?View=msdn&st=a&qu=Q126874&c=0&s=4
can help
0
 

Author Comment

by:hammet
Comment Utility
I've found the cause of the problem. The main opengl window has this loop:
   while (!pShutdown) {
      if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
         if (msg.message==WM_QUIT)
      pShutdown=true;
         else {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
         }
      }
   }
Child window keydown event is catched here (I've traced it). It is supossed that DispatchMessage sends message to child window but ControlDialog::PreTranslateMessage, ControlDialog::OnKeyDown and ControlDialog::OnChar don't get called. How can I perform this?
I'll give 50 points to inox (the best answer by the moment). I'll give 200 point to the one who gives me the final answer to this question.
0
 
LVL 4

Expert Comment

by:inox
Comment Utility

the ControlDialog must have the mainwindow as parent, whether directly or indirectly, is that the case?

Goto the file WINCORE.CPP
in line 2653 find the function
BOOL PASCAL CWnd::WalkPreTranslateTree(HWND hWndStop, MSG* pMsg)
(here the PreTranslateMessage calls are routed)
set a breakpoint there does it stop?
if:
you can follow up the
for (HWND hWnd = pMsg->hwnd; hWnd != NULL; hWnd = ::GetParent(hWnd))
loop to check your dialog is in the chain
if not:
In the file THRDCORE.CPP (MFC Sources) the is the function
BOOL CWinThread::PreTranslateMessage(MSG* pMsg)
set a bp there and see if it stops
if:
 follow to the WalkPreTranslateTree call
if not:
 in the same file goto the
BOOL CWinThread::PumpMessage()
here it must stop, check whats going on



0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

9 Experts available now in Live!

Get 1:1 Help Now