MFC VC++ アプリケーション Tip集 サイト


3章.CComboBoxクラス

3−2.指定した文字列をコンボボックスリストで選択する。




BOOL SetCombStr( UINT nID , const CString& str )
{
	BOOL bRet = FALSE;
	CComboBox * pCombo = ( CComboBox * )GetDlgItem( nID );
	UINT nSum = pCombo->GetCount();
	CString strComp;
	int nIndex = -1;
	for( UINT i = 0 ; i < nSum ; i++ ){
		pCombo->GetLBText( i , strComp );
		if( ! str.Compare( strComp ) ){
			nIndex = i;
			break;
		}
	}
	if( nIndex != -1 ){
		pCombo->SetCurSel( nIndex );
		bRet = TRUE;
	}else{
		SetDlgItemText( nID , str );
	}
	return bRet;
}


Top へ戻る