Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get a list of all windows on the Desktop and their handles Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
11-Oct-02
Category
System
Language
Delphi 2.x
Views
74
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

How to get a list of all windows on the Desktop and their handles

Answer:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   StdCtrls;
8   
9   type
10    TForm1 = class(TForm)
11      Button1: TButton;
12      Memo1: TMemo;
13      procedure Button1Click(Sender: TObject);
14      procedure GetWins;
15    private
16      { Private declarations }
17    public
18      { Public declarations }
19    end;
20  
21  var
22    Form1: TForm1;
23    WindowList: TList;
24  
25  implementation
26  
27  {$R *.DFM}
28  
29  function GetWindows(Handle: HWND; Info: Pointer): BOOL; stdcall;
30  begin
31    Result := True;
32    WindowList.Add(Pointer(Handle));
33  end;
34  
35  procedure TForm1.GetWins;
36  var
37    TopWindow, CurrentWindow: HWND;
38    Dest: array[0..80] of char;
39    ClassName: array[0..80] of char;
40    i: Integer;
41  begin
42    try
43      WindowList := TList.Create;
44      TopWindow := Handle;
45      EnumWindows(@GetWindows, Longint(@TopWindow));
46      CurrentWindow := TopWindow;
47      for i := 0 to WindowList.Count - 1 do
48      begin
49        CurrentWindow := GetNextWindow(CurrentWindow, GW_HWNDNEXT);
50        GetWindowText(CurrentWindow, Dest, sizeof(Dest) - 1);
51        GetClassName(CurrentWindow, ClassName, sizeof(ClassName) - 1);
52        if StrLen(Dest) > 0 then
53          Memo1.Lines.Add(Dest + ' = ' + ClassName + ' - ' + IntToStr(CurrentWindow));
54      end;
55    finally
56      WindowList.Free;
57    end;
58  end;
59  
60  procedure TForm1.Button1Click(Sender: TObject);
61  begin
62    GetWins;
63  end;
64  
65  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC