Solved

mydefineddialog::PreTranslateMessage doesn't get called

Posted on 2003-10-21
8
1,316 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 98
countEvens challenge 2 115
sum13 challenge 24 135
"Black Box" Testing of Control System Software 2 97
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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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