Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mydefineddialog::PreTranslateMessage doesn't get called

Posted on 2003-10-21
8
Medium Priority
?
1,505 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
Industry Leaders: 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: 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. …
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.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 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