| 68 | } |
| 69 | |
| 70 | QProcessList QProcessInfo::enumerate(bool includeWindowTitles) |
| 71 | { |
| 72 | QProcessList ret; |
| 73 | |
| 74 | HANDLE h = NULL; |
| 75 | PROCESSENTRY32 pe = {0}; |
| 76 | pe.dwSize = sizeof(PROCESSENTRY32); |
| 77 | h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
| 78 | if(Process32First(h, &pe)) |
| 79 | { |
| 80 | do |
| 81 | { |
| 82 | QProcessInfo info; |
| 83 | info.setPid((uint32_t)pe.th32ProcessID); |
| 84 | info.setName(QString::fromStdWString(std::wstring(pe.szExeFile))); |
| 85 | |
| 86 | ret.push_back(info); |
| 87 | } while(Process32Next(h, &pe)); |
| 88 | } |
| 89 | CloseHandle(h); |
| 90 | |
| 91 | if(!includeWindowTitles) |
| 92 | return ret; |
| 93 | |
| 94 | HMODULE user32 = LoadLibraryA("user32.dll"); |
| 95 | |
| 96 | if(user32) |
| 97 | { |
| 98 | callbackContext ctx(ret); |
| 99 | |
| 100 | ctx.GetWindowThreadProcessId = |
| 101 | (PFN_GETWINDOWTHREADPROCESSID)GetProcAddress(user32, "GetWindowThreadProcessId"); |
| 102 | ctx.GetWindow = (PFN_GETWINDOW)GetProcAddress(user32, "GetWindow"); |
| 103 | ctx.IsWindowVisible = (PFN_ISWINDOWVISIBLE)GetProcAddress(user32, "IsWindowVisible"); |
| 104 | ctx.GetWindowTextLengthW = |
| 105 | (PFN_GETWINDOWTEXTLENGTHW)GetProcAddress(user32, "GetWindowTextLengthW"); |
| 106 | ctx.GetWindowTextW = (PFN_GETWINDOWTEXTW)GetProcAddress(user32, "GetWindowTextW"); |
| 107 | ctx.EnumWindows = (PFN_ENUMWINDOWS)GetProcAddress(user32, "EnumWindows"); |
| 108 | |
| 109 | if(ctx.GetWindowThreadProcessId && ctx.GetWindow && ctx.IsWindowVisible && |
| 110 | ctx.GetWindowTextLengthW && ctx.GetWindowTextW && ctx.EnumWindows) |
| 111 | { |
| 112 | ctx.EnumWindows(fillWindowTitles, (LPARAM)&ctx); |
| 113 | } |
| 114 | |
| 115 | FreeLibrary(user32); |
| 116 | } |
| 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
| 121 | #elif defined(Q_OS_UNIX) |
| 122 |
nothing calls this directly
no test coverage detected