请教各位大虾该程序是如何运行的?(50分)

E

echolan

Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个截获消息的例程:<br>下面定义了一个function用于截取ScrollBox的滚动消息,检测到消息时,弹出对话框!在完成该操作后恢复原有的滚动消息的响应!<br>代码的目的十分清楚,只是不明白,该程序中是如何使Function触发的?请教各位大虾,多多指教!不盛感激!!<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; Db, DBTables, Grids, DBGrids, ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; DBGrid1: TDBGrid;<br>&nbsp; &nbsp; Table1: TTable;<br>&nbsp; &nbsp; DataSource1: TDataSource;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; //function &nbsp;NewWindowProc(WindowHandle:hwnd;TheMessage:WParameter;paramW:Wparameter;paramL:Lparameter):LongInt{$IFDEF WIN32}stdcall;{$ELSE};export;{$ENDIF}<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; 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>&nbsp; oldwindowproc:pointer;<br>function &nbsp;NewWindowProc(WindowHandle:hwnd;TheMessage:WParameter;paramW:Wparameter;paramL:Lparameter):LongInt{$IFDEF WIN32}stdcall;{$ELSE};export;{$ENDIF}<br>begin<br>&nbsp; if TheMessage=WM_VSCROLL then<br>&nbsp; showmessage('You are polling the Vertical ScrollBar!');<br>&nbsp; NewWindowProc:=CallWindowProc(OldWindowProc,WindowHandle,TheMessage,paramW,paramL);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; OldWindowProc:=Pointer(SetWindowLong(DbGrid1.Handle,GWL_WNDPROC,LongInt(@NewWindowProc)));<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; SetWindowLong(DbGrid1.Handle,GWL_WNDPROC,LongInt(OldWindowProc));<br>end;<br><br>end.
 
delphi5开发人员指南上有子类化的例子。你找来看看就清楚了。<br>它是把DBGRID的窗口过程指针转向到了NEWWINDOWPROc函数的。<br>这样,在系统的消息运转时,消息将被传入NEWWINDOWPROC。<br>关于消息驱动机制,我想还是看些关于WINDOWS编程基础的书就行了。
 
有没有哪位能具体说明一下?<br>
 

Similar threads

I
回复
0
查看
497
import
I
I
回复
0
查看
714
import
I
I
回复
0
查看
583
import
I
I
回复
0
查看
620
import
I
顶部