Example // The pointer to my edit control. extern CEdit* pmyEdit; // The index of the char to get information on. extern int nIndex;CString strText;pmyEdit->GetWindowText(strText); strText = strText.Mid(nIndex, 1);// Get the text extent of the character. CDC* pDC = pmyEdit->GetDC(); CSize sz = pDC->GetTextExtent(strText); pmyEdit->ReleaseDC(pDC);CPoint pt = pmyEdit->PosFromChar(nIndex);// Dump the index, character, line number, and character bounds. TRACE("nIndex = %d, character = %c, line = %d, bounds = {%d, %d, %d, %d}\r\n", nIndex, strText[0], pmyEdit->LineFromChar(nIndex), pt.x /* left */, pt.y /* top */, pt.x+sz.cx /* right */, pt.y+sz.cy /* bottom */);
先判断RichEdit每行的位置,再根据鼠标点的坐标判断,就像落在矩形中判断一样。
To cnzdgs: CRichEditCtrl的CharFromPos函数用不了啊,查了一下以前的帖子都没怎么讲清楚该怎么用这个函数。
来减法除法求行数可行不?
// The pointer to my edit control.
extern CEdit* pmyEdit;
// The index of the char to get information on.
extern int nIndex;CString strText;pmyEdit->GetWindowText(strText);
strText = strText.Mid(nIndex, 1);// Get the text extent of the character.
CDC* pDC = pmyEdit->GetDC();
CSize sz = pDC->GetTextExtent(strText);
pmyEdit->ReleaseDC(pDC);CPoint pt = pmyEdit->PosFromChar(nIndex);// Dump the index, character, line number, and character bounds.
TRACE("nIndex = %d, character = %c, line = %d, bounds = {%d, %d, %d, %d}\r\n",
nIndex, strText[0], pmyEdit->LineFromChar(nIndex),
pt.x /* left */, pt.y /* top */,
pt.x+sz.cx /* right */, pt.y+sz.cy /* bottom */);
CRichEditCtrl的CharFromPos函数用不了啊,查了一下以前的帖子都没怎么讲清楚该怎么用这个函数。
TRACE2("第%d个字符在第%d行\n", LOWORD(lRet), pEdit->LineFromChar(LOWORD(lRet)));谢谢大家!