Coding Change World

代码改变世界
CGridCtrl中的combox增加模糊查找功能
void CComboEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar == VK_ESCAPE) 
	{
        CWnd* pOwner = GetOwner();
        if (pOwner)
            pOwner->SendMessage(WM_KEYUP, nChar, nRepCnt + (((DWORD)nFlags)<<16));
        return;
    }

	if (nChar == VK_TAB || nChar == VK_RETURN || nChar == VK_ESCAPE)
    {
        CWnd* pOwner = GetOwner();
        if (pOwner)
            pOwner->SendMessage(WM_KEYUP, nChar, nRepCnt + (((DWORD)nFlags)<<16));
        return;
    }
	FuzzySearch();
	CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}
void FindStrNoCase(CStringArray& strTotalArr,CString strFind,CStringArray& strDestArr);
void CComboEdit::FuzzySearch()
{
	// 模糊查找实现

	CInPlaceList1* pOwner = (CInPlaceList1*) GetOwner();  // This MUST be a CInPlaceList1
	if (pOwner)
	{
		CString str;
		GetWindowText(str);
		CStringArray strArr;
		if (str==L"")//  全部删除字符时候,回到初始化状态,显示所有
		{
			pOwner->ResetContent();
			for (int ii=0;ii<m_strTotalArr.GetCount();ii++)
			{
				pOwner->AddString(m_strTotalArr[ii]);
			}
		}

		FindStrNoCase(m_strTotalArr,str,strArr);
		if (strArr.GetCount()>0)
		{
			pOwner->ResetContent();
		}


		SetWindowText(str);
		SetSel((int)_tcslen(str), -1);

		for (int ii=0;ii<strArr.GetCount();ii++)
		{
			pOwner->AddString(strArr[ii]);
		}

	}
}
void FindStrNoCase(CStringArray& strTotalArr,CString strFind,CStringArray& strDestArr)
{
	strDestArr.RemoveAll();
	for (int ii=0;ii<strTotalArr.GetCount();ii++)
	{
		CString str=strTotalArr[ii];
		str.MakeLower();
		strFind.MakeLower();
		if (str.Find(strFind)!=-1)
		{
			strDestArr.Add(strTotalArr[ii]);
		}
	}
}

  

posted on 2021-07-24 13:56  alphaxz  阅读(111)  评论(0编辑  收藏  举报