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
| procedure TForm1.Button1Click(Sender: TObject);
var
CurrWindow: THandle;
Buffer: array[0..1024] of char;
CestMoi: Boolean;
DemanderDeSeChercher: Boolean;
begin
//recherche l'instance de la classe dans la liste des fenetre windows
//Si DemanderDeSeChercher est true, on envoie un message aux autres pour qu'ils se recherchent
Memo1.Lines.Clear;
CurrWindow := FindWindowEx(0, 0, PChar('#32770'), nil); //premiere fenetre
while CurrWindow <> 0 do
begin
//lecture du caption de la fenetre
GetWindowText(CurrWindow, Buffer, 1024);
//verification que le titre contient mon handle
CestMoi := Pos('Chat', string(Buffer)) <> 0;
Memo1.Lines.Add(Format('[%s] %d "%s"', [Ifthen(CestMoi, ' MOI ', 'PAS MOI'), CurrWindow, Buffer]));
//envoie de la demande de se rechercher si ce n'est pas moi
if (DemanderDeSeChercher) and (not CestMoi) then
PostMessage(CurrWindow, WM_CHERCHETOI, 0, 0);
//fenetre suivante
CurrWindow := FindWindowEx(0, CurrWindow, PChar('#32770'), nil);
Label1.caption:= IntToHex(CurrWindow, 8);
end;
end; |
Partager