有没有详细的说明如何跟据WINDOWS消息来处理触发事件?(10分)

  • 主题发起人 主题发起人 xky22
  • 开始时间 开始时间
X

xky22

Unregistered / Unconfirmed
GUEST, unregistred user!
有没有详细的说明如何跟据WINDOWS消息来处理触发事件,有源码附上更好。
 
sendmessage<br>postmessage<br>messape.pas
 
要处理消息 首先要知道要处理的消息的消息号是什么 然后针对这个消息写处理函数即可<br>unit Unit1;<br>//处理消息的单元<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br><br>type<br> &nbsp;TForm_czx = class(TForm)<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;procedure OnMessage100(var Message: TMessage);message WM_USER+610;<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form_czx: TForm_czx;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TForm1 }<br><br>procedure TForm_czx.OnMessage100(var Message: TMessage);<br>begin<br> &nbsp;ShowMessage('aaa');<br> &nbsp;Message.Result:=100;<br>end;<br><br>end.<br><br><br><br><br>unit Unit2;<br>//发消息的单元<br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> &nbsp;StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<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><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;hd:HWND;<br>begin<br> &nbsp;hd:=FindWindow('TForm_czx', nil);<br> &nbsp;if hd=0 then Exit;<br> &nbsp;if Sendmessage(hd,WM_USER+610,0,0)=100 then<br> &nbsp;begin<br> &nbsp; &nbsp;ShowMessage('1000');<br> &nbsp;end;<br>end;<br><br>end.
 
接受答案了.
 

Similar threads

后退
顶部