Scan Url de IEFrame

Résolu
cs_bilal Messages postés 87 Date d'inscription dimanche 2 février 2003 Statut Membre Dernière intervention 4 mars 2010 - 5 oct. 2007 à 00:19
cs_bilal Messages postés 87 Date d'inscription dimanche 2 février 2003 Statut Membre Dernière intervention 4 mars 2010 - 7 oct. 2007 à 16:17
voici un code qui devrait fonctionner mais je suis bloqué a 2 lignes

je l'ai traduit pour le c++ builer 6, compilation 5/5


Exemple de récupération de Handle avec FindWindow et
FindWindowEx, et récupération de texte d'un Edit d'une
application externe

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 =   class (TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
procedure Button1Click(Sender: TObject);
private
    { Déclarations privées }
public
    { Déclarations publiques }
end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{------------------------------------------------------------
ATTENTION : S'il y a plusieurs instances de l'Explorateur ou
d'Internet Explorer, ce code prendra la première fenêtre dans
l'ordre Z, si l'on veut sélectionner la bonne fenêtre, il faut
utiliser un autre code
-------------------------------------------------------------}

//Récupération de l'URL en cours dans Internet Explorer
function GetCurrentInternetExplorerURL:string;
var Explorer,ClientWork,Toolbar,ComboBox,ComboBoxChild,Edit:HWND;
  Mem:integer;
begin

//Retrouve le Handle de la fenêtre principale
Explorer: =FindWindow('IEFrame',nil);
if Explorer= 0  then 
  Result: =''
else
begin
  //Cherche le Handle de la fenêtre de travail
  ClientWork:= FindWindowEx(Explorer,0,'WorkerA',nil);
 if  ClientWork =0 then
    //Compatibilité XP / 98
    ClientWork:= FindWindowEx(Explorer,0,'WorkerW',nil);
  //Retrouve le Handle de la ToolBar
  Toolbar:=FindWindowEx(ClientWork,0,'ReBarWindow32',nil);
  //Cherche le Handle du ComboBox
  ComboBox:=FindWindowEx(Toolbar,0,'ComboBoxEx32', nil);
  ComboBoxChild:=FindWindowEx(ComboBox,0,'ComboBox',nil);
  //Atteint l'Edit et envoie un message pour avoir le texte
  Edit:=FindWindowEx(ComboBoxChild,0,'Edit',nil);
  Mem:=SendMessage(Edit,WM_GETTEXTLENGTH,0,0)+1;
  SetLength(Result,Mem);
  //Envoi du message
  SendMessage(Edit,WM_GETTEXT,Mem,Integer(@Result[1]));
 end ;
end;

procedure TForm1.Button1Click(Sender: TObject);

begin

Label1.Caption: = GetCurrentInternetExplorerURL;

end;

end.




tout est ok mais je n'obtient aucun resultat !!?

SetLength(Result,Mem);

//Envoi du message
SendMessage(Edit,WM_GETTEXT,Mem,Integer(@Result[1]));


 
j'ai traduit c'est 2 lignes mais toujours rien par :




  char *Result; 

  Result= new char[Mem+1];

  GetWindowText(Edit,Result,Mem+1);

  listView->Items->Add( Result );


  ou


   char Result[128];

   GetWindowText(Edit, Result, 256);

   SendMessage(listView->Handle , LB_ADDSTRING, 0, (long)Result);

merci d'avance
Vegeta

1 réponse

cs_bilal Messages postés 87 Date d'inscription dimanche 2 février 2003 Statut Membre Dernière intervention 4 mars 2010
7 oct. 2007 à 16:17
mon problem est resolu !

voici mon code :

Le problem que j'avais est que mon IE6 contient la toolbar msn !!

ce qui me permet d'avoir plusieurs fenettres dans 1 grace aux onglets

la methode de lire les url ne fonctionne pas si on utilise des onglets !!!

je vais quant meme essayer trouver une solution global !

pour Mozilla qu'elle est le chemin ?

Avec ma methode je peux afficher les classes enfants et ......

voici ma methode pour c++builder 6

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   Form1->listView->Items->Clear();
   EnumWindows(WNDENUMPROC (EnumWindowsProc), 0);
}

LRESULT CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
  char szClass[128];
  GetClassName( hwnd, szClass, sizeof(szClass) );

 if(!strcmp(szClass, "IEFrame"))
 {
   // Recherche des classes Enfants
     EnumChildWindows(hwnd, WNDENUMPROC(EnumChildProc),0); 

    char szTitre[128];
    GetWindowTextA(hwnd, szTitre, sizeof(szTitre));

   bool trouver = false;
  for(  int i=0; i<Form1->listView->Items->Count  && trouver==false;           i++ )
    {
      if( AnsiString(szTitre) == Form1->listView->Items->Strings[i] )
      trouver = true;
    }

    if(!trouver)   // titre des nouvelles fenetre IE
    Form1->listView->Items->Add( szTitre ); 
 }
  return true;
}

LRESULT CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
  // Type de classe enfant :
 // WorkerW/A; ReBarWindow32; ComboBoxEx32; ComboBox; Edit.

  char szClass[128];
  GetClassName( hwnd, szClass, sizeof(szClass) );

  if(!strcmp(szClass, "Edit"))
  {
    char szTitre[128];
    SendMessage(hwnd,WM_GETTEXT,sizeof(szTitre),LPARAM(szTitre));
    Form1->listView->Items->Add( szTitre );
  }

 return true;
}

Voilà

Vegeta
3
Rejoignez-nous