一段消息截取的演示代码? ( 积分: 30 )

  • 主题发起人 主题发起人 qq258268936
  • 开始时间 开始时间
Q

qq258268936

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Buttons, ExtCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;btn1: TButton;<br> &nbsp; &nbsp;btn2: TButton;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;Label3: TLabel;<br> &nbsp; &nbsp;Panel1: TPanel;<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;Procedure WinMsg (Var Msg : TMsg; Var Handled : Boolean);<br><br> &nbsp; &nbsp;Procedure DealFun1;//处理函数1<br> &nbsp; &nbsp;Procedure DealFun2;//处理函数2<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>{ TForm1 }<br><br>procedure TForm1.WinMsg(var Msg: TMsg; var Handled: Boolean);<br>Var<br> &nbsp;aPt:Pointer;<br>begin<br> &nbsp;If Msg.Message = WM_LBUTTONDOWN then<br> &nbsp;begin<br> &nbsp; &nbsp;aPt:=FindVCLWindow(Msg.pt); //获取对应的指针地址<br> &nbsp; &nbsp;if TButtonControl(aPt).ClassName&lt;&gt;'TButton' then Exit;<br> &nbsp; &nbsp;Label1.Caption := '您按下了:'+TButton(aPt).Caption;<br> &nbsp; &nbsp;case TButtonControl(aPt).Tag of<br> &nbsp; &nbsp; &nbsp;1:<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DealFun1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TButtonControl(aPt).SetFocus;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;2:<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DealFun2;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TButtonControl(aPt).SetFocus;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;Application.OnMessage := WinMsg;<br>end;<br><br>procedure TForm1.DealFun1;<br>begin<br> &nbsp;Label2.Caption := '处理事件1';<br>end;<br><br>procedure TForm1.DealFun2;<br>begin<br> &nbsp;Label2.Caption := '处理事件2';<br>end;<br><br>end.<br>共同计论,集思广议
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Buttons, ExtCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;btn1: TButton;<br> &nbsp; &nbsp;btn2: TButton;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;Label3: TLabel;<br> &nbsp; &nbsp;Panel1: TPanel;<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;Procedure WinMsg (Var Msg : TMsg; Var Handled : Boolean);<br><br> &nbsp; &nbsp;Procedure DealFun1;//处理函数1<br> &nbsp; &nbsp;Procedure DealFun2;//处理函数2<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>{ TForm1 }<br><br>procedure TForm1.WinMsg(var Msg: TMsg; var Handled: Boolean);<br>Var<br> &nbsp;aPt:Pointer;<br>begin<br> &nbsp;If Msg.Message = WM_LBUTTONDOWN then<br> &nbsp;begin<br> &nbsp; &nbsp;aPt:=FindVCLWindow(Msg.pt); //获取对应的指针地址<br> &nbsp; &nbsp;if TButtonControl(aPt).ClassName&lt;&gt;'TButton' then Exit;<br> &nbsp; &nbsp;Label1.Caption := '您按下了:'+TButton(aPt).Caption;<br> &nbsp; &nbsp;case TButtonControl(aPt).Tag of<br> &nbsp; &nbsp; &nbsp;1:<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DealFun1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TButtonControl(aPt).SetFocus;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;2:<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DealFun2;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TButtonControl(aPt).SetFocus;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;Application.OnMessage := WinMsg;<br>end;<br><br>procedure TForm1.DealFun1;<br>begin<br> &nbsp;Label2.Caption := '处理事件1';<br>end;<br><br>procedure TForm1.DealFun2;<br>begin<br> &nbsp;Label2.Caption := '处理事件2';<br>end;<br><br>end.<br>共同计论,集思广议
 
?有什么问题?
 
if TButtonControl(aPt).ClassName&lt;&gt;'TButton' then Exit;<br>什么意思?
 
接受答案了.
 
后退
顶部