5,392
社区成员
发帖
与我相关
我的任务
分享
private
{ Private declarations }
FOldProc: TWndMethod;
procedure MyProc(var message: TMessage);
create。。
FOldProc := DBGrid1.WindowProc;
DBGrid1.WindowProc := MyProc;
procedure TForm3.MyProc(var message: TMessage);
var
curpos: integer;
info: TScrollInfo;
begin
if (message.Msg = WM_HSCROLL) then
begin
info.cbSize := SizeOf(TScrollInfo);
info.fMask := SIF_ALL;
GetScrollInfo(DBGrid1.Handle, SB_HORZ, info);
if (info.nPos = 0) and (info.nTrackPos = 0) and (message.WParam = 3) then
SendMessage(DBGrid1.Handle, WM_HSCROLL, SB_RIGHT, 0)
// SetScrollPos(DBGrid1.Handle, SB_HORZ, info.nMax, True)
else if (info.nPos = info.nMax) and (info.nTrackPos = 0) and (message.WParam = 2) then
SendMessage(DBGrid1.Handle, WM_HSCROLL, SB_LEFT, 0);
// SetScrollPos(DBGrid1.Handle, SB_HORZ, 0, True);
end;
FOldProc(message);
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DBGrid1.WindowProc := FOldProc;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
SendMessage(DBGrid1.Handle, WM_HSCROLL, SB_LEFT, 0);
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
SendMessage(DBGrid1.Handle, WM_HSCROLL, SB_RIGHT, 0);
end;