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);
// 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);
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);
改为 LPTSTR lpstr = new _TCHAR[255];
去掉 *(LPWORD)lpstr = 255;测试成功