如题。

解决方案 »

  1.   

    BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
    {
        DWORD dwID;    GetWindowThreadProcessId(hwnd, &dwID);
        if (dwID == (DWORD)lParam) {
            PostMessage(hwnd, WM_QUIT, 0, 0);
            return FALSE;
        }
        return TRUE;
    }
      

  2.   

    HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0 );
    PROCESSENTRY32 procentry=sizeof(PROCESSENTRY32);
    BOOL bFlag=Process32First( hSnapShot, &procentry ) ;
    while( bFlag )
    {
          if(stricmp(procentry.szExeFile,"你的程序名")==0)
              processid=procentry.th32ProcessID;    //找到
          bFlag=Process32Next(hSnapShot,&procentry);
    }注意一个程序可能有几个实例同时运行,所以可能同时找到几个ID。
      

  3.   

    BOOL ShowProcess()//显示进程
    {
        int i=0;
    TCHAR* szFilePatch  = malloc(MAX_PATH ); //存放进程路径
    HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
        PROCESSENTRY32* information = malloc(sizeof(PROCESSENTRY32));
    if(Process32First(handle,information))
    {
    ListView_DeleteAllItems(hListView); //清空列表
    //显示系统第一个进程的id号,线程数,优先级
    _ltoa(information->th32ProcessID,Buffer,10);
    AddItem(hListView, i,0, Buffer); 
    AddItem(hListView,i,1,information->szExeFile);
    _ltoa(information->cntThreads, Buffer, 10);
    AddItem(hListView,i,2,Buffer);
    _ltoa(information->pcPriClassBase,Buffer,10);
    AddItem(hListView, i, 3, Buffer);
    i++;
    //显示其他进程信息
    while(Process32Next(handle,information)!=FALSE)
    {
    _ltoa(information->th32ProcessID,Buffer,10); 
      AddItem(hListView, i,0,Buffer );//添加进程(ID号)
    AddItem(hListView,i,1,information->szExeFile);//添加该进程映像名
    _ltoa(information->cntThreads, Buffer, 10);
        AddItem(hListView,i,2,Buffer);//添加该进程的线程数
    _ltoa(information->pcPriClassBase,Buffer,10);
    AddItem(hListView, i, 3, Buffer); //添加进程优先级
    if(strcmp(information->szExeFile, "System"))//进程"System"没有路径
    {
         GetProPatch(information->th32ProcessID,szFilePatch);
         AddItem(hListView, i, 4, szFilePatch); //添加进程路径
    }
    i++;
    }
    }
    free(szFilePatch);
    free(information);
    CloseHandle(handle);
        return TRUE;
    }//添加项目,iItem为纵向列数,iSubItem为横向列数,lpstr为显示内容
    BOOL  AddItem(HWND hWndListView, int iItem, int iSubItem, LPSTR lpstr)
    {
    if( 0 == iSubItem)
    {
    LV_ITEM lvi;
        lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
        lvi.stateMask = 0;
        lvi.state = 0;
            lvi.iItem =  iItem;
    lvi.iSubItem = iSubItem;
    lvi.pszText = lpstr; // sends an LVN_GETDISPINFO
    if( ListView_InsertItem(hWndListView,(LPARAM)&lvi) == -1)
            return FALSE;
    }
    else if( 0 < iSubItem)
                   ListView_SetItemText(hWndListView, iItem, iSubItem ,lpstr);
        return TRUE;

    }
      

  4.   

    类似这个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");
    }