unit UMessages;
//interception des messages parvenant directement
à la fenêtre d'application
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Memo2: TMemo;
Labelmemo1: TLabel;
Labelmemo2: TLabel;
Label5: TLabel;
Label6: TLabel;
LabelWparam: TLabel;
LabelLparam: TLabel;
LabelTime: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Déclarations privées
}
public
{ Déclarations publiques }
end;
{TMSG (2.x) (WINTYPES unit)
Aide dans TPW1.5
TMsg = packed record
hwnd: HWnd;
message: Word;
wParam: Word;
lParam: LongInt;
time: Longint;
pt: TPoint;
end;
The TMSG structure contains information from the Windows application queue.
Member Description
hwnd Identifies the window that receives the message.
message Specifies the message number.
wParam Specifies additional information about the message. The
exact meaning depends on the message value.
lParam Specifies additional information about the message. The
exact meaning depends on the message value.
time Specifies the time at which the message was posted.
pt Specifies the position of the cursor, in screen coordinates,
when the message was posted.
See Also
TEVENTMSG, GetMessage
}
var
Form1: TForm1;
implementation
var HwndAvantPreced,HwndPrecedent:HWND;
//Utilisez Winsight en mode suivi des messages options
(souris,fenêtre,système)
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var infoWindow:string;
begin
if not Handled then
with Msg do
begin
if hwnd=Form1.handle then
memo1.lines.add(inttostr(memo1.lines.count)+'//fenêtre : '+Form1.name+'='+IntToStr(hwnd))
else
if hwnd=Application.handle then
memo1.lines.add(inttostr(memo1.lines.count)+'//fenêtre : Application'+'='+IntToStr(hwnd))
else
begin
if hwnd=Edit1.Handle then
infoWindow:='Edit1'
else
if hwnd=memo1.Handle then
infoWindow:='memo1'
else
if hwnd=memo2.Handle then
infoWindow:='memo2';
memo1.lines.add(inttostr(memo1.lines.count)+'//fenêtre : '
+infoWindow+' ='+IntToStr(hwnd));
end;
Label6.Caption:=Label5.Caption;
Label5.Caption:=IntToStr(hwnd);
case message of
WM_LBUTTONDOWN: memo2.lines.add('souris LEFT: '+IntToStr(message));
WM_RBUTTONDOWN: memo2.lines.add('souris RIGHT: '+IntToStr(message));
WM_KEYDOWN:memo2.lines.add('clavier KEYDOWN: '+IntToStr(message));
end;
LabelWparam.Caption:= 'wParam='+IntToStr(wParam);
LabelLparam.Caption:= 'lParam='+IntToStr(lParam);
LabelTime.Caption:= 'Time='+IntToStr(Time);
Edit1.text := 'x='+IntToStr(pt.x)+' y='+IntToStr(pt.y)+'//Handle='+IntToStr(Edit1.Handle);
Labelmemo1.Caption:='//Handle memo1='+IntToStr(memo1.Handle);
Labelmemo2.Caption:='//Handle memo2='+IntToStr(memo2.Handle);
Label1.caption:=inttostr(memo1.lines.count);
//n'a pas de Handle car TGraphicControl
Label2.caption:=inttostr(memo2.lines.count);
//n'a pas de Handle car TGraphicControl
end
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
memo1.Clear
end;
end.