就是好像word中的查找功能一样
如果按下查找botton后,在编辑框中找到要查找的字符串时,如何将该字符串高亮度显示???谢谢各位!

解决方案 »

  1.   

    CEdit::SetSel
    This method selects a range of characters in an edit control.void SetSel(
    DWORD dwSelection,
    BOOL bNoScroll = FALSE );void SetSel(
    int nStartChar,
    int nEndChar,
    BOOL bNoScroll = FALSE ); ParametersdwSelection 
    Specifies the starting position in the low-order word and the ending position in the high-order word. If the low-order word is zero and the high-order word is –1, all the text in the edit control is selected. If the low-order word is –1, any current selection is removed. bNoScroll 
    Indicates whether the caret should be scrolled into view. If FALSE, the caret is scrolled into view. If TRUE, the caret is not scrolled into view. nStartChar 
    Specifies the starting position. If nStartChar is zero and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed. nEndChar 
    Specifies the ending position. 
      

  2.   

    先用GetWindowText/Find找到文本位置,然后SetSel
      

  3.   

    void CTestDlg::Onselect() 
    {
    UpdateData(TRUE);
    m_edit="FUNNY LEUNG";
    m_control.SetSel(0,-1,FALSE);
    UpdateData(FALSE);


    }
    我这样写,执行Onselect()后并没有选中,那是什么原因啊???
    m_edit是edit box的变量
    m_control是控件变量
      

  4.   

    还有SetSel的最后一个参数是什么意思??
      

  5.   

    m_control.SetFocus();
    m_control.SetSel(0,-1,FALSE);最后一个参数我也不清楚,从MSDN的字面意思我没看出来,在程序里试了也没看出来
      

  6.   

    int nStartPos = 0;
    int nStopPos = 0;
    int iFind =0;
    if (m_strFind.IsEmpty()) return;
    while (m_strContent.Find(m_strFind, nStartPos)!=-1)
    {
    nStartPos = m_strContent.Find(m_strFind, nStartPos);
    nStopPos = nStartPos + m_strFind.GetLength();
    m_edit.SetSel(nStartPos, nStopPos); CHARFORMAT cf;
    cf.cbSize = sizeof(CHARFORMAT);
    m_edit.GetSelectionCharFormat(cf); cf.crTextColor = 255;
    cf.dwMask = CFM_COLOR;
    if (cf.dwEffects & CFE_AUTOCOLOR)
    cf.dwEffects -= CFE_AUTOCOLOR; m_edit.SetSelectionCharFormat(cf);
    nStartPos = nStopPos;
    iFind++;
    }
    m_edit.SetSel(0,0);
    CString msg;
    msg.Format("<%s>在原文中共出现%d次",m_strFind,iFind);给你段我的代码,这段代码中m_edit是CRichEidt 可以设置高亮显示的颜色 你可以参考参考