本帖最后由 lght 于 2009-12-11 17:36:43 编辑

解决方案 »

  1.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      h: HWnd;
      p: array[0..254] of char;
    begin
      h := GetWindow(Handle, GW_HWNDFIRST);
      while h <> 0 do
      begin
        if GetWindowText(h, p, 255) > 0 then Memo1.Lines.Add(p);
        h := GetWindow(h, GW_HWNDNEXT);
      end;
    end;楼主试试这段代码,看看和spy找到是不是一样
      

  2.   


    function EnumWinProc(Wnd : HWND; form1 : TForm1) : Boolean; Export; {$IFDEF Win32}StdCall;{$ENDIF}
    var
    WinText : Array[0..255] of Char;
    begin
    GetWindowText(Wnd, WinText, 255);
    Result := True;
    if (StrPas(WinText)<>'') then
    Form1.ListBox1.Items.Add(StrPas(WinText));
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
     EnumWindows(@EnumWinProc, LongInt(Self));
    end;你可以揭帖了
    以上两段代码都能达到你的要求
      

  3.   

    GetWindow可以找到,EnumWindows不行,FindWindow,FindWindowEx也不行?
    什么原因?
      

  4.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, HexDecBinInt;type
      TForm1 = class(TForm)
        lst1: TListBox;
        btn1: TButton;
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    //------------------------------------------------------------------------------//回调函数//------------------------------------------------------------------------------function EnumChildWindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
    var
      ssText:array[0..254] of Char;
      id:Integer;
    begin
      GetWindowText(hWnd,ssText,255);
      id:=GetDlgCtrlID(hWnd);
      if Trim(StrPas(sstext)) <> '' then
        Form1.lst1.Items.Add('  ------>' + ssText + '---->' + IntToDigit(id,16,0));
      result:=True;
    end;
    //------------------------------------------------------------------------------function EnumwindowsProc(hWnd:HWND;lparam:LPARAM):Boolean;stdcall;
    var
      sText:array[0..254] of Char;
      id:Integer;
    begin
      GetWindowText(hWnd,sText,255);
      id:=GetDlgCtrlID(hWnd);
      if Trim(StrPas(sText)) <> '' then
      begin
        Form1.lst1.Items.Add(Trim(StrPas(sText)) + '---->' + IntToStr(id));;
        EnumChildWindows(hWnd,@EnumChildWindowsProc,0);
      end;
      result:=True;
    end;
    //------------------------------------------------------------------------------
    procedure TForm1.btn1Click(Sender: TObject);
    begin
      lst1.Clear;
      EnumWindows(@EnumwindowsProc,0);
    end;
      

  5.   


    unit HexDecBinInt;interface
    uses
          Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,   
          Dialogs,   StdCtrls;
      const   
          cScaleChar   =   '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      function   IntPower(Base,   Exponent:   Integer):   Integer;
      function   DigitToInt(mDigit:   string;   mScale:   Byte):   Integer;
        function   IntToDigit(mNumber:   Integer;   mScale:   Byte;   
          mLength:   Integer   =   0):   string;
    implementation
    //------------------------------------------------------------------------------
      function   IntPower(Base,   Exponent:   Integer):   Integer;   {   返回Base的Exponent次方   }
      var
          I:   Integer;   
      begin   
          Result   :=   1;   
          for   I   :=   1   to   Exponent   do   
              Result   :=   Result   *   Base;   
      end;   {   IntPower   }
      //------------------------------------------------------------------------------  function   DigitToInt(mDigit:   string;   mScale:   Byte):   Integer;
      {   返回进制表示转换成整数;mScale指定多少进制   }
      var   
          I:   Byte;   
          L:   Integer;
      begin   
          Result   :=   0;   
          mDigit   :=   UpperCase(mDigit);
          L   :=   Length(mDigit);   
          for   I   :=   1   to   L   do   
              Result   :=   Result   +   (Pos(mDigit[L   -   I   +   1],   cScaleChar)   -   1)   *
                  IntPower(mScale,   I   -   1);
      end;   {   DigitToInt   }
    //------------------------------------------------------------------------------
      function   IntToDigit(mNumber:   Integer;   mScale:   Byte;
          mLength:   Integer   =   0):   string;
      {   返回整数的进制表示;mScale指定多少进制;mLength指定长度,长度不足时向前补0   }   
      var   
          I,   J:   Integer;   
      begin   
          Result   :=   '';   
          I   :=   mNumber;   
          while   (I   >=   mScale)   and   (mScale   >   1)   do   begin   
              J   :=   I   mod   mScale;   
              I   :=   I   div   mScale;   
              Result   :=   cScaleChar[J   +   1]   +   Result;   
          end;   
          Result   :=   cScaleChar[I   +   1]   +   Result;
          for   I   :=   1   to   mLength   -   Length(Result)   do   Result   :=   '0'   +   Result;   
      end;   {   IntToDigit   }
    end.
      

  6.   

    怎么可能,
    主窗口,次窗口,你没分清楚而已
    findwindow 只找顶层窗口,而findwindowex找子窗口.
    ----------------
    spy能找的,你都能找到
      

  7.   

    最近在用 EnumChildWindows 的时候,同样发现楼主的问题。就是它枚举不全,有遗漏。找遍整个网络,也找不到解决的办法。