比如richedit,我只知道
h:=FindWindowEx(hwnd,0,nil,pchar('send'));
这样的语句可以找有caption的控件的句柄,有人说要用EnumChildWindows,但这个函数怎么用呢?我的delphi没有帮助文件,那位高手能写个例子给我看看

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, DBTables, ADODB, ExtCtrls;
    type
      PwindowstructInfo=^Twindowstruct;
      Twindowstruct = record
        caption:string;
        calname:string;
        wndhandle:Thandle;
      end;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }  end;var
      Form1: TForm1;
     
    implementation{$R *.dfm}function Enumwndproc( Hwindow:Hwnd;param: lparam): boolean  stdcall ;
     var
       buffer1,buffer2:Pchar;
       //FoundCaption:boolean;
      // FoundClname:boolean;
     begin
       result:=true;
       getmem(buffer1,255);
       getmem(buffer2,255);
      try
       if GetWindowText(Hwindow,buffer1,255)>0   then
        if  pos( PwindowstructInfo(param).caption,strpas(buffer1))>0   then
             result := false;  if  GetClassName(hwindow,buffer2,255)>0   then
          if pos( PwindowstructInfo(param).calname,strpas(buffer2))>0    then
              Result := False;  if Result = False then
         PwindowstructInfo(param).wndhandle:=Hwindow; //返回查找到的窗口句柄 
      finally
       freemem(buffer1);
       freemem(buffer2);
     end;
     
     end;function FindAwindow(caption, clname: string): Thandle;
     var
      wndInfo:Twindowstruct;
    begin
      wndInfo.caption:=caption;
      wndInfo.calname:=clName;
      wndInfo.wndhandle:=0;
      EnumWindows(@Enumwndproc,Lparam(@wndInfo));
      FindAwindow:=wndInfo.wndhandle;
    end;
    function Enumchildwndproc(H:Hwnd;param:Lparam) :boolean stdcall;
       var
         caption,clname:Pchar;
      begin
         result:=true;
         getmem(caption,255);
         getmem(clname,255);
        try
          GetWindowText(H,caption,255);
          GetClassName(H,clname,255);
          form1.Memo1.Lines.Add('标题: '+strpas(caption)     +  '类名:'  + strpas(clname));
        finally
          freemem(caption);
          freemem(clname);
        end;  
      end;
    procedure TForm1.Button1Click(Sender: TObject);
      var
       Thewindowhandle:Thandle;
    begin
      Thewindowhandle:=FindAwindow('From1','');
      form1.Memo1.Lines.Clear;
      showmessage(inttostr(Thewindowhandle));
     if  Thewindowhandle<>0   then
        Enumchildwindows(Thewindowhandle,@Enumchildwndproc,0);
     
    end;
    end.