15,979
社区成员
发帖
与我相关
我的任务
分享
BOOL CAutoCompleteComboBox::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
m_bWorkOnText = TRUE;
int nVKey = (int) pMsg->wParam;
if (nVKey == VK_DELETE || nVKey == VK_BACK)
m_bWorkOnText = FALSE;
}
return CComboBox::PreTranslateMessage(pMsg);
}
void CAutoCompleteComboBox::OnEditUpdate()
{
// TODO: Add your control notification handler code here
if (!m_bWorkOnText)
return;
//取得编辑框中的文字;
CString strWindowText;
GetWindowText(strWindowText);
int nLength = strWindowText.GetLength();
//取得当前的选择范围
DWORD dwCurSel = GetEditSel();
WORD dStart = LOWORD(dwCurSel);
WORD dEnd = HIWORD(dwCurSel);
// 实际做查找和选择的语句
if (SelectString(-1, strWindowText) == CB_ERR)
{
SetWindowText(strWindowText); // 恢复文字
if (dwCurSel != CB_ERR)
SetEditSel(dStart, dEnd); // 恢复原先的位置
}
// 把添加的文字做为选择的文字
if (dEnd < nLength && dwCurSel != CB_ERR)
SetEditSel(dStart, dEnd);
else
SetEditSel(nLength, -1);
}
if ( HIWORD(wParam) == EN_CHANGE )
{
.....
return TRUE;//不用系统再处理
}
else
return CComboBox::OnCommand(wParam, lParam);//不处理的让系统处理
ShowDropDown(TRUE); //使用这个鼠标会不见
::SetCursor(::LoadCursor(NULL,IDC_ARROW)); //重新显示鼠标