请教,怎样使用CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS ,0);枚举每一个进程,并得到该进程打开的所有顶层窗口。使用EnumWindows();函数枚举窗口,利用窗口句柄得到窗口进程名称、路径及版本属性。

解决方案 »

  1.   

    http://support.microsoft.com/default.aspx/kb/175030
      

  2.   

    我使用EnumWindows();得到了窗口句柄,
    char  strCaption[127],strName[127]; if(!(::GetWindowLong(hWnd,GWL_STYLE) & WS_VISIBLE))
    return true; GetModuleFileName((HMODULE)GetWindowLong( hWnd, GWL_HINSTANCE), strName, 127))只得到了当前运行程序的进程路径
      

  3.   

    //-------------- 以下的语句将进程ID映射为进程名 ----------------// HANDLE hProcess;
    HANDLE hProcessSnap=NULL;
    hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);//0表示当前进程
    if(hProcessSnap==(HANDLE)-1)
    return; CString cspid;
    PROCESSENTRY32 pe32={0};
    pe32.dwSize=sizeof(PROCESSENTRY32);
    if(Process32First(hProcessSnap,&pe32))
    {
    do
    {
    for(int i = 0; i < iterm; i++) {
    cspid = m_ListCtrl1.GetItemText(i,4); 
    if(pe32.th32ProcessID == (unsigned long)atoi(cspid)) {
    m_ListCtrl1.SetItemText(i,5,pe32.szExeFile); //将进程名写入ListCtrl
    }
    }
    }
    while(Process32Next(hProcessSnap,&pe32));
    }
    CloseHandle(hProcessSnap);
    //------------------- 将进程ID映射为进程名 结束 -----------------//其中pe32.szExeFile是进程名,用pe32.th32ProcessID可获得进程ID
    要获得进程句柄的话,用OpenProcess就行了
      

  4.   

    这些东西在MSDN里面可以查到的,如果你没有习惯使用MSDN,那么你应该开始培养这种习惯了.
      

  5.   

    #include <windows.h>
    #include <tlhelp32.h>
    #include <stdio.h>BOOL GetProcessList () 

        HANDLE         hProcessSnap = NULL; 
        BOOL           bRet      = FALSE; 
        PROCESSENTRY32 pe32      = {0}; 
     
        //  Take a snapshot of all processes in the system.     hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);     if (hProcessSnap == INVALID_HANDLE_VALUE) 
            return (FALSE); 
     
        //  Fill in the size of the structure before using it.     pe32.dwSize = sizeof(PROCESSENTRY32); 
     
        //  Walk the snapshot of the processes, and for each process, 
        //  display information.     if (Process32First(hProcessSnap, &pe32)) 
        { 
            DWORD         dwPriorityClass; 
            BOOL          bGotModule = FALSE; 
            MODULEENTRY32 me32       = {0}; 
     
            do 
            { 
                bGotModule = GetProcessModule(pe32.th32ProcessID, 
                    pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32));             if (bGotModule) 
                { 
                    HANDLE hProcess; 
     
                    // Get the actual priority class. 
                    hProcess = OpenProcess (PROCESS_ALL_ACCESS, 
                        FALSE, pe32.th32ProcessID); 
                    dwPriorityClass = GetPriorityClass (hProcess); 
                    CloseHandle (hProcess);                 // Print the process's information. 
                    printf( "\nPriority Class Base\t%d\n", 
                        pe32.pcPriClassBase); 
                    printf( "PID\t\t\t%d\n", pe32.th32ProcessID);
                    printf( "Thread Count\t\t%d\n", pe32.cntThreads);
                    printf( "Module Name\t\t%s\n", me32.szModule);
                    printf( "Full Path\t\t%s\n\n", me32.szExePath);
                } 
            } 
            while (Process32Next(hProcessSnap, &pe32)); 
            bRet = TRUE; 
        } 
        else 
            bRet = FALSE;    // could not walk the list of processes 
     
        // Do not forget to clean up the snapshot object.     CloseHandle (hProcessSnap); 
        return (bRet); 

      

  6.   

    #include <windows.h>
    #include <tlhelp32.h>BOOL GetProcessModule (DWORD dwPID, DWORD dwModuleID, 
         LPMODULEENTRY32 lpMe32, DWORD cbMe32) 

        BOOL          bRet        = FALSE; 
        BOOL          bFound      = FALSE; 
        HANDLE        hModuleSnap = NULL; 
        MODULEENTRY32 me32        = {0}; 
     
        // Take a snapshot of all modules in the specified process.     hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID); 
        if (hModuleSnap == INVALID_HANDLE_VALUE) 
            return (FALSE); 
     
        // Fill the size of the structure before using it.     me32.dwSize = sizeof(MODULEENTRY32); 
     
        // Walk the module list of the process, and find the module of 
        // interest. Then copy the information to the buffer pointed 
        // to by lpMe32 so that it can be returned to the caller.     if (Module32First(hModuleSnap, &me32)) 
        { 
            do 
            { 
                if (me32.th32ModuleID == dwModuleID) 
                { 
                    CopyMemory (lpMe32, &me32, cbMe32); 
                    bFound = TRUE; 
                } 
            } 
            while (!bFound && Module32Next(hModuleSnap, &me32)); 
     
            bRet = bFound;   // if this sets bRet to FALSE, dwModuleID 
                             // no longer exists in specified process 
        } 
        else 
            bRet = FALSE;           // could not walk module list 
     
        // Do not forget to clean up the snapshot object.     CloseHandle (hModuleSnap); 
     
        return (bRet); 

      

  7.   

    http://support.microsoft.com/support/kb/articles/Q175/0/30.ASP