본문 바로가기

Programming/MFC

OnInitDialog()에서 컨트롤에 포커스 주기

컨트롤에 포커스를 주기 위해서는

 

m_ctrl_edit_bitrate.SetFocus() ;

 

위와 같이 하면 된다.

 

그러나 초기에 다이얼로그가 리턴값을 TRUE를 주게 되면 포커스가 먹지 않는다.

 

따라서 리턴값을 FALSE를 주면 포커스가 먹는다.

 

 

BOOL CEXESGDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // TODO:  여기에 추가 초기화 작업을 추가합니다. 

 ListView_SetExtendedListViewStyleEx( m_ctrl_list_ex_esg.GetSafeHwnd(), LVS_EX_FULLROWSELECT , LVS_EX_FULLROWSELECT ) ;
 m_ctrl_list_ex_esg.InsertColumn( 0, _T("IP Address"), LVCFMT_CENTER, 130 ) ;
 m_ctrl_list_ex_esg.InsertColumn( 1, _T("Port"), LVCFMT_CENTER, 80 ) ;
 m_ctrl_list_ex_esg.InsertColumn( 2, _T("Bitrate"), LVCFMT_CENTER, 130 ) ;

 CHeaderCtrl* pListHeader = m_ctrl_list_ex_esg.GetHeaderCtrl() ;
 ASSERT( pListHeader ) ;

 // Iterate through the items and set the image
 HDITEM hdi ;
 hdi.mask = HDI_IMAGE | HDI_FORMAT ;
 int nCnt = pListHeader->GetItemCount() ;

 for ( int i = 0 ; i < nCnt ; i++ )
 {
  if ( pListHeader->GetItem( i, &hdi ) )
  {
   hdi.fmt |= HDF_CENTER ;

   pListHeader->SetItem( i, &hdi ) ;
  }
 }
 m_ctrl_list_ex_esg.SetExtendedStyle( /*LVS_EX_GRIDLINES |*/ LVS_EX_FULLROWSELECT ) ; 

 m_ctrl_edit_bitrate.SetFocus() ;

 return FALSE;  // return TRUE unless you set the focus to a control
 // 예외: OCX 속성 페이지는 FALSE를 반환해야 합니다.