-
February 18th, 2009, 06:06 AM
#1
Focus Problem in MFC Dialog Project
Hi everyone,
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:
BOOL CMyCalculatorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CWnd::SetFocus();
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.
Thanks alot!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|