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