February 18th, 2009, 05:06 AM
Focus Problem in MFC Dialog Project
I've created a dialog project to implement a simple calculator. I'm trying to set the focus to be on my dialog so I will be able to use the WM_KEYDOWN to capture keyboard input. I've enabled the ON_WM_SETFOCUS() and ON_WM_KILLFOCUS() options so I will know when my dialog gets the focus, and when then focus is taken away from it.
I've tried setting the focus using SetFocus() in the following way:
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
return FALSE; // return TRUE unless you set the focus to a control
However, when debugging the program I see that the focus is indeed given to the dialog at first ( ON_WM_SETFOCUS() is activated), but then the focus is immediately taken away from it ( ON_WM_KILLFOCUS() is activated ), and because of this the dialog doesn't respond to key pressings.
What am I doing wrong?
BTW: I'm using visual studio 2005 with an MFC project.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!