怎么知道另一程序是否正在执行? 怎么知道另一程序是否正在执行?如果在执行把他调到前台 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(pWndPrev=CWnd::FindWindow(_T("#32770"),"OnlyOneInst")) { pWndChild=pWndPrev->GetLastActivePopup(); if(pWndPrev->IsIconic()) pWndPrev->ShowWindow(SW_RESTORE); pWndChild->SetForegroundWindow(); return FALSE; } else return TRUE;); http://www.codeguru.com/system/PList.htmlsingle interface to enumerate processes//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");} #include "Tlhelp32.h"void CListProcessesDlg::ListProcesses(){ HANDLE hProcessSnap=NULL; PROCESSENTRY32 pe32={0}; hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(hProcessSnap==(HANDLE)-1) { AfxMessageBox("Create Tool Help32Snapshot() failed\n"); return; } pe32.dwSize=sizeof(PROCESSENTRY32); if(Process32First(hProcessSnap,&pe32)) { do{ m_ctrlLstProcesses.AddString(pe32.szExeFile); } while(Process32Next(hProcessSnap,&pe32)); } else { AfxMessageBox("Process32First() failed\n"); } CloseHandle(hProcessSnap);} 散分:现在的C++项目都这么不值钱了吗? 怎样用软件仿真玩具动作? 基于VC 的远程控制代码 初学VC遇到一问题,CAsyncSocket创建出错. 怎样用MFC来做BMP图象的生成、保存模块?多谢了先 关于视频采集的问题。。。求解...等待.?? 请问流媒体为什么不能用一般的软件下载呢?它的特点是怎么样的呢? 一个关于位图的问题 怎么样使鼠标离开工具条时工具条的按钮变灰? 欢迎大家来讨论“COM+松耦合事件”方面的问题,我会加分的。 怎么让线程的全局函数能访问两个类的成员?? 如何按照某些特定的格式打印报表?例如有斜杠等等?
{
pWndChild=pWndPrev->GetLastActivePopup();
if(pWndPrev->IsIconic())
pWndPrev->ShowWindow(SW_RESTORE);
pWndChild->SetForegroundWindow();
return FALSE;
}
else return TRUE;);
single interface to enumerate processes//enum process to find a certain module
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");
}
#include "Tlhelp32.h"
void CListProcessesDlg::ListProcesses()
{
HANDLE hProcessSnap=NULL;
PROCESSENTRY32 pe32={0}; hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==(HANDLE)-1)
{
AfxMessageBox("Create Tool Help32Snapshot() failed\n");
return;
}
pe32.dwSize=sizeof(PROCESSENTRY32);
if(Process32First(hProcessSnap,&pe32))
{
do{
m_ctrlLstProcesses.AddString(pe32.szExeFile);
}
while(Process32Next(hProcessSnap,&pe32));
}
else
{
AfxMessageBox("Process32First() failed\n");
}
CloseHandle(hProcessSnap);
}