rt
谢谢!

解决方案 »

  1.   

    DWORD dwProcessId;
    GetWindowThreadProcessId(m_hWnd, &dwProcessId);
      

  2.   

    BOOL CALLBACK EnumWindowProc(HWND hWnd,LPARAM  lParam)
    {
        DWORD    dwMaxCount = 250;
    DWORD    dwTID      = 0;
    DWORD    dwPID      = 0;
    DWORD    dwReturnCount;
    TCHAR    szWindowText[250];
    if(!IsWindowVisible(hWnd))
    {
    return TRUE;
    }    dwReturnCount = GetWindowText(hWnd,szWindowText,dwMaxCount);
    if(dwReturnCount == 0)
    {
    return TRUE;
    }
    else
    {
    dwTotal ++;
    }
    CString temp1;
        temp1.Format("%X",hWnd);
        m_appinfolist.InsertItem (0,temp1);    
    dwTID = GetWindowThreadProcessId(hWnd,&dwPID);
    CString temp2;
        temp2.Format("%d",dwPID);
    m_appinfolist.SetItemText (0,1,temp2);
    CString temp3;
        temp3.Format("%d",dwTID);
    m_appinfolist.SetItemText (0,2,temp3);
        m_appinfolist.SetItemText (0,3,szWindowText); 
    // GetProcessInfoFromId(dwPID);
    return TRUE;
    }
      

  3.   

    DWORD GetProcessId(char *targetFile )//获取进程的ID
    {
    DWORD Pid=-1;
    HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);//创建系统快照
    PROCESSENTRY32 lPrs;
    ZeroMemory(&lPrs,sizeof(lPrs));
    lPrs.dwSize=sizeof(lPrs);
    Process32First(hSnap,&lPrs);//取得系统快照里第一个进程信息
    if (strstr(targetFile,lPrs.szExeFile))//判断进程信息是否是targetFile 
    {
    Pid=lPrs.th32ProcessID;
    return Pid;
    } while(1)
    {
    ZeroMemory(&lPrs,sizeof(lPrs));
    lPrs.dwSize=(&lPrs,sizeof(lPrs));
    if (!Process32Next(hSnap,&lPrs))//继续枚举进程信息
    {
    Pid=-1;
    break;
    }
    if (strstr(targetFile,lPrs.szExeFile))
    {
    Pid=lPrs.th32ProcessID;
    break;
    }
    } return Pid;}
      

  4.   

    To get thread: std::deque<DWORD> dqThreads;
    HANDLE hThreadSnap = NULL; 
    BOOL bRet = FALSE; 
    THREAD_INFORMATION_EX tie;
    DWORD dwThisThread = ::GetCurrentThreadId(); // used for not killing ourself // Take a snapshot of all threads currently in the system. 
    DWORD dwProcessID=GetCurrentProcessId();
    hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, dwProcessID); 
    if (hThreadSnap == INVALID_HANDLE_VALUE) 
    return false; 
    // Fill in the size of the structure before using it.
    tie.te32.dwSize = sizeof(THREADENTRY32); 
    // Walk the thread snapshot to find all threads of the process. 
    // If the thread belongs to the process, add its information 
    // to the display list.
    if (Thread32First(hThreadSnap, &tie.te32)) 

    do 

    if (tie.te32.th32OwnerProcessID == dwProcessID) 

    dqThreads.push_back(tie.te32.th32ThreadID);
    ZeroMemory(&tie, sizeof(THREAD_INFORMATION_EX));
    tie.te32.dwSize = sizeof(THREADENTRY32);


    while (Thread32Next(hThreadSnap, &tie.te32)); 
    bRet = TRUE; 

    //else 
    // return false;          // could not walk the list of threads 
    CloseHandle (hThreadSnap);