override PreTranslateMessage(MSG* pMsg) if(pMsg->message==WM_MOUSEMOVE) { CPoint cursorpos; GetCursorPos(&cursorpos); CPoint relativepos; //get coordinate of cursor position relative to the rich edit control ... long cindex=CRichEditCtrl::CharFromPos(relativepos); long line=CRichEditCtrl::LineFromChar(cindex); }
计算位置,然后进行scroll,总感觉很不方便,能不能模拟 ctrl + end 来实现滚动到最后面?
ctrl + end 事实上也是计算位置然后滚动,两个方法: 1)象你说的那样发送消息; 2)CRichEditCtrl::GetLineCount int GetLineCount( ) const;Return ValueThe number of lines in this CRichEditCtrl object.ResCall this function to retrieve the number of lines in the CRichEditCtrl object.For more information, seeEM_GETLINECOUNT in the Win32 documentation. //////////////////////////////////////////////////////////////////// CRichEditCtrl::LineScroll void LineScroll( int nLines, int nChars = 0 );ParametersnLinesSpecifies the number of lines to scroll vertically.nCharsSpecifies the number of character positions to scroll horizontally. This value is ignored if the rich edit control has either the ES_RIGHT or ES_CENTER style. Edit styles are specified in Create.///////////////////////////////////////////////////////////// ////////////////实现///////////////////////////////////////// LineScroll(0); LineScroll(GetLineCount( )); //Over. //先获取控件指针这个没问题吧
m_edit.SetSel(-1,-1);
m_edit.SetSel( 1000000,1000000 );
m_edit.Replace....
属性设置,是多行的
m_edit.SetWindowText(String1 + "\r\n");
输入第二行String2的时候:
m_edit.GetWindowText(string);
string += String2 + "\r\n";
m_edit.SetWindowText(string);
m_edit.SetSel(-1,-1);
之后类似
否则我就用cedit了。
[先滚到第一行,然后再从第一行滚到想要的行]
的方法达到要求,这个实现起来较简单,只要获取到当前光标所在行就行了。这是本人的一点经验。
如果有什么不明白的地方请帖出来,正好这两天较闲。
if(pMsg->message==WM_MOUSEMOVE)
{
CPoint cursorpos;
GetCursorPos(&cursorpos);
CPoint relativepos;
//get coordinate of cursor position relative to the rich edit control
...
long cindex=CRichEditCtrl::CharFromPos(relativepos);
long line=CRichEditCtrl::LineFromChar(cindex);
}
ctrl + end 来实现滚动到最后面?
1)象你说的那样发送消息;
2)CRichEditCtrl::GetLineCount
int GetLineCount( ) const;Return ValueThe number of lines in this CRichEditCtrl object.ResCall this function to retrieve the number of lines in the CRichEditCtrl object.For more information, seeEM_GETLINECOUNT in the Win32 documentation.
////////////////////////////////////////////////////////////////////
CRichEditCtrl::LineScroll
void LineScroll( int nLines, int nChars = 0 );ParametersnLinesSpecifies the number of lines to scroll vertically.nCharsSpecifies the number of character positions to scroll horizontally. This value is ignored if the rich edit control has either the ES_RIGHT or ES_CENTER style. Edit styles are specified in Create./////////////////////////////////////////////////////////////
////////////////实现/////////////////////////////////////////
LineScroll(0);
LineScroll(GetLineCount( ));
//Over.
//先获取控件指针这个没问题吧