1、有没有有关“当一个固定‘目标程序’启动之后,就能够启动另外一个‘监视它的’固定程序”的例子——40分;
2、要做到时时监控这个“目标程序”,应当怎样做?最好提供例子。——40分。
/*
Write by sfengnet
功能:监测进程中有没有记事本在运行
*/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <tlhelp32.h>
#include "stdio.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled=true;
Button1->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
HANDLE hwnd ;
const AnsiString exename="NOTEPAD.EXE";
AnsiString processname;
PROCESSENTRY32 processinfo ;
processinfo.dwSize = sizeof (processinfo) ;
hwnd = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0) ;
if (hwnd == NULL)
return ;
bool status = Process32First (hwnd, &processinfo) ;
while (status)
{
processname = (AnsiString)processinfo.szExeFile;
if(processname.UpperCase()==exename)
{
Label1->Caption="记事本被打开了!";
break;
}
else
Label1->Caption="记事本被关闭了!";
status = Process32Next (hwnd, &processinfo) ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled=false;
Button1->Enabled=true;
}
//---------------------------------------------------------------------------
http://weblogs.asp.net/kennykerr/archive/2004/05/18/134342.aspx
http://www.ccrun.com/article/go.asp?i=491&d=5s77xy