如果知道这个程序的类名或窗口标题,可以用FindWindow()函数。
如果不知道,只好枚举进程列表,然后查找。

解决方案 »

  1.   

    我知道类名和窗口标题,请问类名是App还是Dlg OR view的类名?
      

  2.   

    一点代码,可以直接用://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.   

    to qiuanhong(练从难处练,用从易处用):
    大哥,好人那!等我试一下,给你家分!