Comment acceder à un controle qui se trouve dans un autre controle?

Résolu
corole3 Messages postés 39 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 4 janvier 2010 - 3 janv. 2010 à 14:57
corole3 Messages postés 39 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 4 janvier 2010 - 4 janv. 2010 à 15:21
Bonjour,



je souhaite par programmation, cliquer sur des contrôles. J'arrive à accéder aux deux CheckBox sur la Form1, mais pas à ceux qui sont dans le GroupBox

Comment faire ?
Voici le code


procedure TForm1.Button1Click(Sender: TObject);
var
  Parent,Enfant: HWND;
  i: Integer;
  s: string;
begin
  Parent := FindWindow(nil,'TestCapture' );
  BringWindowToTop(Parent);
  if Parent <> 0 then
  begin
     Enfant := FindWindowEx(Parent, 0, 'TcheckBox',Pchar('CheckBox1'));
    sendmessage(Enfant,BM_CLICK,0,0); //ok
   
    Enfant := FindWindowEx(Parent, 0, 'TcheckBox',Pchar('CheckBox2'));
    sendmessage(Enfant,BM_CLICK,0,0);//ok
    
    Enfant := FindWindowEx(Parent, 0, 'TGroupBox',Pchar('GroupBox1'));
    Enfant := FindWindow(nil,'CheckBox3' );
    sendmessage(Enfant,BM_CLICK,0,0);


Merci

Corole3

4 réponses

Utilisateur anonyme
4 janv. 2010 à 14:22
Salut,

Tu ne crois pas qu'il y a un petit souci quelque part :

Enfant := FindWindowEx(Parent, 0, 'TGroupBox',Pchar('GroupBox1'));
Enfant := FindWindow(nil,'CheckBox3' );

procedure TForm1.Button1Click(Sender: TObject);
var
  Parent,Enfant,PetitEnfant: HWND;
begin
  Parent := FindWindow(nil,'Form1' );
  BringWindowToTop(Parent);
  if Parent <> 0 then
  begin
     Enfant := FindWindowEx(Parent, 0, 'TcheckBox',Pchar('CheckBox1'));
    sendmessage(Enfant,BM_CLICK,0,0); //ok

    Enfant := FindWindowEx(Parent, 0, 'TcheckBox',Pchar('CheckBox2'));
    sendmessage(Enfant,BM_CLICK,0,0);//ok

    Enfant := FindWindowEx(Parent, 0, 'TGroupBox',Pchar('GroupBox1'));

    PetitEnfant:= FindWindowEx(Enfant,0,'TcheckBox',Pchar('CheckBox3'));
    sendmessage(PetitEnfant,BM_CLICK,0,0);

    PetitEnfant:= FindWindowEx(Enfant,0,'TcheckBox',Pchar('CheckBox4'));
    sendmessage(PetitEnfant,BM_CLICK,0,0);
  End;
end;
3
corole3 Messages postés 39 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 4 janvier 2010
4 janv. 2010 à 14:55
Salut Francky23012301,

en fait, je postais la réponse quand j'ai vu la tienne.
Tu as tout à fait raison pour les erreurs puisque je réutilise deux fois Enfant, et que dans la deuxième ligne je l'efface avec 'nil'.
En y pensant, j'ai un peu honte.


//Clique sur le TCheckBox4
     Grphnd := FindWindowEx(Parent, 0, pchar('TGroupBox'),Pchar('GroupBox1'));
    Grphnd1 := FindWindowEx(Grphnd, 0, pchar('TCheckBox'),Pchar('CheckBox4'));
     sendmessage(Grphnd1,BM_CLICK,0,0);



En tous cas, merci Francky23012301
Corole3
0
Utilisateur anonyme
4 janv. 2010 à 15:15
Valide la réponse qui te convient : Ca permet aux personnes qui feront des recherches ultérieures et tomberont sur ce topic de trouver immédiatement la solution .

Merci
0
corole3 Messages postés 39 Date d'inscription vendredi 9 mai 2003 Statut Membre Dernière intervention 4 janvier 2010
4 janv. 2010 à 15:21
ok, c'est fait

Corole3
0
Rejoignez-nous