• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

How to loop through all of the windows.

Hey,

I want to find the window which is named: #32770.
This is the ICQ message dialog.

Ofcourse there are more #32770 windows since it's a general name for a dialog,
so that's why I want to loop through all #32770 then get the pid from the handle and then check if the exe file is icq.exe or icqlite.exe.

I know how to get the pid from the handle, so all I need is that you could provide me a code that loops through all windows with the name #32770.

BTW, Trying to find window titles with the name Message Session, is not an option since it differs with different languages.
Thnx!
0
TonyJiz
Asked:
TonyJiz
1 Solution
 
geobulCommented:
Hi,

Drop a TListBox and a TButton on a form and use the code below. Pressing the button will fill the listbox with HWND and title of all top-level windows which class name is #32770.

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  WindowsList: TStrings;

procedure WindowInfo(hWnd: HWND; List: TStrings);
var
  ErrorCode: Integer;
  TheText: array[0..255] of char;
  TheClassName: array[0..255] of char;
begin
  ErrorCode := GetClassName(hWnd, TheClassName, 255);
  if (ErrorCode <> 0) and (TheClassName = '#32770') then begin
    // do something with the window using its handle 'hWnd'. For instance, get the window title and fill a TStrings
    GetWindowText(hWnd, TheText, 255);
    if (StrLen(TheText) = 0) then TheText := '[Window without title]';
    List.Add(IntToStr(hWnd)+'-'+TheText);
  end;
end;

function EnumerateWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
begin
  Result := TRUE;
  WindowInfo(hWnd, WindowsList);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items.Clear;
  WindowsList := ListBox1.Items;
  EnumWindows(@EnumerateWindows, 0);
end;

end.

Regards, Geo
0
 
Wim ten BrinkSelf-employed developerCommented:
At http://www.workshop-alex.org/sources/trayicon/ApplicationList.html you can find a sample application that enumerates child windows too, in case you need an example. ;-)

But Geo's code should do the trick, though.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Tackle projects and never again get stuck behind a technical roadblock.
Join Now