长
长发
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> OldWndProc : Pointer;<br> WndProcPtr : Pointer;<br> Procedure WndMethod(var Msg : TMessage);<br> Procedure HandleAppMessage(var Msg : TMsg;var Handled : Boolean);<br> public<br> end;<br>var<br> Form1: TForm1;<br>implementation<br>uses unit2;<br>{$R *.dfm}<br>{ TForm1 }<br>procedure TForm1.HandleAppMessage(var Msg: TMsg; var Handled: Boolean);<br>begin<br> if Msg.message = DDGM_FOOMSG then<br> showmessage(Format('Message seen by OnMessage! value is: $%x',[Msg.message]));<br>end;<br>procedure TForm1.WndMethod(var Msg: TMessage);<br>begin<br> if Msg.Msg = DDGM_FOOMSG then<br> showmessage(Format('Message seen by WndMethod! value is: $%x',[Msg.Msg]));<br> with Msg do<br> Result := callwindowProc(OldWndProc,Application.Handle,Msg,WParam,LParam);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> Application.OnMessage := HandleAppMessage;//set OnMessage handler<br> WndProcPtr := MakeObjectInstance(WndMethod); //make window Proc<br> OldWndProc := Pointer(SetWindowLong(Application.Handle,gwl_wndProc,Integer(WndProcPtr)));<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> SetWindowLong(Application.Handle,GWL_WNDPROC,Longint(OldWndProc));<br> FreeObjectInstance(WndProcPtr);<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> SendMessage(Application.Handle,DDGM_FOOMSG,0,0);<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> PostMessage(Application.Handle,DDGM_FOOMSG,0,0);<br>end;<br>end.<br><br>unit Unit2;<br>interface<br>uses Forms,Messages;<br>const<br> DDGM_FOOMSG = WM_USER;<br>implementation<br>uses Windows,SysUtils,Dialogs;<br>var<br> WProc : Pointer;<br>Function NewWndProc(Handle : hWnd; Msg,WParam,LParam : LongInt):LongInt;stdcall;<br>begin<br> if Msg = DDGM_FOOMSG then<br> showmessage(Format('Message seen by WndProc! value is: $%x',[Msg]));<br> Result := CallWindowProc(WProc,Handle,Msg,WParam,LParam);<br>end;<br>initialization<br>{set window procedure of application window}<br> WProc := pointer(SetWindowLong(Application.Handle,gwl_wndProc,integer(@NewWndProc)));<br>end.<br><br>这是书上的例子 但我老是不明白其中的每步的意思和他的原理 那位GG可以给我详细讲解一下