HanDs
管理员

[Delphi文章] 用Delphi函数监视系统程序 



unit main;
interface
uses
Windows, Messages, SysUtils, 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 := 'OICQ用户登录'; //需要监视窗口的标识,你也可以自己定义
end;
end.


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
D el ph i 函数 监视 系统 程序
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复