菜鸟问题:如何判断某一程序是否正在运行?(内空)(100) 简单办法:FindWindow();复杂点儿的:查找系统中相应的进程 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //enum process to find a certain modulevoid CPtbView::IsAppRun(CString modulename){ DWORD buf[4096]; DWORD num; TCHAR filenamebuf[_MAX_PATH+1]; HMODULE hModule; DWORD cbReturned; BOOL bret=EnumProcesses(buf,4095,&num); bool bfound=false; CString msg; if(!bret) { AfxMessageBox("Error EnumProcesses"); return; } for(int i=0;i<(int)num;i++) { HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]); if(hProcess ==NULL) continue; bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned ); if(bret) { DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH); CloseHandle( hProcess ) ; if(dwret==0) { msg.Format("%d",GetLastError()); AfxMessageBox(msg); break; } else { TCHAR* pfind=_tcsstr(filenamebuf,modulename); if(pfind) { bfound=true; break; } } } } if(bfound) AfxMessageBox("Found it"); else AfxMessageBox("Not found");}void CPtbView::OnViewCheckrun(){ IsAppRun("notepad.exe");} also refer to http://www.codeguru.com/system/PList.htmlSingle interface for enumerating processes and modules under NT and Win9x/2K. - Ivo Ivanov (2001/10/04) 如何将剪贴板中的图像保存为BMP文件 散分~~~戒烟了~~~ 如何向数据库ACCESS中写入DateTime类型的数据? 一个很郁闷的问题 ! #pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ ) 是什么意思 VC6.0好还是7.0好? C++的项目 SOS!(V)C的图形图象操作…… Microsoft Visual Studio .NET 2003 有谁做过Fourier-Mellin变换的匹配算法啊?! VC的DUBUG大揭密 各位大虾救救我~~~~~~~~~~~~~~~~~~~~~~~`!!!
void CPtbView::IsAppRun(CString modulename)
{
DWORD buf[4096];
DWORD num;
TCHAR filenamebuf[_MAX_PATH+1];
HMODULE hModule;
DWORD cbReturned;
BOOL bret=EnumProcesses(buf,4095,&num);
bool bfound=false;
CString msg;
if(!bret)
{
AfxMessageBox("Error EnumProcesses");
return;
}
for(int i=0;i<(int)num;i++)
{
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]);
if(hProcess ==NULL)
continue;
bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned );
if(bret)
{
DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH);
CloseHandle( hProcess ) ;
if(dwret==0)
{
msg.Format("%d",GetLastError());
AfxMessageBox(msg);
break;
}
else
{
TCHAR* pfind=_tcsstr(filenamebuf,modulename);
if(pfind)
{
bfound=true;
break;
}
}
}
}
if(bfound)
AfxMessageBox("Found it");
else
AfxMessageBox("Not found");
}void CPtbView::OnViewCheckrun()
{
IsAppRun("notepad.exe");
}
http://www.codeguru.com/system/PList.html
Single interface for enumerating processes and modules under NT and Win9x/2K. - Ivo Ivanov (2001/10/04)