E
echolan
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个截获消息的例程:<br>下面定义了一个function用于截取ScrollBox的滚动消息,检测到消息时,弹出对话框!在完成该操作后恢复原有的滚动消息的响应!<br>代码的目的十分清楚,只是不明白,该程序中是如何使Function触发的?请教各位大虾,多多指教!不盛感激!!<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Db, DBTables, Grids, DBGrids, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Panel1: TPanel;<br> DBGrid1: TDBGrid;<br> Table1: TTable;<br> DataSource1: TDataSource;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> //function NewWindowProc(WindowHandle:hwnd;TheMessage:WParameter;paramW:Wparameter;paramL:Lparameter):LongInt{$IFDEF WIN32}stdcall;{$ELSE};export;{$ENDIF}<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>type<br>{$IFDEF WIN32}<br>WParameter=LongInt;<br>{$ELSE}<br>WParameter=Word;<br>{$ENDIF}<br>LParameter=LongInt;<br>var<br> oldwindowprocointer;<br>function NewWindowProc(WindowHandle:hwnd;TheMessage:WParameter;paramW:Wparameter;paramL:Lparameter):LongInt{$IFDEF WIN32}stdcall;{$ELSE};export;{$ENDIF}<br>begin<br> if TheMessage=WM_VSCROLL then<br> showmessage('You are polling the Vertical ScrollBar!');<br> NewWindowProc:=CallWindowProc(OldWindowProc,WindowHandle,TheMessage,paramW,paramL);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> OldWindowProc:=Pointer(SetWindowLong(DbGrid1.Handle,GWL_WNDPROC,LongInt(@NewWindowProc)));<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> SetWindowLong(DbGrid1.Handle,GWL_WNDPROC,LongInt(OldWindowProc));<br>end;<br><br>end.