By calling UpdateWindow, the button is being redrawn before the focus change can take effect. The Invalidate should be sufficient by itself, the window will get repainted when everything settles down.
views:
1746answers:
3
A:
Mark Ransom
2008-12-15 21:47:43
Ok, I removed UpdateWindow, my original problem stil persists.
rec
2008-12-15 21:54:52
A:
This draws the thick border around the button:
static_cast<CButton*>(GetDlgItem(IDC_BUTTON1))->SetButtonStyle(BS_DEFPUSHBUTTON);
A more elegant way to do this would be to define a CButton member variable in CbuttonfocusDlg and associate it to the IDC_BUTTON1 control, and then calling
this->m_myButton.SetButtonStyle(BS_DEFPUSHBUTTON);
This makes the button to which I'm setting the focus the default button, but note that when the focus goes to a control (inside the dialog) that is not a button, the default button is once more the original default button set in the dialog resource, in this case the "Ok" button.
rec
2008-12-16 15:54:22
Aha, I misunderstood the question! I'm sorry, I could have come up with this answer yesterday. You kept emphasizing the word "focus", and the dotted line is the official focus indicator.
Mark Ransom
2008-12-16 23:03:21
+1
A:
Use WM_NEXTDLGCTL.
See http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx
Joel
2008-12-16 22:51:21
+1. The OP is asking the wrong question, caused by a misunderstanding of how dialogs work. OP, please be careful that the behavior you implement follows 'normal' window UI rules about default buttons etc. (i.e., that pressing enter after opening the dialog does something intuitive).
Roel
2008-12-19 15:05:11