2011年11月11日 星期五

[MFC] Set default focus of control item in dialog

The story is like this, we had some small requirement with our program.
Default focus of control item in our program was asked to change to some edit box for data input instead of setting on OK button as default, so that users don't need to change the focus by moving cursor or clicking Tab button.

And it can avoid an extra Enter button clicking to run OK when our program is launched.
But this request wasn't altered in next version.
I discussed with our engineer, and he said SetFocus() method of CWnd can work properly.
Then  I found something tricky in OnInitDialog() function when I looking into this issue.
It's just the key point to resolve this problem.
Share with you here.

* Set the focus of control item in OnInitDialog(), but it doesn't work.












* The key point is here,
OnInitDialog() must return FALSE so that the focus of control item can be set properly.




沒有留言:

張貼留言