Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnKeyDown() Problems

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I'm trying to intercept this windows message, but I have had NO luck. I've created a class that has CWnd as the base class. I then added the OnKeyDown windows message. The OnKeyDown() isn't even called. I did this all through Class wizard. What I have is an edit box that I want to monitor what is being typed...character by character. Can someone help me to figgure this problem out? Thanks in advance!

Niky Williams
 
An alternative that might work is to use Class Wizard to add a message handler that will be called when the EN_CHANGE message is sent to the edit control. You might add a function called "OnChangeEditBoxContents" or something.

If that doesn't do it, maybe EN_UPDATE will.

Both of these should work with regular edit controls. If you derived your own class only for handling the keypress, that class can probably be scrapped. However, if you need it for other reasons, then maybe it is my above suggestions that should be scrapped!
 
Hmmm, sounds like there might be a focus problem, but I'm not sure. If you would like your dialog box to capture the OnKeyDown() for you, then you actually need to use the PreTranslateMessage() instead of the OnKeyDown(). The PreTranslateMessage() is not the be-all-end-all of capturing when a key is depressed. It acts more like a hot-key or a single command. Not sure if this is what you are wanting or not. Hope I helped some.

Nyjil
 

You can handle messages in PreTranslateMessage

BOOL CXXXX::preTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch (pMsg->message)
{
case WM_RBUTTONDOWN:
m_XXX.OnRClick();
return TRUE;
case WM_KEYDOWN:
do something
break;
default:
break;

}
return CDialog::preTranslateMessage(pMsg);
}
 
The message handling you should do in CDocument. If you create other windows, dialogs, you'll handle them in new create associated classes. John Fill
1c.bmp


ivfmd@mail.md
 
The message handling you should do in CDocument. If you create other windows, dialogs, you'll handle them in new created associated classes. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top