郑板桥道情十首歌:C++ MFC中怎样列出当前的系统进程?

来源:百度文库 编辑:神马品牌网 时间:2024/05/06 14:29:28
我自己想做一个小软件,用它可以打开指定的网页,现在又一个问题:我想在这个软件刚开始运行的时候能得到当前系统的进程列表,并且判断某个进程是否已经开始运行(主要是想看一下拨号上网的进程有没有在运行),并且再软件被关闭之前能提示关掉这个进程(从而断开网络),具体要怎么做啊?
我说的是在VC++ 的MFC里
现在进程列表我已经做出来了,并且也可以判断指定的进程是否正在运行
现在还差一步:怎样结束指定的进程?

MFC好像没有现成的吧!

还是用api吧!下面这个函数希望你对你有帮助
主要用了GetWindowThreadProcessId

BOOL CALLBACK
EnumWindowsProc(
HWND hwnd,
LPARAM lParam
)
{
DWORD pid = 0;
int i;
CHAR buf[TITLE_SIZE];

//SAMPLE: superfunky cast! don't do this yourself
// unless you know what it's for: stupid casts cause bugs.
CTaskList& refList = *((CTaskList*) lParam);

//
// get the processid for this window
//
if (!GetWindowThreadProcessId( hwnd, &pid )) {
return TRUE;
}

//
// look for the task in the task list for this window
//
for (i=0; i < refList.GetSize(); i++)
{
if (refList[i]->dwProcessId == pid)
{
refList[i]->hwnd = hwnd;
//
// we found the task so lets try to get the
// window text
//
if (GetWindowText( refList[i]->hwnd, buf, sizeof(buf) ))
{
//
// got it, so lets save it
//
strcpy( refList[i]->WindowTitle, buf);
}
break;
}
}

//
// continue the enumeration
//
return TRUE;
}

http://www.rosipay.com/1/17890.html

http://www.rosipay.com/1/17890.html

hProcess=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
report=Process32First(hProcess,pinfo);
while(report)
{
hModule=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pinfo->th32ProcessID);
Module32First(hModule, minfo);
GetShortPathName(minfo->szExePath,shortpath,256);
printf("%s --- %s\n",pinfo->szExeFile,shortpath);
report=Process32Next(hProcess, pinfo);
}

WinCE下的系统进程列出程序

主要是方便远程调试的程序。
有空下载下去,自己看看了。

http://www.rosipay.com/1/17890.html