unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> ListBox1: TListBox;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> i:integer;<br> hCurrentWindow: HWnd;<br> szText: array[0..254] of char;<br> begin<br> ListBox1.Items.Clear;<br> hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br> i:=hCurrentWindow;<br> While hCurrentWindow <> 0 Do<br> Begin<br> If GetWindowText(hCurrentWindow, @szText, 255) > 0 Then begin<br> ListBox1.Items.add(Strpas(@szText));<br>// if Strpas(@szText)='Myform' then<br>// postmessage(hCurrentWindow,WM_SYSCOMMAND,SC_CLOSE,0);<br> end;<br> hCurrentWindow := GetNextWindow(hCurrentWindow, GW_HWNDNEXT);<br> End;<br> end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> i:integer;<br> hCurrentWindow: HWnd;<br> szText: array[0..254] of char;<br> ProTitle:string;<br> begin<br> ProTitle:=Listbox1.Items[Listbox1.ItemIndex];<br> hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);<br> i:=hCurrentWindow;<br> While hCurrentWindow <> 0 Do<br> Begin<br> If GetWindowText(hCurrentWindow, @szText, 255) > 0 Then begin<br> if Strpas(@szText)=ProTitle then begin<br> postmessage(hCurrentWindow,WM_SYSCOMMAND,SC_CLOSE,0);<br> listbox1.Items.Delete(listbox1.ItemIndex);<br> end;<br> end;<br> hCurrentWindow := GetNextWindow(hCurrentWindow, GW_HWNDNEXT);<br> End;<br> end;<br><br>end.<br>