unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1;
hWnd: Longword; //为取得窗口的句柄
WinText: pChar; //窗口的标题implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Windowstate := wsMinimized; //窗口最小化
Timer1.Enabled := True; //使时间控件可用,运行监视代码
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
hWnd := FindWindow(nil, WinText); //根据标题取得窗口的句柄
if (hWnd <> 0) then // 如果窗口的句柄不为0,则表示指定
PostMessage(hWnd,WM_CLOSE,0,0); //窗口存在,则发送WM_CLOSE关闭窗口
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := False; //使时间控件不可用
WinText := 'LineX 天堂輔助程式'; // 需要监视窗口的标识,你也可以自己定义
WinText := 'LinGM';
end;end.
我的这个就只能关闭窗体名为LinGM的程式,上面的那个就不能关闭了.我需要关闭多个.该怎么实现啊??? 刚才有位仁兄给我解了。但是他的监视作用就没了每天一次button才关闭一次。
因为那边分已给出。只好再次求解。!!
hWnd: Longword; //为取得窗口的句柄
WinText: pChar; //窗口的标题
m_lstCaption :TStrings;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Windowstate := wsMinimized; //窗口最小化
Timer1.Enabled := True; //使时间控件可用,运行监视代码
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
i :Integer;
begin
for i:= 0 to m_lstCaption.Count-1 do
begin
hWnd := FindWindow(nil, PChar(m_lstCaption[i])); //根据标题取得窗口的句柄
if (hWnd <> 0) then // 如果窗口的句柄不为0,则表示指定
PostMessage(hWnd,WM_CLOSE,0,0); //窗口存在,则发送WM_CLOSE关闭窗口
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
m_lstCaption := TStringList.create;
Timer1.Enabled := False; //使时间控件不可用
m_lstCaption.add('LineX 天堂輔助程式');
m_lstCaption.add('LinGM');
end;end.