看看下面的消息,使用参数SB_BOTTOM就可以满足你的要求,在插入字符串后向你的RichEdit发送这个消息就可以了WM_VSCROLL nScrollCode = (int) LOWORD(wParam); // scroll bar value nPos = (short int) HIWORD(wParam); // scroll box position hwndScrollBar = (HWND) lParam; // handle to scroll bar
Parameters nScrollCode Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values: Value Meaning SB_BOTTOM Scrolls to the lower right. SB_ENDSCROLL Ends scroll. SB_LINEDOWN Scrolls one line down. SB_LINEUP Scrolls one line up. SB_PAGEDOWN Scrolls one page down. SB_PAGEUP Scrolls one page up. SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation. SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to. SB_TOP Scrolls to the upper left. nPos Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used. hwndScrollBar Value of lParam. If the message is sent by a scroll bar, then hwndScrollBar is the handle to the scroll bar control. If the message is not sent by a scroll bar, hwndScrollBar is NULL.
SendMessage(RichEdit1.Handle,WM_Vscroll,sb_LineDown,0);
我需要当RichEdit出现滚动条后,能每次都自动把滑块滑到最底部,我查看了API,知道用GetScrollRange、SetScrollPos可以搞定,但我对具体参数的类型设置不是很清楚,能否帮我说一说?或者做一个小程序演示一下?
nScrollCode = (int) LOWORD(wParam); // scroll bar value
nPos = (short int) HIWORD(wParam); // scroll box position
hwndScrollBar = (HWND) lParam; // handle to scroll bar
Parameters
nScrollCode
Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values: Value Meaning
SB_BOTTOM Scrolls to the lower right.
SB_ENDSCROLL Ends scroll.
SB_LINEDOWN Scrolls one line down.
SB_LINEUP Scrolls one line up.
SB_PAGEDOWN Scrolls one page down.
SB_PAGEUP Scrolls one page up.
SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.
SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.
SB_TOP Scrolls to the upper left.
nPos
Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.
hwndScrollBar
Value of lParam. If the message is sent by a scroll bar, then hwndScrollBar is the handle to the scroll bar control. If the message is not sent by a scroll bar, hwndScrollBar is NULL.
还是告诉我如何调用GetScrollRange吧!
procedure TForm1.btnAddLineClick(Sender: TObject);
Var nLineCount:Integer;
nScrollCount:Integer;
begin
//取得当前RichEdit中的内容的行数
nLineCount:=SendMessage(RichEdit1.Handle ,EM_GETLINECOUNT ,0,0);
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
Richedit1.Lines.Add('aaaaaaaaaaaaaaa');
//计算出需要滚动的行数
nScrollCount:= SendMessage(RichEdit1.Handle ,EM_GETLINECOUNT ,0,0)-nLineCount;
SendMessage(RichEdit1.Handle,EM_LINESCROLL ,0,nCount);
end;
RichEdit1.SelLength := 0;
RichEdit1.SelStart:=RichEdit1.GetTextLen;
RichEdit1.Perform( EM_SCROLLCARET, 0, 0 );