このプログラムは、システム内のこのプロセス、対応するファイル指定、CPU共有、関連プロセス情報などを除くすべてのプロセスのIDを検索およびリストします選択したプロセス。
このプログラムが実行されている場合、システムトレイ領域にアイコンが追加されます。Ctrl+Alt+Delを押すときに表示されるタスクリストに表示されません。非アクティブまたは最小化されたときに自動的に非表示。プログラムが既に実行されている場合、実行したい場合にのみ実行されます。
このプログラムは、プログラムの繰り返しの実行方法を回避することは非常にユニークです。インターネットでいくつかの方法を試した後、プログラムが最小化された状態からアクティブ化されたとき、ウィンドウをクリックするとボタンを最小限に抑えることができないことがわかりました。したがって、著者はカスタムメッセージを送信および処理する方法を採用します。プログラムが実行されているとき、最初にシステム内のWindowsを列挙している場合は、プログラムウィンドウにカスタムメッセージを送信してから終了します。実行中のプログラムは、カスタムメッセージを受信した後にウィンドウを表示します。
//プロジェクトファイルprocviewpro.dpr
プログラムprocviewpro;
用途
form、windows、messages、main in 'procview.pas' {form1};
{$ r *.res}
{
//これはシステムによって自動です
始める
Application.Initialize;
Application.Title:= 'システムプロセス監視';
application.createform(tform1、form1);
application.run;
終わり。
}
var
myhwnd:hwnd;
始める
myhwnd:= findwindow(nil、 'System Process Monitoring');
myhwnd = 0 then //見つかりませんでした。続行してください
始める
Application.Initialize;
Application.Title:= 'システムプロセス監視';
application.createform(tform1、form1);
application.run;
終わり
else //ウィンドウを発見し、マウスクリックシステムトレイエリアメッセージを送信してウィンドウをアクティブにします
Postmessage(myhwnd、wm_systraymsg、0、wm_lbuttondown);
{
//次の方法の欠点は次のとおりです。ウィンドウが元々最小化された状態にある場合、アクティベーション後にウィンドウをクリックすると、ウィンドウが最小限に抑えられません。
showwindow(myhwnd、sw_restore);
flashwindow(myhwnd、true);
}
終わり。
{
//以下は、プログラムの繰り返しの実行を避けるためにグローバルな原子を使用する方法です
const
atomstr = 'procview';
var
原子:整数;
始める
GlobalFindatom(Atomstr)= 0の場合
始める
ATOM:= GlobalAddatom(Atomstr);
アプリケーションで
始める
初期化;
タイトル:= 'システムプロセス監視';
createform(tform1、form1);
走る;
終わり;
GlobalDeleTeatom(Atom);
終わり;
終わり。
}
//ユニットファイルprocview.pas
ユニットprocview;
インタフェース
用途
Windows、メッセージ、sysutils、クラス、グラフィック、コントロール、フォーム、ダイアログ、
stdctrls、tlhelp32、ボタン、comctrls、extctrls、shellapi、myflag;
const
process_terminate = 0;
systray_id = 1;
wm_systraymsg = wm_user+100;
タイプ
tform1 = class(tform)
lvsysproc:tlistview;
lblsysproc:tlabel;
lblaboutproc:tlabel;
lvaboutproc:tlistview;
lblcountsysproc:tlabel;
lblcountaboutproc:tlabel;
パネル:Tpanel;
btndetermine:tbutton;
btnrefresh:tbutton;
lblothers:tlabel;
LBMAIL:TLABEL;
myflag1:tmyflag;
手順btnrefreshclick(sender:t object );
手順btndetermineclick(sender:t object );
手順lvsysprocclick(sender:t object );
手順formcreate(sender:t object );
手順ApponMinimize(送信者:Tオブジェクト);
手順formclose(sender:t object ; var action:tcloseaction);
手順formdeactivate(sender:t object );
手順lblemailclick(sender:t object );
手順formsize(sender:t object );
プライベート
{プライベート宣言}
fshandle:thandle;
FormoldHeight、FormoldWidth:整数;
手順systray onclick (var message:tmessage);メッセージwm_systraymsg;
公共
{公開宣言}
終わり;
var
form1:tform1;
idid:dword;
FP32:TPROCESSENTRY32;
FM32:TModuleEntry32;
Systrayicon:tnotifyicondata;
実装
{$ r *.dfm}
関数RegisterServiceProcess(dwprocessid、dwtype:integer):integer; stdcall; external 'kernel32.dll';
手順tform1.btnrefreshclick(sender:t object );
var
CLP:bool;
newItem1:tlistitem;
Myicon:Ticon;
iconindex:word;
procfile:charの配列[0..max_path];
始める
myicon:= ticon.create;
lvsysproc.items.clear;
lvsysproc.smallimages.clear;
fshandle:= createToolHelp32SNAPSHOT(TH32CS_SNAPPROCESS、0);
fp32.dwsize:= sizeof(fp32);
clp:= process32first(fshandle、fp32);
iconindex:= 0;
integer(clp)<> 0はします
始める
fp32.th32processid <> getCurrentProcessidの場合
始める
newItem1:= lvsysproc.items.add;
{
newitem1.caption:= fp32.szexefile;
myicon.handle:= extracticon(form1.handle、fp32.szexefile、0);
}
strcopy(procfile、fp32.szexefile);
newitem1.caption:= procfile;
myicon.handle:= extractasocidecon(Hinstance、procfile、iconindex);
myicon.handle <> 0の場合
始める
lvsysprocを使用して
始める
newitem1.imageIndex:= smallimages.addicon(myicon);
終わり;
終わり;
newitem1.subitemsを使用します
始める
add(inttohex(fp32.th32processid、4));
add(inttohex(fp32.th32parentprocessid、4));
add(inttohex(fp32.pcpriclassbase、4));
add(inttohex(fp32.cntusage、4));
add(inttostr(fp32.cntthreads));
終わり;
終わり;
clp:= process32next(fshandle、fp32);
終わり;
CloseHandle(fshandle);
lblcountsysproc.caption:= inttostr(lvsysproc.items.count);
myicon.free;
終わり;
手順tform1.btndetermineclick(sender:t object );
var
processhndle:thandle;
始める
lvsysprocを使用して
始める
選択した場合= nil then
始める
messagebox(form1.handle、 '最初に終了するプロセスを選択してください!'、 '操作プロンプト'、MB_OK+MB_ICONINFORMATION);
終わり
それ以外
始める
messagebox(form1.handle、pchar( 'extering'+itemfocused.caption+'?')の場合
、「プロセスを終了」、MB_YESNO+MB_ICONWARNING+MB_DEFBUTTON2)= MRYES
始める
idid:= strtoint( '$'+itemfocused.subitems [0]);
Processhndle:= openProcess(process_terminate、bool(0)、idid);
integer(terminateprocess(processshndle、0))= 0の場合
messagebox(form1.handle、pchar( '+eminating'+itemfocused.caption+'!')
、「操作失敗」、MB_OK+MB_IC ONERROR )
それ以外
始める
selected.delete;
lvaboutproc.items.clear;
lblcountsysproc.caption:= inttostr(lvsysproc.items.count);
lblcountaboutproc.caption:= '';
終わり
終わり;
終わり;
終わり;
終わり;
手順tform1.lvsysprocclick(sender:t object );
var
newItem2:tlistitem;
CLP:bool;
始める
lvsysproc.selected <> nil thenの場合
始める
idid:= strtoint( '$'+lvsysproc.itemfocused.subitems [0]);
lvaboutproc.items.clear;
fshandle:= createToolHelp32SNAPSHOT(TH32CS_SNAPMODULE、IDID);
fm32.dwsize:= sizeof(fm32);
clp:= module32first(fshandle、fm32);
integer(clp)<> 0はします
始める
newItem2:= lvaboutproc.items.add;
newItem2を使用します
始める
キャプション:= fm32.szexepath;
newItem2.subitemsを使用します
始める
add(inttohex(fm32.th32moduleid、4));
add(inttohex(fm32.glblcntusage、4));
add(inttohex(fm32.proccntusage、4));
終わり;
終わり;
clp:= module32next(fshandle、fm32);
終わり;
CloseHandle(fshandle);
lblcountaboutproc.caption:= inttostr(lvaboutproc.items.count);
終わり
終わり;
手順tform1.formcreate(sender:t object );
始める
アプリケーションで
始める
showwindow(handle、sw_hide);
onminimize:= apponminimize; //最小化されると自動的に非表示になります
Ondeactivate:= formdeactivate;
onactivate:= btnrefreshclick;
終わり;
RegisterServiceProcess(getCurrentProcessid、1);
Systrayiconを使用します
始める
cbsize:= sizeof(systrayicon);
wnd:= handle;
uid:= systray_id;
uflags:= nif_iconまたはnif_messageまたはnif_tip;
ucallbackmessage:= wm_systraymsg;
Hicon:= application.icon.handle;
SZTIP:= 'システムプロセス監視';
終わり;
shell_notifyicon(nim_add、@systrayicon);
lvsysprocを使用して
始める
SmallImages:= TimageList.Createsize(16,16);
smallimages.shareimages:= true;
終わり;
formoldwidth:= self.width;
formoldheight:= self.height;
終わり;
//最小化されると自動的に非表示になります
手順tform1.apponminimize(sender:t object );
始める
showwindow(application.handle、sw_hide);
終わり;
//マウスを応答して、システムトレイエリアアイコンをクリックします
手順tform1.systray onclick (var message:tmessage);
始める
メッセージで
始める
if(lparam = wm_lbuttondown)または(lparam = wm_rbuttondown)then
始める
Application.Restore;
SetForeGroundWindow(ハンドル);
showwindow(application.handle、sw_hide);
終わり;
終わり;
終わり;
手順tform1.formclose(sender:t object ; var action:tcloseaction);
始める
shell_notifyicon(nim_delete、@systrayicon);
RegisterServiceProcess(getCurrentProcessID、0);
lvsysproc.smallimages.free;
終わり;
//非アクティブなときに自動的に非表示になります
手順tform1.formdeactivate(sender:t object );
始める
application.minimize;
終わり;
手順tform1.lblemailclick(sender:t object );
始める
shellexecute(handle、 'open'、pchar( 'mailto:[email protected]')、nil、nil、sw_show)<33 thenの場合
messagebox(form1.handle、 '電子メールソフトウェアを起動できません!'、「ごめんなさい」、mb_iconinformation+mb_ok);
終わり;
//フォームサイズが変更されたら、各コンポーネントの位置を調整します
手順tform1.formresize(sender:t object );
始める
panel1を使用して、apt:= top+self.height-formoldheight;
lvsysprocを使用して
始める
width:= width+self.width-formoldwidth;
終わり;
lvaboutprocを使用して
始める
高さ:= height+self.height-formoldheight;
width:= width+self.width-formoldwidth;
終わり;
formoldwidth:= self.width;
formoldheight:= self.height;
終わり;
終わり。
上記のプログラムは、Delphi 2、Windows 95中国語版、Delphi 5、およびWindows 97の中国語版でコンパイルおよび実行できます。ご質問がある場合は、[email protected]にメールしてください。
postScript:
上記のコードでは、RegisterServiceProcess()は、Win 9xにのみ存在する未発表のAPI関数です。
MASM32を学んだ後、私はMASM32でこのプログラムを書き直して改善しました
興味のある友達は最新バージョンをダウンロードできます:
http://www.hcny.gov.cn/netres/download/procview.rar