我倒是做了一个例子,不知道是不是合乎你的要求,我实现的效果是:界面有两个Grid,分别为Grid1和Grid2,当Grid1获得焦点并且鼠标在其上进行滚动时,将弹出对话框。代码如下: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, Grids, DBGrids;type TForm1 = class(TForm) DBGrid1: TDBGrid; ADOConnection1: TADOConnection; ADOTable1: TADOTable; DataSource1: TDataSource; DBGrid2: TDBGrid; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } procedure DoAppMessage(var Msg: TMsg; var Handled: Boolean); end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DoAppMessage(var Msg: TMsg; var Handled: Boolean); var i: integer; begin Handled := False; if Msg.message=WM_MOUSEWHEEL then begin if (FindVCLWindow(Mouse.CursorPos)<>DBGrid1) then Exit; for i:=0 to Self.ComponentCount-1 do begin if not (Self.Components[i] is TWinControl) then continue; if not TWinControl(Self.Components[i]).Focused then continue; if not (Self.Components[i]=DBGrid1) then continue; ShowMessage('haha'); Handled := True; end; end; end;procedure TForm1.FormCreate(Sender: TObject); begin Application.OnMessage := DoAppMessage; end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid2: TDBGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DoAppMessage(var Msg: TMsg; var Handled: Boolean);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DoAppMessage(var Msg: TMsg; var Handled: Boolean);
var
i: integer;
begin
Handled := False;
if Msg.message=WM_MOUSEWHEEL then
begin
if (FindVCLWindow(Mouse.CursorPos)<>DBGrid1) then Exit;
for i:=0 to Self.ComponentCount-1 do
begin
if not (Self.Components[i] is TWinControl) then continue;
if not TWinControl(Self.Components[i]).Focused then continue;
if not (Self.Components[i]=DBGrid1) then continue;
ShowMessage('haha');
Handled := True;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := DoAppMessage;
end;end.