转自:http://blog.csdn.net/riag/article/details/3948124
CEdit的接口LineLength(nCharIndex) 的参数并不是指CEdit的第几行,需要通过函数LineIndex来进行转换。
- int nIndex = 4 ; //假设要获取CEdit的第4行的文字
- int nCharIndex = nCharIndex = this->LineIndex(nIndex) ;
- int nlen = this->LineLength(nCharIndex) ;
- CString strText ;
- this->GetLine(nIndex, strText.GetBuffer(nlen), nlen) ;
- strText.ReleaseBuffer() ;
下面是获取鼠标双击CEdit的那行文字
- void MyEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- CEdit::OnLButtonDblClk(nFlags, point) ;
- int nIndex = this->CharFromPos(point) ;
- int nCharIndex = LOWORD(nIndex) ;
- nIndex = HIWORD(nIndex) ;
- if (nIndex == -1)
- {
- return ;
- }
- CString strText ;
- int nCharIndex = this->LineIndex(nIndex) ;
- int nlen = this->LineLength(nCharIndex) ;
- this->GetLine(nIndex, strText.GetBuffer(nlen), nlen) ;
- strText.ReleaseBuffer() ;
- }