home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / ENUMWIN / MAIN.PAS < prev   
Pascal/Delphi Source File  |  1998-03-31  |  1KB  |  50 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     ListBox1: TListBox;
  12.     Label1: TLabel;
  13.     BitBtn1: TBitBtn;
  14.     procedure FormCreate(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   MainForm: TMainForm;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. { Windows calls this function, passing in Handle a reference
  29.   to each alive window. Param is not used in this example. }
  30. function EnumWinProc(Handle: HWnd; Param: Longint): Boolean;
  31.   Stdcall;  { Use this, not export, in Windows 95, 98 & NT }
  32. var
  33.   Sz: array[0 .. 132] of Char; {Holds result of GetWindowText}
  34. begin
  35.   Result := True;  { Always successful }
  36.   { Call Windows to obtain each window's caption, and then
  37.     add the returned string to the form's ListBox. }
  38.   if GetWindowText(Handle, Sz, Sizeof(Sz)) <> 0 then
  39.     MainForm.ListBox1.Items.Add(StrPas(Sz));
  40. end;
  41.  
  42. { Enumerate all alive windows by passing to Windows the
  43.   address of the preceding callback function. }
  44. procedure TMainForm.FormCreate(Sender: TObject);
  45. begin
  46.   EnumWindows(@EnumWinProc, 0);  { 0 is an unused parameter }
  47. end;
  48.  
  49. end.
  50.