PDA

View Full Version : CDialog and Keyboard events


braveheart09
02-25-2006, 11:22 PM
I have dialog (window/form) that inherits from the CDialog class. This dialog has various controls on it including a few buttons and textboxes.

I am trying to get some keyboard events (key presses) to fire some events but its not working.

In the Header file for the dialog i have this as a protected declaration

afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);


I have an ON_WM_KEYDOWN() event created and its corresponding method in the .cpp file

void COpenGLMFCDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)


Within this method i have written some test code to change the text in a textbox just to see whether the event is fired correctly, but the text is never changed. I also tried changing the dialog's name and also firing some Message Boxes ... but nothing worked.

The code in the "OnKeyDown" method is as follows:

void COpenGLMFCDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){

switch(nChar)
{
case VK_RETURN:
SetWindowText("You pressed Enter");
break;
case VK_F1:
SetWindowText("Help is not available at the moment");
break;
case VK_DELETE:
//SetWindowText("Can't Delete This");
//AfxMessageBox("Testing");
m_Txt_Test.SetWindowText("The Event was fired");
break;
case VK_DIVIDE:
//SetWindowText("Testing");
m_Txt_Test.SetWindowText("Another Event fired");
break;
default:
SetWindowText("Whatever");
}
}


Could someone please (pretty please) tell me why this isn't working and whether i have done all that is needed for a keyboard event to fired & a result to be seen on screen.

Thanks in advance.