1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
unit Unit1;
{Appli d'exemples permattant de :
- CONNAITRE LE HANDLE DE LA FENETRE/COMPOSANT
* sous le curseur de la souris
* de la fenetre au premier plan
- CONNAITRE LES COORDONNES/ECRAN SOURIS
- CONNAITRE LES COORDONNES/FENETRE SOURIS
- CONNAITRE LA POSITION DE LA FENETRE AU PREMIER PLAN
- REPOSITIONNER LA SOURIS
- SIMULER UN CLIC SOURIS
- RECUPERER LE TEXTE CONTENU PAR UN COMPOSANT
- TESTER L'ETAT D'UNE TOUCHE
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons,Clipbrd,shellapi;
type
TForm1 = class(TForm)
Timer1: TTimer;//mettre delai de 20
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
RadioGroup1: TRadioGroup;
StaticText7: TStaticText;
procedure Timer1Timer(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
procedure Touchepressee;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
var Hwnd : THandle;
Posi : TPoint;
RectWin:Trect;
Classe, titre,txt : String;
c:Pchar;
L:cardinal;
begin
If not GetCursorPos(Posi) Then begin
Exit;
end;
// recherche du handle + infos de la fenetre survolée
Hwnd:=WindowFromPoint(Posi);
//ou de la fenetre au premier plan
if RadioGroup1.ItemIndex=1 then Hwnd:=GetForegroundWindow ;
SetLength(titre, 100);
GetWindowText(Hwnd, PChar(titre), 100);
SetLength(Classe, 100);
GetClassName(Hwnd, PChar(Classe), 100);
// Récupération du texte contenu dans la fenêtre survolée
L := SendMessage(Hwnd,WM_GETTEXTLENGTH,0,0);//la longueur du texte
If L<>0 Then begin
GetMem(C,L+1); //on alloue la mémoire. // L+1 parce que les chaînes sont à zéro terminal, il faut prévoir la place du #0
Try
SendMessage(Hwnd,WM_GETTEXT,L+1,Integer(C));//on recupère le texte
txt:=c;
Finally
FreeMem(c);
End;
End
Else txt:='';
// trouve les ccordonnees de la fenetre
GetWindowRect(Hwnd,RectWin);
//Teste l'etat d'une touche --> ici c'est F5
If (GetAsyncKeyState(vk_F5)And $8000)<>0 then begin
//...
end.
//Ecritures des resultats
StaticText1.Caption:='Handle : ' + IntToStr(Hwnd);
StaticText2.Caption:='Titre : ' + titre;
StaticText3.Caption:='Classe : ' + Classe;
StaticText4.Caption:='Mouse.X screen:'+ inttostr (posi.x)+ ' Mouse.Y screen:'+ inttostr (posi.y);
StaticText5.Caption:='WindowPos.X :'+ inttostr (RectWin.Left) + ' WindowPos.Y :' + inttostr(RectWin.Left);
StaticText7.Caption:='Mouse.X Window :'+ inttostr ((posi.x)-RectWin.Left) + ' Mouse.Y Window :' + inttostr((posi.y)-RectWin.Top);
StaticText6.Caption:='Texte : '+txt;
end;
end. |
Partager