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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnKeyDown() 1

Status
Not open for further replies.

nyjil

Programmer
Jul 14, 2000
32
US
Looks like it's time to ask another question. This one should be simple, but I guess I'm making it much too difficult. Here it goes.

I am able to make the program respond to my OnKeyDown() command, as long as there is nothing on the dialog box at all. It will perform nicely and do what I intend it to, until...I actually put anything, and I do mean anything in the dialog box itself. It could even be something so innocent as static text. Then when I depress a key on the keyboard, all I get is a beep from the program and none of the other intended functions run. I believe it has something to do with focus, am I right? If someone has the answer to get around my problem please lemme know. Some sample code sure would be great if you have the time.

Many thanks,
Nyjil
 
Hi

Go to the Class Wizard and add the function PreTranslateMessage
The example shows here comes from the About Box wher I add two Edit boxes and other controls.
This technique is used widely to trap the Return and Enter key in a Dialogbox or a view form.
This is the reason of the check for the wParam member

BOOL CAboutDlg::preTranslateMessage(MSG* pMsg)
{
// Select Only WM_KEYDOWN Message

if ( pMsg->message == WM_KEYDOWN)
{
// Select ESC and Enter Key

AfxMessageBox( "Hey KeyDown ");

if (( pMsg->wParam == VK_RETURN) || ( pMsg->wParam == VK_ESCAPE))
return TRUE;
}

return CDialog::preTranslateMessage(pMsg);
}

Thierry
Thierry.Marneffe@swing.be
 
Wow,

That worked slicker then I had ever hoped. Your sample code proved to be invaluable. Many thanks to you Thierry. I do believe I owe you one.

s-)
Nyjil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top