Колесико мыши в DBGrid
Мы просто изменим WndProc для DBGrid и поместим там то, что нам нужно.
type TomaInvento = class(TControl);
Так что мы можем позже заменить WndProc командой, подобно:
DBGrid1.WindowProc := DBGrid1PillaLaRueda;
например, в событии OnCreate формы.
Здесь мы имеем модуль формы, в котором помещено DBGrid, TTable и TDataSource.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, Grids, DBGrids, Db, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DBGrid1PillaLaRueda(var Message: TMessage);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TomaInvento = class(TControl);
procedure TForm1.DBGrid1PillaLaRueda(var Message: TMessage);
var
Cuanto : short;
begin
if (Message.Msg = WM_MOUSEWHEEL) then begin
Cuanto:=HIWORD(Message.WParam);
Cuanto:=Cuanto div 120;
DbGrid1.DataSource.DataSet.MoveBy(-Cuanto)
end else TomaInvento(DBGrid1).WndProc(Message);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DBGrid1.WindowProc := DBGrid1PillaLaRueda;
end;
end.
В основном, когда мы перемещаем колесо вверх (двигаем палец от себя) сообщение дает нам положительное значение в HiWord для wParam, а когда мы перемещаем колесо вниз (перемещая палец к себе), мы получаем отрицательное значение.
А в остальном, читайте справку Win32.hlp относительно WM_MOUSEWHEEL.
Комментарии