VisualC++ Tips

Just another WordPress.com weblog

How to set focus to a control in the dialog startup

Setting focus to a dialog control is more than just call SetFocus.

Normally, the focus is set to a control which was higher in z-order. But we can set focus in two ways.

  1. Call SetFocus() function to desired control in OnInitDialog and return FALSE.
  2. Call ::PostMessage( this->m_hWnd, WM_NEXTDLGCTL, (WPARAM)( GetDlgItem( IDC_BUTTON1 )->m_hWnd ), TRUE );  in OnInitDialog() and return TRUE. Don’t call SendMessage instead of PostMessage.

September 4, 2008 Posted by afsalm | VC++ | , | No Comments Yet