function GetWnd(input: hwnd; sub: string): HWND;
var
  hCurrentWindow: HWnd;
  WndText: string;
begin
  hCurrentWindow := GetWindow(input, GW_HWNDFIRST);
  while hCurrentWindow <> 0 do
  begin
    WndText := GetWndText(hCurrentWindow);
    if (Pos(sub, WndText) > 0) then
    begin
      Result := hCurrentWindow;
      Exit;
    end;
    hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
  end;
  Result := 0;
end;input是程序句柄,sub是要搜索控件包含的文本,可是这个找程序的句柄没有问题,找里面的控件就找不到了,是不是还有别的函数?

解决方案 »

  1.   

    我参考的文章是
    http://www.csdn.net/develop/Read_Article.asp?Id=21715
      

  2.   

    function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;
    var
      buffer: array[0..255] of char;
    begin
      Result := True;
      GetClassName(hwnd, buffer, 256);
      if StrPas(Buffer) <>'' then
        showmessage(string(StrPas(Buffer)))
      else
        result:=false;//停止枚举
      end;procedure TForm1.Button1Click(Sender: TObject);
    begin
    EnumChildWindows(handle,@EnumChildWindowsProc,0);
    end;
    //注意一些控件如label由于没有handle,所以是不会列出来的
      

  3.   

    希望chw_csdn_chw(chw)大大去看看我的这个贴子http://expert.csdn.net/Expert/topic/2423/2423007.xml?temp=.679455