unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, TLHelp32;type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
function FindProcess(PName: string): DWord;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.FindProcess(PName: string): DWord;
var
lppe:TProcessEntry32;
h:THandle;
found:boolean;
begin
result:=0;
h:=CreateToolHelp32Snapshot(TH32CS_SNAPALL,0);
found:=Process32First(h,lppe);
while found do
begin
if AnsiCompareText(ExtractFileName(lppe.szExeFile),ExtractFileName(PName))=0 then
begin
result:=lppe.th32ProcessID;
break;
end;
found:=Process32Next(h,lppe);
end;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
i:integer;
begin
for i:=0 to 10 do
if FindProcess('notepad.exe')<>0 then
Caption:='Found';
end;end.这个程序会不断吃掉内存,请问各位大虾怎么改?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, TLHelp32;type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
function FindProcess(PName: string): DWord;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.FindProcess(PName: string): DWord;
var
lppe:TProcessEntry32;
h:THandle;
found:boolean;
begin
result:=0;
h:=CreateToolHelp32Snapshot(TH32CS_SNAPALL,0);
found:=Process32First(h,lppe);
while found do
begin
if AnsiCompareText(ExtractFileName(lppe.szExeFile),ExtractFileName(PName))=0 then
begin
result:=lppe.th32ProcessID;
break;
end;
found:=Process32Next(h,lppe);
end;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
i:integer;
begin
for i:=0 to 10 do
if FindProcess('notepad.exe')<>0 then
Caption:='Found';
end;end.这个程序会不断吃掉内存,请问各位大虾怎么改?
解决方案 »
- Delphi7直接运行可执行文件与用WinExec()调用运行结果不一样
- com对象中的GUID问题
- 为什么一个进程仅启动一条线程运行一周才用三秒,运行26条这样线程时,运行一周用时却会达到100多秒?这样用线程有什么优势?
- 用ShellExecute调用chm文件时,怎么样实现一打开chm文件时就到指定的html中??
- 如何控制ListView的scrollbar(等待中...)
- ADOQuery 参数传递问题?
- TADOQuery
- 怎么判断一个线程是否在运行?
- 我在www.delphi-jedi.org 怎么找不到TAPI说明的PAS 文件
- 请问我要显示一段文字(多行)。我用TStaticText。可是我刚把它的形状调好后,关闭重来那又成了一行了,怎么办?或者有没有别的方法?
- DBCTRLGRID的用法?怎么样根据字段的值设置DBCtrlGrid背景色?高手请看!!!
- 如何实现从A、B、C三组数据中随意选择一组数据,然后点一下就显示这组数据中的一个数?
end;
found:=Process32Next(h,lppe);
end;CloseHandle(h);