Link to home
Start Free TrialLog in
Avatar of postrowski
postrowski

asked on

How do I use CDialog::PreTranslateMessage() in 16-bit?

How can I get my dialog (derived from CDialog) to respond to the PreTranslateMessage.  I can do it with no problems in 32-bit, but in 16-bit, the same function never gets called.
I'm trying to use this to capture the keyboard input before it gets to an edit box (which has the focus).
Avatar of chensu
chensu
Flag of Canada image

It should work in 16-bit the same as in 32-bit. It is an MFC virtual function. Try CWinApp::PreTranslateMessage() to see if it gets called.
Avatar of postrowski
postrowski

ASKER

I've tried it at the CWinApp level, and it never got called there either.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have the prototype correct.
When I set up breakpoints in the App's PreTranslateMessage, I find that I can receive PreTranslateMessage calls up until I launch the new dialog with the DoModal().  At this point, even the App's PreTranslateMessage no longer gets called.
The new dialog is being created by a modless dialog.
The DoModal() call occurs directly after recieving a message to launch the new dialog, thus the App's PreTranslateMessage is already in the call stack when the new dialog is up.  Could this be causing some sort of problem?
Also, I'm not explicitly setting the m_pMainWnd before I call DoModal on the new dialog, could that also be the problem?

Your proposed 'answer' is correct, in that is what I needed to do next, but it still doesn't help me yet.

Do you have any other ideas?

Thanks for your help.
You said "The DoModal() call occurs directly after recieving a message to launch the new dialog, thus the App's PreTranslateMessage is already in the call stack when the new dialog is up." How do you send the message? SendMessage or PostMessage? Use PostMessage instead of SendMessage. And you'd better set m_pMainWnd because some parts of MFC code need it.
What I meant is that the user clicks on a button to launch the new dialog.  In the OnButtonClicked function for that button (which is called through windows messaging), I then call SendMessage to call a routine that launches the dialog with a DoModal call.
Changing this to a PostMessage call has no effect.

I tried to set m_pMainWnd, but quickly learned that it is a member of CWinThread, which doesn't exist in 16-bit.
m_pMainWnd exists in 16-bit, it is a member of CWinApp.
I have tried a simple program which has the same symptom as your program. So, I think there is nothing wrong with your program. That is the restriction of 16-bit MFC. In order to do what you want, you can derive your own edit box class from CEdit and create it in the CDialog::OnInitDialog().
You don't have to write your own CEdit class.  You can do what you want by added a function to handle the EN_UPDATE message from the edit box.  It will pass you notification before it updates the screen.  You can get the data into your member variable by using the UpdateData(TRUE) function, check and/or modify the value, and then do an UpdateData(FALSE) to put it back on the screen.