0279带查询功能的ComboBox控件

来源:互联网 发布:godaddy主机数据库 编辑:程序博客网 时间:2024/04/29 01:14
2009-08-18 08:12 A.M.

带查询功能的ComboBox控件主要是通过CComboBox类的SelectString方法找到符合要求的字符串并将其返回,然后通过CComboBox类的SetEditSel方法使字符串处于选中状态。

代码:

void CComboSelectDlg::OnEditupdateCombo1()
{
// TODO: Add your control notification handler code here
if(!m_Auto)
   return;
CString str;
m_Combo.GetWindowText(str);
int nLength = str.GetLength();
DWORD dwCurSel = m_Combo.GetEditSel();
DWORD dStart = LOWORD(dwCurSel);
DWORD dEnd = HIWORD(dwCurSel);
if(m_Combo.SelectString(-1,str) == CB_ERR)
{
   m_Combo.SetWindowText(str);
   if(dwCurSel != CB_ERR)
    m_Combo.SetEditSel(dStart,dEnd);
}
m_Combo.GetWindowText(str);
if(dEnd < nLength && dwCurSel != CB_ERR)
   m_Combo.SetEditSel(dStart,dEnd);
else
   m_Combo.SetEditSel(nLength,-1);
}

BOOL CComboSelectDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)
{
   m_Auto = TRUE;
   int nKey = (int)pMsg->wParam;
   if(nKey == VK_DELETE || nKey == VK_BACK)
    m_Auto = FALSE;
}
return CDialog::PreTranslateMessage(pMsg);
}

原创粉丝点击