比如我的程序中正在打开的金山词霸,QQ,所有父窗口,子窗口的句柄,就象类似spy++程序

解决方案 »

  1.   

    // Syntax: EnumWindows(lpEnumFunc: TFNWndEnumProc;  {the address of the enumeration callback function} 
                lParam: LPARAM  {a 32-bit application-defined value} 
                ): BOOL;  {returns TRUE or FALSE} { 
      The EnumWindows function enumerates all top-level windows 
      on the screen by passing the handle of each window, in 
      turn, to an application-defined callback function. 
      EnumWindows continues until the last top-level window is enumerated 
      or the callback function returns FALSE.   Die EnumWindows Funktion zählt alle Top-Level Fenster 
      auf und gibt jeweils das Handle zurück. 
      EnumWindows endet, wenn das letzte Fenster aufgezählt wurde 
      oder die Callback-Funktion False zurückgibt.   Callback Syntax: } EnumWindowsProc(hWnd: HWND;  {a handle to a top-level window} 
                    lParam: LPARAM  {the application-defined data} 
                    ): BOOL;  {returns TRUE or FALSE} 

      Example how to list all Top-Level Windows in a Listbox.   Nachfolgend ein Beispiel, um alle Top-Level Fenster in 
      einer Listbox anzuzeigen. 
    } function EnumWindowsProc(wHandle: HWND; lb: TListBox): Bool; stdcall; export; 
    var 
      Title, ClassName: array[0..255] of char; 
    begin 
      Result := True; 
      GetWindowText(wHandle, Title, 255); 
      GetClassName(wHandle, ClassName, 255); 
      if IsWindowVisible(wHandle) then 
         lb.Items.Add(string(Title) + '-' + string(ClassName)); 
    end; procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      EnumWindows(@EnumWindowsProc, Integer(Listbox1)); 
    end; 
      

  2.   

    呵呵,楼上真快:
    function EnumWindowsProc(hwnd: HWND; lParam: LPARAM): Boolean; stdcall;
    var
      cName: array[0..180] of Char;
      wName: array[0..32] of Char;
      tHandle: LongWord;
    begin
      GetClassName(hwnd, cName, 32);    //cName为窗体类名
      GetWindowText(hwnd, wName, 180);  //cName为窗体标题
      tHandle := GetWindowLong(hwnd, GWL_STYLE); {判断窗体是否可见,以排除不可见窗体}
      if (WS_VISIBLE and tHandle) > 1 then
        Form1.Memo1.Lines.Append(IntToStr(hwnd) + '-' + StrPas(wName)+ '-' + StrPas(cName));
    end;procedure TForm1.btnStartClick(Sender: TObject);
    begin
      EnumWindows(@EnumWindowsProc, 0);
    end;
      

  3.   

    请稍作修改:
    ...
    begin
      result := true;  //此处加上此句,如楼上 :P
      GetClassName(hwnd, cName, 32);    //cName为窗体类名
    ...
      

  4.   

    1hwnd 是application 的句柄吗?, 为什么要用这个applicaiont类的句柄,它和金山等的主窗口是同一级的窗口,对吗?
    2,为什么要用到窗体类,窗体类的作用是什么