The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE. 
怎样找一个程序是否在运行
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&brvbar; 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");
}