// Button1À» Ŭ¸¯Çϸé ÇöÀç ½ÇÇàÁßÀÎ ApplicationÀÇ ¸®½ºÆ®¸¦ ListBox1¿¡ ±¸ÇÑ´Ù
// LibtBox1¿¡¼ ƯÁ¤ ÇÁ·Î±×·¥À» Ŭ¸¯Çϸé Label1¿¡ ±× ÇÁ·Î±×·¥ÀÇ Á¤º¸¸¦ º¸¿©ÁØ´Ù
// Button2¸¦ Ŭ¸¯Çϸé ÀÌ ÇÁ·Î±×·¥À» Á¦¿ÜÇÑ ³ª¸ÓÁö ÇÁ·Î±×·¥µéÀ» Minimized ½ÃŲ´Ù
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
ListBox1: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function EnumWindowsProc(Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
caption: Array [0..128] of Char;
begin
Result := True;
if {skip invisible windows}
IsWindowVisible(Wnd) and
{only process truly top-level windows. GetWindowLong must be used, not GetParent}
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
{skip WS_EX_TOOLWINDOW windows}
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
lb.Items.AddObject(caption, TObject(Wnd));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Clear;
EnumWindows(@EnumWindowsProc, Integer(ListBox1));
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var
theClassname: array [0..128] of Char;
Wnd: HWND;
tid, pid: DWORD;
begin
with Sender as TListbox do
begin
if ItemIndex >= 0 then
begin
Wnd := HWND(Items.Objects[itemindex]);
if Wnd <> 0 then
begin
Windows.GetClassname(Wnd, theClassname, Sizeof(classname));
tid := GetWindowThreadProcessID(Wnd, @pid );
label1.caption :=
Format(
'HWND: %8.8x'#13#10+
'Class: %s'#13#10+
'Process ID: %8.8x'#13#10+
'Thread ID: %8.8x',
[Wnd, theClassname, pid, tid] );
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
Wnd: HWND;
begin
for i := 0 to ListBox1.Items.Count-1 do
begin
Wnd := HWND(ListBox1.Items.Objects[i]);
// ÀÌ ÇÁ·Î±×·¥ÀÌ ¾Æ´Ï°í minimized(iconic)°¡ ¾Æ´Ï¸é...
if (Wnd <> 0) and (Wnd <> Application.Handle) then
if not IsIconic(Wnd) then
begin
ShowWindow(Wnd, SW_HIDE);
ShowWindow(Wnd, SW_MINIMIZE);
end;
end;
end;
end. |
|