Note: Do not call SetFocus to change a control's focus in a dialog window, except when handling the WM_INITDIALOG message.
To explicitly set the focus to a dialog's control call SendMessage(hDialog, WM_NEXTDLGCTL, (WPARAM)hwndCtrl, TRUE). The WM_NEXTDLGCTL message notifies the dialog manager that the focus has changed.
The exception is the initial WM_INITDIALOG message. When you receive WM_INITIDIALOG call SetFocus on the desired control's hWnd. You must return FALSE to notify the dialog manager that you set the initial focus.
When handling other dialog messages if you use SetFocus (and not WM_NEXTDLGCTL) it prevents the dialog manager from updating its internal bookkeeping. For example, it might cause the dialog manager to display the wrong default pushbutton or fail to select the text of an edit control. For details see Raymond Chen's book The Old New Thing, page 227, "How to set focus in a dialog box." (Or see his blog.)