不是光标,而是鼠标在第几行?

解决方案 »

  1.   

    GetCursorPos  获取鼠标位置然后根据richedit的第一行位置以及每一行的高度
    来减法除法求行数可行不?
      

  2.   

    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 */);
      

  3.   

    先判断RichEdit每行的位置,再根据鼠标点的坐标判断,就像落在矩形中判断一样。
      

  4.   

    To cnzdgs:
    CRichEditCtrl的CharFromPos函数用不了啊,查了一下以前的帖子都没怎么讲清楚该怎么用这个函数。
      

  5.   

    终于在网上查到怎么用了LRESULT lRet = pEdit->SendMessage(EM_CHARFROMPOS, 0, (LPARAM)&pt);
    TRACE2("第%d个字符在第%d行\n", LOWORD(lRet), pEdit->LineFromChar(LOWORD(lRet)));谢谢大家!