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
Solved

mydefineddialog::PreTranslateMessage doesn't get called

Posted on 2003-10-21
8
1,282 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
ID: 9595236
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
ID: 9596641
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
ID: 9596858
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 48

Expert Comment

by:AlexFM
ID: 9597259
Try to overwrite CWinApp::PreTranslateMessage and catch message there.
0
 

Author Comment

by:hammet
ID: 9597867
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
ID: 9598083

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
ID: 9605046
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
ID: 9605659

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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