void FindText( CRicheditctrl & cRichEdit ,LPCTSTR pszText,BOOL bWholeWord,BOOL bCaseSen,BOOL bUp )
{
DWORD dwOptions = 0;
if (bWholeWord)
dwOptions |= FR_WHOLEWORD;
if (bCaseSen)
dwOptions |= FR_MATCHCASE;
if (!bUp)
dwOptions |= FR_DOWN;
CHARRANGE crCurSel;
m_cRichEdit.GetSel(crCurSel);
FINDTEXTEXW ftw;
ZeroMemory(&ftw,sizeof(FINDTEXTEXW));
if (bUp) //注意,如果是向上查找的话,FINDTEXTEXW 中的chrg 应该是倒序
{
ftw.chrg.cpMin = crCurSel.cpMin ;
ftw.chrg.cpMax = 0;
}
else
{
ftw.chrg.cpMin = crCurSel.cpMax;
ftw.chrg.cpMax = -1;
}
#ifdef _UNICODE
ftw.lpstrText = pszText;
#else
USES_CONVERSION;
ftw.lpstrText = A2W(pszText);
#endif
if( -1 == cRichEdit.SendMessage(EM_FINDTEXTEXW,dwOptions,(LPARAM)&ftw) )
{
CString strText;
strText.Format(_T("没有找到 \" %s \" "),pszText);
MessageBox(strText);
}
else
{
cRichEdit.SetSel(ftw.chrgText);
cRichEdit.SendMessage(EM_HIDESELECTION,0,0);
}
}
来源
CRichEditCtrl系列讲堂2 查找功能的实现
最新推荐文章于 2022-12-02 18:59:16 发布