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}
function EnumWindowsProc(Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
ClassName: string;
caption: Array [0..128] of Char;
begin
Result := True;
SetLength(ClassName, 255);
if IsWindowVisible(Wnd) and // invisible 윈도우는 제외
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or // top-level 윈도우만
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
// 윈도우의 Title 캡션을 읽어온다
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
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}
function EnumWindowsProc(Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
ClassName: string;
caption: Array [0..128] of Char;
begin
Result := True;
SetLength(ClassName, 255);
if IsWindowVisible(Wnd) and // invisible 윈도우는 제외
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or // top-level 윈도우만
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
// 윈도우의 Title 캡션을 읽어온다
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
// 윈도우의 클래스명을 읽어온다
GetClassName(Wnd, PChar(ClassName), 255);
SetLength(ClassName, StrLen(PChar(ClassName)));
lb.Items.AddObject(caption +' - '+ClassName, TObject(Wnd));
// Microsoft Internet Explorer의 클래스명은 IEFrame
if ClassName = 'IEFrame' then
PostMessage(Wnd, WM_CLOSE, 0, 0); // Close Window
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Clear;
EnumWindows(@EnumWindowsProc, Integer(ListBox1));
end;
end.