1. 动态创建CMyEdit控件的代码:
pEdit =  new  CMyEdit;  
pEdit->Create(WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_MULTILINE
|WS_VSCROLL, 
   CRect(10,10,100,100), this, 1);  
pEdit->ModifyStyleEx(0,  WS_EX_CLIENTEDGE,  SWP_DRAWFRAME);  2. CMyEdit中被继承的函数
void CMyEdit::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
int iStart, iEnd;
CString m_sSelectedText, m_sEditText;
GetSel(iStart, iEnd);
GetWindowText(m_sEditText); //get begin and end position of selected line (between two '\n')
int iLeft = m_sEditText.ReverseFind('\n');
int iRight = iLeft; 
CString remainStr = m_sEditText.Left(iLeft);
while ( iLeft>iStart )
{
iRight = iLeft-1;
iLeft = remainStr.ReverseFind('\n');
remainStr = remainStr.Left(iLeft-1);
}
  
//set selected for current line
SetFocus();
SetSel(iLeft+1,iRight-iLeft-1);     //这里无效,没有高亮显示整行。
//get text of selected line
m_sSelectedText = m_sEditText.Mid(iLeft+1,iRight-iLeft-1);//这里得到了整行的内容 CEdit::OnLButtonDblClk(nFlags, point);
}???
谢谢

解决方案 »

  1.   

    CEdit自己就有设置整行高亮的效果(北京为蓝色,字体为白色)。
      

  2.   

    既然楼上说没有就使用RichEdit
      

  3.   

    不会是你在主界面中已经处理过双击消息的关系吧?呵呵,给个Sample我测试一下,[email protected]
      

  4.   

    I_Love_CPP(我愛C++) ( ) :不是的,CEdit自己默认的双击高亮显示的是当前选中的一个单词,而不是一整行
      

  5.   

    楼主是不是想双击选中CEdit的某行呀,,
    代码是否有误,,
    改成
    void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
    int iLeft = m_sEditText.ReverseFind('\n');
    int iRight = iLeft;
    CString remainStr = m_sEditText.Left(iLeft);
    if(iLeft<iStart)
    iRight =  m_sEditText.GetLength();  // while ( iLeft>iStart )
    {
    iRight = iLeft-1;
    iLeft = remainStr.ReverseFind('\n');
    remainStr = remainStr.Left(iLeft-1);
    }
    //set selected for current line
    SetFocus();

    SetSel(iLeft+1,iRight); //这里无效,没有高亮显示整行。
      

  6.   

    发现是最后一行在作怪,, 注释调就可以了..
    CEdit::OnLButtonDblClk(nFlags, point);
      

  7.   

    谢谢 tonyswe(tong) ( )我太马虎了,Setsel那里参数写错了。最后一行注释掉就好了。解决了,结贴。
      

  8.   

    ==========================================================================
    把CEdit::OnLButtonDblClk(nFlags, point);//注释起来,另:
    CEdit::SetSel 
    void SetSel( DWORD dwSelection, BOOL bNoScroll = FALSE );void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );ParametersdwSelectionSpecifies the starting position in the low-order word and the ending position in the high-order word. If the low-order word is 0 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.低位字指定起始位置,高位字为结束位置。如果低位为0,高位为-1,则编辑控件中的全部文本被选中;如果低位字为-1,则任何当前选定内容被去掉选定状态。 bNoScrollIndicates 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.指示是否显示脱字符是滚动可见的。如果值为FALSE,则显示,TRUE不显示。 nStartCharSpecifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.指出当前选中部分的开始位置。如果nStartChar=0且nEndChar=-1,则编辑控件的文本被全选;如果nStartChar=-1,则任何当前选定内容被去掉选定状态。 nEndCharSpecifies the ending position.指出结束位置。 ResCall this function to select a range of characters in an edit control.调用此成员函数在一个编辑控件中选择一定范围的字符。