Solved

mydefineddialog::PreTranslateMessage doesn't get called

Posted on 2003-10-21
8
1,212 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
 
LVL 48

Expert Comment

by:AlexFM
ID: 9597259
Try to overwrite CWinApp::PreTranslateMessage and catch message there.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Smart Camera scanning and reading information 3 100
countEvens challenge 2 77
changeXy challenge 13 67
mapAB Challlenge 35 126
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: 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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

16 Experts available now in Live!

Get 1:1 Help Now