怎么知道另一程序是否正在执行?
如果在执行把他调到前台

解决方案 »

  1.   

    if(pWndPrev=CWnd::FindWindow(_T("#32770"),"OnlyOneInst"))
    {
    pWndChild=pWndPrev->GetLastActivePopup();
    if(pWndPrev->IsIconic())
    pWndPrev->ShowWindow(SW_RESTORE);
    pWndChild->SetForegroundWindow();
    return FALSE;
    }
    else return TRUE;);
      

  2.   

    http://www.codeguru.com/system/PList.html
    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&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");
    }
      

  3.   


    #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);
    }