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 not accessed

Status
Not open for further replies.

FranT

Programmer
Aug 6, 2005
1
NL
Hello

I'm a Delphi programmer and changed to the visual c++ language. I have problems with the OnKeyDown routine.
When I execute the program in debug mode I see that the routine isn't executed. The compiler does not show an error or warning. I made a new MFC project with the application wizard. Can please somebody tell me why the routine isn't called when I press a button?

void CTestDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_RETURN:
SetWindowText("You pressed Enter");
break;

default:
SetWindowText("Whatever");
}

CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

Kind regards,
Frank.
 
In dialogs you usually trap <Enter> by overloading the
OnOK method.

Won't work if you have an Edit control with 'Want return' set - then the control will eat the <Enter>.

>why the routine isn't called when I press a button

I assume you mean a button on the keyboard - "isn't called when you press a key". The word Button is usally used in another context, like the 'OK' and 'Cancel' buttons (that usually correspond to the <Enter> and <Esc> key)

/Per
[sub]
www.perfnurt.se[/sub]
 
There is a focus issue. Only one window has the focus at one moment. If your window does have the focus, there will be no keyboard message going to the handler of that window. By clicking the boarder of your dialog window you may set the focus to it.

There might be other problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top