请教如何列举所有窗口?就像任务管理器的“应用程序”一栏,只列举存在的窗口。如何呢?谢谢。

解决方案 »

  1.   

    这个应该可以的:
    for i:=Screen.FormCount-1 downto 0 do ...
      

  2.   

    逐一查出各视窗的标题:procedure TForm1.Button1Click(Sender: TObject);
    var
      hCurrentWindow: HWnd;
      szText: array[0..254] of char;
    begin
      hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
      while hCurrentWindow <> 0 do
      begin
        if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
        Memo1.Lines.Add(StrPas(@szText));
        hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
      end;
    end;