Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1997-06-13
9
Medium Priority
?
504 Views
Last Modified: 2013-12-03
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).
0
Comment
Question by:postrowski
[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
  • 5
  • 3
9 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1398289
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.
0
 

Author Comment

by:postrowski
ID: 1398290
I've tried it at the CWinApp level, and it never got called there either.
0
 
LVL 23

Accepted Solution

by:
chensu earned 300 total points
ID: 1398291
Are your sure the prototype of PreTranslateMessage() function is correct?
virtual BOOL PreTranslateMessage(MSG *pMsg);

If so, you have to do some debugging. Open MFC source code appcore.cpp and set some breakpoints in CWinApp::Run() and CWinApp::PumpMessage() to find out why it is not called. I guess the base class function CWinApp::PreTranslateMessage() and CWnd::PreTranslateMessage() are called. But the execution does not go through your overriden version.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:postrowski
ID: 1398292
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.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1398293
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.
0
 

Author Comment

by:postrowski
ID: 1398294
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.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1398295
m_pMainWnd exists in 16-bit, it is a member of CWinApp.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1398296
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().
0
 

Expert Comment

by:fredjones
ID: 1398297
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.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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