Delphi to use the scroll bar

DELPHI default scroll bar to send a message format:

function TControl.Perform(
Msg: Cardinal;
WParam: WPARAM;
LParam: LPARAM
): LRESULT;
如:Memo1.Perform(WM_HSCROLL, SB_LEFT, 0);

 

The horizontal scroll bar messages WM_HSCROLL
SendMessage (Memo1.Handle, WM_HSCROLL, MAKEWPARAM (SB_THUMBPOSITION, 50), 0); // scroll to this
SendMessage (Memo1.Handle, WM_HSCROLL, SB_LEFT, 0); // left edge of the
SendMessage (Memo1.Handle, WM_HSCROLL, SB_RIGHT, 0); // right edge
SendMessage (Memo1.Handle, WM_HSCROLL, SB_PAGELEFT, 0); // turning left
SendMessage (Memo1.Handle, WM_HSCROLL, SB_PAGERIGHT, 0); // page right
SendMessage (Memo1.Handle, WM_HSCROLL, SB_LINELEFT, 0 ); // scroll left
SendMessage (Memo1.Handle, WM_HSCROLL, SB_LINERIGHT, 0); // scroll right

Vertical scroll bar message a WM_VSCROLL
the SendMessage (Memo1.Handle, a WM_VSCROLL, MAKEWPARAM (the SB_THUMBPOSITION, 50), 0); // scroll 50 to this position is scrolled to the specified line number
SendMessage (Memo1.Handle, WM_VSCROLL, SB_TOP, 0); // top
SendMessage (Memo1.Handle, WM_VSCROLL, SB_BOTTOM, 0); // bottom
SendMessage (Memo1.Handle, WM_VSCROLL, SB_PAGEUP, 0); // page up
SendMessage (Memo1.Handle, WM_VSCROLL, SB_PAGEDOWN, 0); // down
SendMessage (Memo1.Handle, WM_VSCROLL, SB_LINEUP, 0); // scroll up
SendMessage (Memo1.Handle, WM_VSCROLL, SB_LINEDOWN, 0); // scroll down

//获得滚动条的位置
The GetScrollPos function retrieves the current position of the scroll box (thumb) in the specified
scroll bar. The current position is a relative value that depends on the current scrolling range.
For example, if the scrolling range is 0 through 100 and the scroll box is in the middle of the
bar, the current position is 50.

{GetScrollPos function retrieves the specified scroll box in the scroll bar (thumb) is the current position. The current position is a relative value, depending on the current scrolling range.
For example, if the scroll range is 0 to 100, and the scroll box located in the middle of the bar, the current position 50. }

GetScrollPos int (
the HWND the hWnd,
int nBar
);
var
H, V: Integer;
the begin
H: = GetScrollPos (Memo1.Handle, SB_HORZ);
V: = GetScrollPos (Memo1.Handle, SB_VERT);
the Caption: = the Format ( 'level value vertical =% d value =% d ', [H, V]);
End;

//显示和隐藏滚动条
ShowScrollBar(Memo1.Handle,SB_HORZ,false); //隐藏MEMO水平滚动条
ShowScrollBar(Memo1.Handle,SB_VERT,false); //隐藏MEMO垂直滚动条

//判断 滚动条是否出现
procedure TForm1.Button1Click(Sender: TObject);
begin
  if (GetWindowlong(Memo1.Handle, GWL_STYLE) and WS_VSCROLL) > 0 then ShowMessage('垂直滚动条显示');
  if (GetWindowlong(Memo1.Handle, GWL_STYLE) and WS_HSCROLL) > 0 then ShowMessage('水平滚动条显示');
end;
  

 

Guess you like

Origin www.cnblogs.com/guorongtao/p/11880391.html