cedit   
  crichedit   
  ceditview   
  cricheditview有许多行字符串,请问怎么才能知道鼠标在哪个字符之上

解决方案 »

  1.   

    Example#ifdef _DEBUG
       // The pointer to my edit.
       extern CEdit* pmyEdit;
       // The point where the user clicked the mouse.
       extern CPoint myPt;   int n = pmyEdit->CharFromPos(myPt);
       int nLineIndex = HIWORD(n);
       int nCharIndex = LOWORD(n);
       TRACE(TEXT("nLineIndex = %d, nCharIndex = %d\r\n"), nLineIndex, nCharIndex);
    #endif这样就得到了鼠标所在字符的nLineIndex, nCharIndex。
      CString strLine;
      pmyEdit->GetLine(nLineIndex, strLine.GetBuffer(pmyEdit->LineLength(nLineIndex)));strLine.Mid(nCharIndex, 1);
      

  2.   

    pmyEdit->LineLength(nLineIndex);请问为什么得到的总是第一行字符的个数用pmyEdit->GetLine并没有得到字符串,为什么?
      

  3.   

    CPoint myPt;
    LPTSTR lpstr = new char[255];
    *(LPWORD)lpstr = 255; int n = m_edit.CharFromPos(myPt);
    int nLineIndex = HIWORD(n);
    int nCharIndex = LOWORD(n); m_edit.GetLine(nLineIndex, lpstr);
    CString strLine = lpstr; strLine.Mid(nCharIndex, 1);
      

  4.   

    感谢 xlzxlich(阳光) 的解答把 LPTSTR lpstr = new char[255];
    改为 LPTSTR lpstr = new _TCHAR[255];
    去掉 *(LPWORD)lpstr = 255;测试成功