本程序運行時會在系統托盤區加入圖標
本程序避免程序反復運行的方法是比較獨特的
//工程文件procviewpro
program procviewpro;
uses
Forms
{$R *
{
//這是系統自動的
begin
Application
Application
Application
Application
end
}
var
myhwnd:hwnd;
begin
myhwnd := FindWindow(nil
if myhwnd=
begin
Application
Application
Application
Application
end
else //發現窗口
postmessage(myhwnd
{
//下面的方法的缺點是
showwindow(myhwnd
FlashWindow(MYHWND
}
end
{
//下面是使用全局原子的方法避免程序反復運行
const
atomstr=
var
atom:integer;
begin
if globalfindatom(atomstr)=
begin
atom:=globaladdatom(atomstr);
with application do
begin
Initialize;
Title :=
CreateForm(TForm
Run;
end;
globaldeleteatom(atom);
end;
end
}
//單元文件procview
unit procview;
interface
uses
Windows
StdCtrls
const
PROCESS_TERMINATE=
SYSTRAY_ID=
WM_SYSTRAYMSG=WM_USER+
type
TForm
lvSysProc: TListView;
lblSysProc: TLabel;
lblAboutProc: TLabel;
lvAboutProc: TListView;
lblCountSysProc: TLabel;
lblCountAboutProc: TLabel;
Panel
btnDetermine: TButton;
btnRefresh: TButton;
lblOthers: TLabel;
lblEmail: TLabel;
MyFlag
procedure btnRefreshClick(Sender: TObject);
procedure btnDetermineClick(Sender: TObject);
procedure lvSysProcClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure AppOnMinimize(Sender:TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDeactivate(Sender: TObject);
procedure lblEmailClick(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
fshandle:thandle;
FormOldHeight
procedure SysTrayOnClick(var message:TMessage);message WM_SYSTRAYMSG;
public
{ Public declarations }
end;
var
Form
idid: dword;
fp
fm
SysTrayIcon:TNotifyIconData;
implementation
{$R *
function RegisterServiceProcess(dwProcessID
procedure TForm
var
clp:bool;
newitem
MyIcon:TIcon;
IconIndex:word;
ProcFile : array[
begin
MyIcon:=TIcon
lvSysProc
lvSysProc
fshandle:=CreateToolhelp
fp
clp:=process
IconIndex:=
while integer(clp)<>
begin
if fp
begin
newitem
{
newitem
MyIcon
}
StrCopy(ProcFile
newitem
MyIcon
if MyIcon
begin
with lvSysProc do
begin
NewItem
end;
end;
with newitem
begin
add(IntToHex(fp
Add(IntToHex(fp
Add(IntToHex(fp
Add(IntToHex(tUsage
Add(IntToStr(tThreads));
end;
end;
clp:=process
end;
closehandle(fshandle);
lblCountSysProc
MyIcon
end;
procedure TForm
var
processhndle:thandle;
begin
with lvSysProc do
begin
if selected=nil then
begin
messagebox(form
end
else
begin
if messagebox(form
begin
idid:=strtoint(
processhndle:=openprocess(PROCESS_TERMINATE
if integer(terminateprocess(processhndle
messagebox(form
else
begin
Selected
lvAboutProc
lblCountSysProc
lblCountAboutProc
end
end;
end;
end;
end;
procedure TForm
var
newitem
clp:bool;
begin
if lvSysProc
begin
idid:=strtoint(
ems
fshandle:=CreateToolhelp
fm
clp:=Module
while integer(clp)<>
begin
newitem
with newitem
begin
caption:=fm
with newitem
begin
add(IntToHex(fm
add(IntToHex(fm
add(IntToHex(fm
end;
end;
clp:=Module
end;
closehandle(fshandle);
lblCountAboutProc
end
end;
procedure TForm
begin
with application do
begin
showwindow(handle
OnMinimize:=AppOnMinimize; //最小化時自動隱藏
OnDeactivate:=FormDeactivate; //不活動時自動隱藏
OnActivate:=btnRefreshClick;
end;
RegisterServiceProcess(GetcurrentProcessID
From:http://tw.wingwit.com/Article/program/Delphi/201311/24680.html