Advertisement
Old_But_Gold

Untitled

Oct 23rd, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.91 KB | None | 0 0
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #pragma comment(lib, "Comctl32.lib")
  6. #pragma comment(lib, "Psapi.lib")
  7.  
  8. #define MainName L"Task Manager"
  9. #define SCREEN_WIDTH GetSystemMetrics(SM_CXSCREEN)
  10. #define SCREEN_HEIGHT GetSystemMetrics(SM_CYSCREEN)
  11.  
  12. #define ID_SELECT_BTN 0x1010
  13. #define ID_MENU_RUN_TASK 0x2010
  14. #define ID_MENU_EXIT 0x2011
  15. #define ID_MENU_ABOUT 0x2012
  16. #define ID_MENU_RARE 0x3010
  17. #define ID_MENU_NORMAL 0x3011
  18. #define ID_MENU_OFTEN 0x3012
  19. #define ID_MENU_NONE 0x3013
  20. #define ID_MENU_UPDATE 0x4010
  21.  
  22. #define IDC_TABCONTROL 0x5010
  23. #define IDC_LISTVIEW_PROCESSES 0x6010
  24. #define IDC_PROGRESSBAR_CPU 0x7010
  25. #define IDC_PROGRESSBAR_RAM 0x8010
  26.  
  27. #define IDM_CLOSE_PROCESS 0x5011
  28. #define IDM_OPEN_LOCATION 0x5012
  29.  
  30. #define TIMER_PROCESSES 0x1
  31. #define TIMER_GRAPH 0x2
  32.  
  33. #include <Windows.h>
  34. #include <iomanip>
  35. #include <CommCtrl.h>
  36. #include <wingdi.h>
  37. #include <string>
  38. #include "resource.h"
  39. #include <TlHelp32.h> // For process enumeration
  40. #include <Psapi.h> // For process memory information
  41. #include <shellapi.h>
  42. #include <map>
  43. #include <sstream>
  44. #include <set>
  45. #include <fstream>
  46. #include <vector>
  47. #include <gdiplus.h>
  48. #include <Windows.h>
  49. #pragma comment(lib, "gdiplus.lib")
  50.  
  51.  
  52. #define ProcessListViewX 10
  53. #define ProcessListViewY 25
  54.  
  55. #define TabControlX 10
  56. #define TabControlY 10
  57.  
  58. HMENU CreateAppMenu() {
  59. HMENU hMenu = CreateMenu();
  60. HMENU hFileMenu = CreatePopupMenu();
  61. HMENU hRefreshMenu = CreatePopupMenu();
  62.  
  63. AppendMenu(hFileMenu, MF_STRING, ID_MENU_RUN_TASK, L"Запустить новую задачу");
  64. AppendMenu(hFileMenu, MF_SEPARATOR, 0, NULL);
  65. AppendMenu(hFileMenu, MF_STRING, ID_MENU_EXIT, L"Выход");
  66.  
  67. AppendMenu(hRefreshMenu, MF_STRING, ID_MENU_RARE, L"Редко (5 сек)");
  68. AppendMenu(hRefreshMenu, MF_STRING, ID_MENU_NORMAL, L"Нормально (3 сек)");
  69. AppendMenu(hRefreshMenu, MF_STRING, ID_MENU_OFTEN, L"Часто (1 сек)");
  70. AppendMenu(hRefreshMenu, MF_STRING, ID_MENU_NONE, L"Отключить");
  71.  
  72. AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hFileMenu, L"Файл");
  73. AppendMenu(hMenu, MF_STRING, ID_MENU_ABOUT, L"О разработчике");
  74. AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hRefreshMenu, L"Частота обновления");
  75. AppendMenu(hMenu, MF_STRING, ID_MENU_UPDATE, L"Обновить сейчас");
  76.  
  77. return hMenu;
  78. }
  79.  
  80. HIMAGELIST CreateTabImageList() {
  81. HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 1, 1);
  82. ImageList_SetBkColor(hImageList, CLR_NONE);
  83. HICON hIcon1 = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PROCESSICON));
  84. HICON hIcon2 = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_GRAPHICON));
  85.  
  86. ImageList_AddIcon(hImageList, hIcon1);
  87. ImageList_AddIcon(hImageList, hIcon2);
  88.  
  89. DestroyIcon(hIcon1);
  90. DestroyIcon(hIcon2);
  91. return hImageList;
  92. }
  93.  
  94. void AddTabItems(HWND hTab) {
  95. HIMAGELIST hImageList = CreateTabImageList();
  96. TabCtrl_SetImageList(hTab, hImageList);
  97.  
  98. TCITEM tie = { 0 };
  99. tie.mask = TCIF_TEXT | TCIF_IMAGE;
  100.  
  101. tie.pszText = (LPWSTR)L"Процессы";
  102. tie.iImage = 0;
  103. TabCtrl_InsertItem(hTab, 0, &tie);
  104.  
  105. tie.pszText = (LPWSTR)L"Производительность";
  106. tie.iImage = 1;
  107. TabCtrl_InsertItem(hTab, 1, &tie);
  108.  
  109. tie.pszText = (LPWSTR)L"Автозагрузка";
  110. tie.iImage = 0;
  111. TabCtrl_InsertItem(hTab, 2, &tie);
  112. }
  113.  
  114. HMENU CreateContextMenu() {
  115. HMENU hMenu = CreatePopupMenu();
  116. AppendMenu(hMenu, MF_STRING, IDM_CLOSE_PROCESS, L"Закрыть процесс");
  117. AppendMenu(hMenu, MF_STRING, IDM_OPEN_LOCATION, L"Открыть расположение файла");
  118. return hMenu;
  119. }
  120.  
  121. void HandleContextMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) {
  122. POINT pt;
  123. GetCursorPos(&pt);
  124. HMENU hMenu = CreateContextMenu();
  125. TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);
  126. DestroyMenu(hMenu);
  127. }
  128.  
  129. void CloseProcessById(DWORD processId) {
  130. HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, processId);
  131. if (hProcess) {
  132. if (TerminateProcess(hProcess, 0)) {
  133. MessageBox(NULL, L"Процесс успешно завершён.", L"Успех", MB_OK | MB_ICONINFORMATION);
  134. } else {
  135. MessageBox(NULL, L"Не удалось завершить процесс.", L"Ошибка", MB_OK | MB_ICONERROR);
  136. }
  137. CloseHandle(hProcess);
  138. } else {
  139. MessageBox(NULL, L"Не удалось открыть процесс для завершения.", L"Ошибка", MB_OK | MB_ICONERROR);
  140. }
  141. }
  142.  
  143. void OpenProcessLocation(DWORD processId) {
  144. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
  145. if (hProcess) {
  146. TCHAR fullPath[MAX_PATH] = {0};
  147. DWORD size = MAX_PATH;
  148.  
  149. if (QueryFullProcessImageName(hProcess, 0, fullPath, &size)) {
  150. std::wstring folderPath(fullPath);
  151. folderPath = folderPath.substr(0, folderPath.find_last_of(L"\\/"));
  152.  
  153. ShellExecute(NULL, L"open", folderPath.c_str(), NULL, NULL, SW_SHOWNORMAL);
  154. } else {
  155. MessageBox(NULL, L"Не удалось получить путь процесса.", L"Ошибка", MB_OK | MB_ICONERROR);
  156. }
  157.  
  158. CloseHandle(hProcess);
  159. } else {
  160. MessageBox(NULL, L"Не удалось открыть процесс для получения пути.", L"Ошибка", MB_OK | MB_ICONERROR);
  161. }
  162. }
  163.  
  164. std::wstring GetPriority(DWORD processId)
  165. {
  166. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
  167. if (hProcess)
  168. {
  169. DWORD priorityClass = GetPriorityClass(hProcess);
  170. if (priorityClass == 0) {
  171. CloseHandle(hProcess);
  172. return L"Неизвестно";
  173. }
  174.  
  175. std::wstring priorityString;
  176. switch (priorityClass) {
  177. case IDLE_PRIORITY_CLASS: priorityString = L"Низкий"; break;
  178. case BELOW_NORMAL_PRIORITY_CLASS: priorityString = L"Ниже нормального"; break;
  179. case NORMAL_PRIORITY_CLASS: priorityString = L"Нормальный"; break;
  180. case ABOVE_NORMAL_PRIORITY_CLASS: priorityString = L"Выше нормального"; break;
  181. case HIGH_PRIORITY_CLASS: priorityString = L"Высокий"; break;
  182. case REALTIME_PRIORITY_CLASS: priorityString = L"Реального времени"; break;
  183. default: priorityString = L"Неизвестно"; break;
  184. }
  185.  
  186. CloseHandle(hProcess);
  187. return priorityString;
  188. }
  189. return L"Нет доступа";
  190. }
  191.  
  192. void ChangeIcon(PROCESSENTRY32 pe32, HWND hListView, LVITEM& lvi, std::map<std::wstring, int>& iconMap)
  193. {
  194. TCHAR fullPath[MAX_PATH];
  195. DWORD processNameLength = sizeof(fullPath) / sizeof(TCHAR);
  196. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pe32.th32ProcessID);
  197. if (hProcess) {
  198. if (QueryFullProcessImageName(hProcess, 0, fullPath, &processNameLength)) {
  199. std::wstring processPath(fullPath);
  200. auto it = iconMap.find(processPath);
  201. if (it != iconMap.end())
  202. {
  203. lvi.iImage = it->second;
  204. } else
  205. {
  206. HICON hIcon = ExtractIcon(NULL, fullPath, 0);
  207. if (hIcon) {
  208. int imageIndex = ImageList_AddIcon(ListView_GetImageList(hListView, LVSIL_SMALL), hIcon);
  209. if (imageIndex != -1) {
  210. lvi.iImage = imageIndex;
  211. iconMap[processPath] = imageIndex;
  212. }
  213. DestroyIcon(hIcon);
  214. }
  215. }
  216. }
  217. CloseHandle(hProcess);
  218. }
  219. }
  220.  
  221. bool Is64BitProcess(DWORD processID) {
  222. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processID);
  223. if (hProcess) {
  224. BOOL is64Bit = FALSE;
  225. IsWow64Process(hProcess, &is64Bit);
  226. CloseHandle(hProcess);
  227. return is64Bit == FALSE;
  228. }
  229. return false;
  230. }
  231.  
  232. std::wstring GetProcessTimeCreation(DWORD processId)
  233. {
  234. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
  235. if (hProcess) {
  236. FILETIME creationTime, exitTime, kernelTime, userTime;
  237. if (GetProcessTimes(hProcess, &creationTime, &exitTime, &kernelTime, &userTime)) {
  238. SYSTEMTIME st;
  239. FileTimeToSystemTime(&creationTime, &st);
  240. st.wHour += 3; //For UTC
  241. wchar_t timeString[100];
  242. swprintf_s(timeString, 100, L"%02d/%02d/%04d %02d:%02d:%02d",
  243. st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
  244. std::wstring result(timeString);
  245. return result;
  246. }
  247. CloseHandle(hProcess);
  248. }
  249. return L"";
  250. }
  251.  
  252. std::wstring FormatFloat(int precision, double value) {
  253. std::wstringstream stream;
  254. stream.precision(precision);
  255. stream << std::fixed << value << L" MB";
  256. return stream.str();
  257. }
  258.  
  259. std::wstring GetMemoryUsage(HANDLE hProcess) {
  260. PROCESS_MEMORY_COUNTERS_EX pmc;
  261. if (GetProcessMemoryInfo(hProcess, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc))) {
  262.  
  263. double memoryUsageMB = pmc.WorkingSetSize / (1024.0 * 1024.0);
  264. return FormatFloat(3, memoryUsageMB);
  265. }
  266. return L"N/A";
  267. }
  268.  
  269. HWND CreateProcessListView(HWND hParent) {
  270. HWND hListView = CreateWindowEx(0, WC_LISTVIEW, NULL,
  271. WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL,
  272. ProcessListViewX, ProcessListViewY, SCREEN_WIDTH - 40, SCREEN_HEIGHT - 70,
  273. hParent, (HMENU)IDC_LISTVIEW_PROCESSES, (HINSTANCE)GetWindowLongPtr(hParent, GWLP_HINSTANCE), NULL);
  274.  
  275. LVCOLUMN lvColumn;
  276.  
  277. HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 1, 1);
  278. ImageList_SetBkColor(hImageList, CLR_NONE);
  279.  
  280. HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAINICON));
  281. ImageList_AddIcon(hImageList, LoadIcon(NULL, IDI_WINLOGO));
  282. ImageList_AddIcon(hImageList, hIcon);
  283.  
  284. DestroyIcon(hIcon);
  285. ListView_SetImageList(hListView, hImageList, LVSIL_SMALL);
  286. ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER);
  287.  
  288. const std::wstring columnHeaders[] = {
  289. L"Имя процесса", L"ID процесса", L"ID родительского процесса", L"Приоритет",
  290. L"Загрузка ЦП", L"Загрузка Памяти", L"Время создания", L"Путь к файлу", L"Битность"
  291. };
  292. int columnWidths[] = { 200, 145, 145, 150, 150, 185, 180, 240, 80 };
  293.  
  294. for (int i = 0; i < 9; i++) {
  295. lvColumn.mask = (i == 0)
  296. ? LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT | LVCF_IMAGE
  297. : LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_FMT;
  298.  
  299. lvColumn.fmt = LVCFMT_CENTER;
  300. lvColumn.cchTextMax = MAX_PATH;
  301. lvColumn.pszText = (LPWSTR)columnHeaders[i].c_str();
  302. lvColumn.cx = columnWidths[i];
  303. lvColumn.iImage = 1;
  304. lvColumn.iSubItem = i;
  305.  
  306. ListView_InsertColumn(hListView, i, &lvColumn);
  307. }
  308.  
  309. return hListView;
  310. }
  311.  
  312. int FindProcessInListViewByPID(HWND hListView, DWORD processID) {
  313. LVFINDINFO findInfo = { 0 };
  314. findInfo.flags = LVFI_PARAM;
  315. findInfo.lParam = processID;
  316. return ListView_FindItem(hListView, -1, &findInfo);
  317. }
  318.  
  319. void RemoveStaleProcesses(HWND hListView, const std::set<DWORD>& existingProcesses) {
  320. int itemCount = ListView_GetItemCount(hListView);
  321. for (int i = itemCount - 1; i >= 0; --i) {
  322. LVITEM lvi = { 0 };
  323. lvi.iItem = i;
  324. lvi.mask = LVIF_PARAM;
  325.  
  326. if (ListView_GetItem(hListView, &lvi)) {
  327. DWORD processID = static_cast<DWORD>(lvi.lParam);
  328.  
  329. if (existingProcesses.find(processID) == existingProcesses.end()) {
  330. ListView_DeleteItem(hListView, i);
  331. }
  332. }
  333. }
  334. }
  335.  
  336. void PopulateProcessListView(HWND hListView, std::map<std::wstring, int>& iconMap)
  337. {
  338. SCROLLINFO si = { sizeof(SCROLLINFO) };
  339. si.fMask = SIF_POS;
  340. GetScrollInfo(hListView, SB_VERT, &si);
  341. int scrollPos = si.nPos;
  342.  
  343. SendMessage(hListView, WM_SETREDRAW, FALSE, 0);
  344.  
  345. HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  346. if (hProcessSnap == INVALID_HANDLE_VALUE) {
  347. return;
  348. }
  349.  
  350. PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
  351. std::set<DWORD> existingProcesses;
  352.  
  353. if (Process32First(hProcessSnap, &pe32)) {
  354. do {
  355. std::wstring exeFile = pe32.szExeFile;
  356. DWORD processID = pe32.th32ProcessID;
  357.  
  358. int itemIndex = FindProcessInListViewByPID(hListView, processID);
  359.  
  360. LVITEM lvi = { 0 };
  361. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
  362. lvi.pszText = (LPWSTR)exeFile.c_str();
  363. //lvi.iItem = (itemIndex == -1) ? 0 : ListView_GetItemCount(hListView);
  364. lvi.iItem = (itemIndex == -1) ? ListView_GetItemCount(hListView) : itemIndex;
  365. lvi.iImage = 0;
  366. lvi.cchTextMax = MAX_PATH;
  367. lvi.lParam = processID;
  368.  
  369. ChangeIcon(pe32, hListView, lvi, iconMap);
  370.  
  371. if (itemIndex == -1) {
  372. ListView_InsertItem(hListView, &lvi);
  373. } else {
  374. ListView_SetItem(hListView, &lvi);
  375. }
  376.  
  377. ListView_SetItemText(hListView, lvi.iItem, 1, (LPWSTR)std::to_wstring(pe32.th32ProcessID).c_str());
  378. std::wstring parent = pe32.th32ParentProcessID == 0 ? L"Главный процесс" : std::to_wstring(pe32.th32ParentProcessID);
  379. ListView_SetItemText(hListView, lvi.iItem, 2, (LPWSTR)parent.c_str());
  380. ListView_SetItemText(hListView, lvi.iItem, 3, (LPWSTR)GetPriority(pe32.th32ProcessID).c_str());
  381.  
  382. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pe32.th32ProcessID);
  383. if (hProcess)
  384. {
  385. std::wstring memUsage = GetMemoryUsage(hProcess);
  386. ListView_SetItemText(hListView, lvi.iItem, 5, (LPWSTR)memUsage.c_str());
  387. CloseHandle(hProcess);
  388. }
  389.  
  390. ListView_SetItemText(hListView, lvi.iItem, 6, (LPWSTR)GetProcessTimeCreation(pe32.th32ProcessID).c_str());
  391.  
  392. TCHAR fullPath[MAX_PATH];
  393. DWORD processNameLength = sizeof(fullPath) / sizeof(TCHAR);
  394. if (QueryFullProcessImageName(OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pe32.th32ProcessID), 0, fullPath, &processNameLength)) {
  395. ListView_SetItemText(hListView, lvi.iItem, 7, (LPWSTR)fullPath);
  396. }
  397. ListView_SetItemText(hListView, lvi.iItem, 8, Is64BitProcess(pe32.th32ProcessID) ? (LPWSTR)L"64-бит" : (LPWSTR)L"32-бит");
  398.  
  399. existingProcesses.insert(processID);
  400. } while (Process32Next(hProcessSnap, &pe32));
  401. }
  402. CloseHandle(hProcessSnap);
  403.  
  404. RemoveStaleProcesses(hListView, existingProcesses);
  405.  
  406. SendMessage(hListView, WM_SETREDRAW, TRUE, 0);
  407.  
  408. si.nPos = scrollPos;
  409. SetScrollInfo(hListView, SB_VERT, &si, TRUE);
  410. }
  411.  
  412. int GetCurrentRAMUsage() {
  413. MEMORYSTATUSEX memInfo;
  414. memInfo.dwLength = sizeof(MEMORYSTATUSEX);
  415.  
  416. if (GlobalMemoryStatusEx(&memInfo)) {
  417. DWORDLONG totalRAM = memInfo.ullTotalPhys;
  418. DWORDLONG freeRAM = memInfo.ullAvailPhys;
  419.  
  420. int ramUsage = static_cast<int>((1.0 - (double)freeRAM / totalRAM) * 100);
  421. return ramUsage;
  422. }
  423.  
  424. return 0;
  425. }
  426.  
  427. typedef struct _SYSTEM_PROCESSOR_TIMES {
  428. ULONGLONG IdleTime;
  429. ULONGLONG KernelTime;
  430. ULONGLONG UserTime;
  431. ULONGLONG DpcTime;
  432. ULONGLONG InterruptTime;
  433. ULONG InterruptCount;
  434. } SYSTEM_PROCESSOR_TIMES;
  435.  
  436. typedef NTSTATUS (NTAPI *ZwQuerySystemInformationFunc)(
  437. ULONG SystemInformationClass,
  438. PVOID SystemInformation,
  439. ULONG SystemInformationLength,
  440. PULONG ReturnLength
  441. );
  442.  
  443. int GetCurrentCPUUsage(SYSTEM_INFO sysInfo, SYSTEM_PROCESSOR_TIMES* CurrentSysProcTimes,
  444. SYSTEM_PROCESSOR_TIMES* PreviousSysProcTimes,
  445. ZwQuerySystemInformationFunc ZwQuerySystemInformation)
  446. {
  447. static DWORD oldTime = GetTickCount();
  448. DWORD nowTime = GetTickCount();
  449. DWORD perTime = nowTime - oldTime;
  450. oldTime = nowTime;
  451.  
  452. ZwQuerySystemInformation(sysInfo.dwNumberOfProcessors, &CurrentSysProcTimes[0], sizeof(SYSTEM_PROCESSOR_TIMES) * sysInfo.dwNumberOfProcessors, nullptr);
  453.  
  454. ULONGLONG totalIdleTime = 0;
  455. for (int j = 0; j < sysInfo.dwNumberOfProcessors; j++) {
  456. totalIdleTime += CurrentSysProcTimes[j].IdleTime - PreviousSysProcTimes[j].IdleTime;
  457. }
  458.  
  459. ULONGLONG averageIdleTime = totalIdleTime / sysInfo.dwNumberOfProcessors;
  460.  
  461. double idleTimeMs = averageIdleTime / 10000.0;
  462.  
  463. double cpuUsage = 100.0 * (1.0 - (idleTimeMs / perTime));
  464.  
  465. if (cpuUsage < 0 || cpuUsage > 100) {
  466. cpuUsage = 0;
  467. }
  468.  
  469. memcpy(&PreviousSysProcTimes[0], &CurrentSysProcTimes[0], sizeof(SYSTEM_PROCESSOR_TIMES) * sysInfo.dwNumberOfProcessors);
  470. return cpuUsage;
  471. }
  472.  
  473. std::wstring GetSystemUptime() {
  474. ULONGLONG systemUptime = GetTickCount64();
  475. ULONGLONG seconds = (systemUptime / 1000) % 60;
  476. ULONGLONG minutes = (systemUptime / (1000 * 60)) % 60;
  477. ULONGLONG hours = (systemUptime / (1000 * 60 * 60)) % 24;
  478. ULONGLONG days = (systemUptime / (1000 * 60 * 60 * 24));
  479.  
  480. return L"Время работы: " + std::to_wstring(days) + L" дн. " +
  481. std::to_wstring(hours) + L" ч. " +
  482. std::to_wstring(minutes) + L" мин. " +
  483. std::to_wstring(seconds) + L" сек.";
  484. }
  485.  
  486. std::wstring GetMemoryInfo()
  487. {
  488. MEMORYSTATUSEX memoryStatus;
  489. memoryStatus.dwLength = sizeof(MEMORYSTATUSEX);
  490.  
  491. if (GlobalMemoryStatusEx(&memoryStatus))
  492. {
  493. ULONGLONG totalMemoryMB = memoryStatus.ullTotalPhys / (1024 * 1024);
  494. ULONGLONG freeMemoryMB = memoryStatus.ullAvailPhys / (1024 * 1024);
  495.  
  496. std::wstring result = L"Общий объем памяти: " + std::to_wstring(totalMemoryMB) + L" МБ\r\n" +
  497. L"Свободно: " + std::to_wstring(freeMemoryMB) + L" МБ";
  498. return result;
  499. }
  500. return L"Ошибка получения информации о памяти";
  501. }
  502.  
  503. void DrawGraph(HWND hPerfomance, std::vector<int>& history, const int maxHistory)
  504. {
  505. HDC hdc = GetDC(hPerfomance);
  506. RECT rect;
  507. GetClientRect(hPerfomance, &rect);
  508.  
  509. int width = rect.right - rect.left;
  510. int height = rect.bottom - rect.top;
  511.  
  512. HBRUSH backgroundBrush = CreateSolidBrush(RGB(30, 30, 30));
  513. FillRect(hdc, &rect, backgroundBrush);
  514. DeleteObject(backgroundBrush);
  515.  
  516. SetBkMode(hdc, TRANSPARENT);
  517. SetStretchBltMode(hdc, HALFTONE);
  518.  
  519. HPEN gridPen = CreatePen(PS_DOT, 1, RGB(60, 60, 60));
  520. SelectObject(hdc, gridPen);
  521. for (int i = 1; i <= 10; ++i) {
  522. int y = height - 20 - (height - 40) * i / 10;
  523. MoveToEx(hdc, 0, y, NULL);
  524. LineTo(hdc, width, y);
  525. }
  526.  
  527. if (!history.empty()) {
  528. HPEN graphPen = CreatePen(PS_SOLID, 2, RGB(0, 255, 127));
  529. SelectObject(hdc, graphPen);
  530.  
  531. int spacing = width / maxHistory;
  532. int prevX = 0;
  533. int prevY = height - 20 - (history[0] * (height - 20) / 100);
  534.  
  535. for (size_t i = 1; i < history.size(); ++i) {
  536. int x = i * spacing;
  537. int y = height - 20 - (history[i] * (height - 20) / 100);
  538.  
  539. MoveToEx(hdc, prevX, prevY, NULL);
  540. LineTo(hdc, x, y);
  541.  
  542. prevX = x;
  543. prevY = y;
  544. }
  545. DeleteObject(graphPen);
  546. }
  547.  
  548. DeleteObject(gridPen);
  549. ReleaseDC(hPerfomance, hdc);
  550. }
  551.  
  552. void PushValue(std::vector<int>& history, const int maxHistory, int newValue)
  553. {
  554. history.push_back(newValue);
  555. if (history.size() > maxHistory) {
  556. history.erase(history.begin());
  557. }
  558. }
  559.  
  560. LRESULT CALLBACK ListViewProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  561. static int selectedItemIndex;
  562. switch (uMsg)
  563. {
  564. case WM_ERASEBKGND:
  565. return 1;
  566. case WM_COMMAND:
  567. {
  568. int wmId = LOWORD(wParam);
  569. int wmEvent = HIWORD(wParam);
  570.  
  571. switch (wmId)
  572. {
  573. case IDM_CLOSE_PROCESS:
  574. {
  575. wchar_t buffer[32];
  576. ListView_GetItemText(hwnd, selectedItemIndex, 1, buffer, 32);
  577. DWORD processId = _wtoi(buffer);
  578. CloseProcessById(processId);
  579. }
  580. break;
  581.  
  582. case IDM_OPEN_LOCATION:
  583. {
  584. wchar_t buffer[32];
  585. ListView_GetItemText(hwnd, selectedItemIndex, 1, buffer, 32);
  586. DWORD processId = _wtoi(buffer);
  587. OpenProcessLocation(processId);
  588. }
  589. break;
  590. }
  591. }
  592. break;
  593.  
  594. case WM_CONTEXTMENU: {
  595. if ((HWND)wParam == hwnd)
  596. {
  597. LVHITTESTINFO hitTestInfo = { 0 };
  598. POINT pt;
  599. GetCursorPos(&pt);
  600. ScreenToClient(hwnd, &pt);
  601. hitTestInfo.pt = pt;
  602. ListView_HitTest(hwnd, &hitTestInfo);
  603. selectedItemIndex = hitTestInfo.iItem;
  604. if (selectedItemIndex != -1)
  605. {
  606. HandleContextMenu(hwnd, wParam, lParam);
  607. }
  608. }
  609. break;
  610. }
  611.  
  612.  
  613. case WM_NOTIFY:
  614. {
  615. LPNMHDR nmhdr = (LPNMHDR)lParam;
  616.  
  617. if (nmhdr->code == HDN_ITEMCHANGING) {
  618. LPNMHEADER pnmhHeader = (LPNMHEADER)lParam;
  619. if (pnmhHeader->pitem->cxy < 30) {
  620. pnmhHeader->pitem->cxy = 30;
  621. }
  622. }
  623.  
  624. if (nmhdr->code == NM_CUSTOMDRAW)
  625. {
  626. LPNMLVCUSTOMDRAW pLVCD = (LPNMLVCUSTOMDRAW)lParam;
  627.  
  628. switch (pLVCD->nmcd.dwDrawStage)
  629. {
  630. case CDDS_PREPAINT:
  631. return CDRF_NOTIFYITEMDRAW;
  632.  
  633. case CDDS_ITEMPREPAINT:
  634.  
  635. SetTextColor(pLVCD->nmcd.hdc, RGB(255, 255, 255));
  636. if (pLVCD->nmcd.uItemState & CDIS_SELECTED)
  637. {
  638. SetBkColor(pLVCD->nmcd.hdc, RGB(26, 188, 156));
  639. }
  640. else
  641. {
  642. SetBkColor(pLVCD->nmcd.hdc, RGB(43, 41, 55));
  643. }
  644. return CDRF_DODEFAULT;
  645.  
  646. case CDDS_POSTPAINT:
  647. return CDRF_DODEFAULT;
  648.  
  649. }
  650. }
  651. }
  652. break;
  653.  
  654. default:
  655. return CallWindowProc((WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA), hwnd, uMsg, wParam, lParam);
  656. }
  657. return 0;
  658. }
  659.  
  660. LRESULT CALLBACK TabControlProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  661. {
  662. switch (uMsg)
  663. {
  664. case WM_NOTIFY:
  665. {
  666. LPNMHDR pnmh = (LPNMHDR)lParam;
  667. if (pnmh->code == NM_CUSTOMDRAW)
  668. {
  669. LPNMLVCUSTOMDRAW pLVCD = (LPNMLVCUSTOMDRAW)lParam;
  670. switch (pLVCD->nmcd.dwDrawStage)
  671. {
  672. case CDDS_PREPAINT:
  673. return CDRF_NOTIFYITEMDRAW;
  674.  
  675. case CDDS_ITEMPREPAINT:
  676.  
  677. pLVCD->clrText = RGB(255, 255, 255);
  678. pLVCD->clrTextBk = RGB(57, 66, 100);
  679. return CDRF_DOERASE;
  680.  
  681. default:
  682. break;
  683. }
  684. }
  685. break;
  686. }
  687.  
  688. case WM_CTLCOLORSTATIC:
  689. {
  690. HDC hdcStatic = (HDC)wParam;
  691. HWND hStatic = (HWND)lParam;
  692.  
  693. SetBkColor(hdcStatic, RGB(43, 41, 55));
  694. SetTextColor(hdcStatic, RGB(255, 255, 255));
  695.  
  696. HBRUSH hBrush = CreateSolidBrush(RGB(43, 41, 55));
  697. return (LONG_PTR)hBrush;
  698. }
  699.  
  700. default:
  701. return CallWindowProc((WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA), hwnd, uMsg, wParam, lParam);
  702. }
  703.  
  704. return 0;
  705. }
  706.  
  707. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  708. {
  709. static HWND hTabControl, hListViewProcesses;
  710. static std::map<std::wstring, int> iconMap;
  711. static HWND hProgressBarCPU;
  712. static HWND hProgressBarRAM;
  713.  
  714. static HWND hPerfomanceCPU, hPerfomanceRAM;
  715.  
  716. static UINT_PTR timerId = 0;
  717. static int updateInterval = 1000;
  718.  
  719. static HMODULE lib = nullptr;
  720. static SYSTEM_PROCESSOR_TIMES* CurrentSysProcTimes;
  721. static SYSTEM_PROCESSOR_TIMES* PreviousSysProcTimes;
  722. static ZwQuerySystemInformationFunc ZwQuerySystemInformation = nullptr;
  723.  
  724. static HWND hLabelCPU, hLabelRAM, hLabelUptime, hLabelMemoryInfo;
  725. static SYSTEM_INFO sysInfo;
  726.  
  727. static std::vector<int> cpuUsageHistory;
  728. static const int cpuUsageHistoryMax = 100;
  729. static std::vector<int> ramUsageHistory;
  730. static const int ramUsageHistoryMax = 100;
  731.  
  732. switch (uMsg)
  733. {
  734. case WM_ERASEBKGND:
  735. return 1;
  736.  
  737. case WM_PAINT:
  738. {
  739. PAINTSTRUCT ps;
  740. HDC hdc = BeginPaint(hwnd, &ps);
  741.  
  742. HBRUSH darkBrush = CreateSolidBrush(RGB(43, 41, 55));
  743. FillRect(hdc, &ps.rcPaint, darkBrush);
  744. DeleteObject(darkBrush);
  745.  
  746. EndPaint(hwnd, &ps);
  747. }
  748. return 0;
  749.  
  750. case WM_CREATE:
  751. {
  752. GetSystemInfo(&sysInfo);
  753. CurrentSysProcTimes = new SYSTEM_PROCESSOR_TIMES[sysInfo.dwNumberOfProcessors];
  754. PreviousSysProcTimes = new SYSTEM_PROCESSOR_TIMES[sysInfo.dwNumberOfProcessors];
  755. ZeroMemory(CurrentSysProcTimes, sizeof(SYSTEM_PROCESSOR_TIMES) * sysInfo.dwNumberOfProcessors);
  756. ZeroMemory(PreviousSysProcTimes, sizeof(SYSTEM_PROCESSOR_TIMES) * sysInfo.dwNumberOfProcessors);
  757.  
  758. lib = LoadLibrary(L"ntdll.dll");
  759. if (!lib) {
  760. MessageBox(NULL, L"Не удалось загрузить ntdll.dll", L"Ошибка", MB_OK | MB_ICONERROR);
  761. PostQuitMessage(0);
  762. return -1;
  763. }
  764.  
  765. ZwQuerySystemInformation = (ZwQuerySystemInformationFunc)GetProcAddress(lib, "ZwQuerySystemInformation");
  766. if (!ZwQuerySystemInformation) {
  767. MessageBox(NULL, L"Не удалось найти функцию ZwQuerySystemInformation", L"Ошибка", MB_OK | MB_ICONERROR);
  768. FreeLibrary(lib);
  769. PostQuitMessage(0);
  770. return -1;
  771. }
  772.  
  773. if (ZwQuerySystemInformation(sysInfo.dwNumberOfProcessors, &PreviousSysProcTimes[0], sizeof(SYSTEM_PROCESSOR_TIMES) * sysInfo.dwNumberOfProcessors, nullptr) != 0) {
  774. MessageBox(NULL, L"Не удалось получить данные о процессорах", L"Ошибка", MB_OK | MB_ICONERROR);
  775. FreeLibrary(lib);
  776. PostQuitMessage(0);
  777. return -1;
  778. }
  779.  
  780. hTabControl = CreateWindowEx(0, WC_TABCONTROL, NULL,
  781. WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
  782. TabControlX, TabControlY, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 40,
  783. hwnd, (HMENU)IDC_TABCONTROL, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  784.  
  785. WNDPROC oldTabControlProc = (WNDPROC)GetWindowLongPtr(hTabControl, GWLP_WNDPROC);
  786. SetWindowLongPtr(hTabControl, GWLP_WNDPROC, (LONG_PTR)TabControlProc);
  787. SetWindowLongPtr(hTabControl, GWLP_USERDATA, (LONG_PTR)oldTabControlProc);
  788.  
  789. SetClassLongPtr(hTabControl, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(43, 41, 55)));
  790.  
  791. AddTabItems(hTabControl);
  792. SetMenu(hwnd, CreateAppMenu());
  793.  
  794. hListViewProcesses = CreateProcessListView(hTabControl);
  795.  
  796. PopulateProcessListView(hListViewProcesses, iconMap);
  797. SetClassLongPtr(hListViewProcesses, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(57, 66, 100)));
  798. ListView_SetBkColor(hListViewProcesses, RGB(43, 41, 55));
  799.  
  800. WNDPROC oldListViewProcessesProc = (WNDPROC)SetWindowLongPtr(hListViewProcesses, GWLP_WNDPROC, (LONG_PTR)ListViewProc);
  801. SetWindowLongPtr(hListViewProcesses, GWLP_USERDATA, (LONG_PTR)oldListViewProcessesProc);
  802.  
  803. hProgressBarCPU = CreateWindowEx(0, PROGRESS_CLASS, L"",
  804. WS_CHILD | PBS_SMOOTH | PBS_MARQUEE,
  805. 10, 50, 300, 25, hTabControl, (HMENU)IDC_PROGRESSBAR_CPU,
  806. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  807.  
  808. SendMessage(hProgressBarCPU, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  809. SetClassLongPtr(hProgressBarCPU, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(43, 41, 55)));
  810.  
  811. hProgressBarRAM = CreateWindowEx(0, PROGRESS_CLASS, L"",
  812. WS_CHILD | PBS_SMOOTH | PBS_MARQUEE,
  813. SCREEN_WIDTH - 340, 50, 300, 25, hTabControl, (HMENU)IDC_PROGRESSBAR_RAM,
  814. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  815.  
  816. SendMessage(hProgressBarRAM, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  817. SetClassLongPtr(hProgressBarCPU, GCLP_HBRBACKGROUND, (LONG_PTR)CreateSolidBrush(RGB(43, 41, 55)));
  818.  
  819. hLabelCPU = CreateWindowEx(0, WC_STATIC, L"",
  820. WS_CHILD,
  821. 10, 100, 150, 20, hTabControl, NULL,
  822. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  823.  
  824. hLabelRAM = CreateWindowEx(0, WC_STATIC, L"",
  825. WS_CHILD,
  826. SCREEN_WIDTH - 340, 100, 150, 20, hTabControl, NULL,
  827. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  828.  
  829. hLabelUptime = CreateWindowEx(0, WC_STATIC, L"",
  830. WS_CHILD,
  831. SCREEN_WIDTH / 2 - 150, 50, 300, 20, hTabControl, NULL,
  832. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  833.  
  834. hLabelMemoryInfo = CreateWindowEx(0, WC_STATIC, L"",
  835. WS_CHILD,
  836. SCREEN_WIDTH / 2 - 150, 75, 300, 40, hTabControl, NULL,
  837. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  838.  
  839. hPerfomanceCPU = CreateWindowEx(0, WC_STATIC, L"", WS_CHILD,
  840. 10, 140, SCREEN_WIDTH / 2 - 50, SCREEN_HEIGHT * 0.65, hTabControl, NULL, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  841.  
  842. hPerfomanceRAM = CreateWindowEx(0, WC_STATIC, L"", WS_CHILD,
  843. SCREEN_WIDTH / 2, 140, SCREEN_WIDTH / 2 - 50, SCREEN_HEIGHT * 0.65, hTabControl, NULL, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
  844.  
  845. SendMessage(hProgressBarCPU, PBM_SETBARCOLOR, 0, RGB(26, 188, 156));
  846. SendMessage(hProgressBarRAM, PBM_SETBARCOLOR, 0, RGB(26, 188, 156));
  847.  
  848. SetTimer(hwnd, TIMER_GRAPH, 1000, NULL);
  849. timerId = SetTimer(hwnd, TIMER_PROCESSES, updateInterval, NULL);
  850. }
  851. break;
  852.  
  853. case WM_TIMER:
  854. {
  855. if (wParam == TIMER_PROCESSES)
  856. {
  857. PopulateProcessListView(hListViewProcesses, iconMap);
  858. }
  859.  
  860. if (wParam == TIMER_GRAPH)
  861. {
  862. int cpuUsage = GetCurrentCPUUsage(sysInfo, CurrentSysProcTimes, PreviousSysProcTimes, ZwQuerySystemInformation);
  863. int ramUsage = GetCurrentRAMUsage();
  864.  
  865. SendMessage(hProgressBarCPU, PBM_SETPOS, cpuUsage, 0);
  866. SendMessage(hProgressBarRAM, PBM_SETPOS, ramUsage, 0);
  867.  
  868. std::wstring pcTime = GetSystemUptime();
  869. std::wstring cpuLabel = L"Загрузка ЦП: " + std::to_wstring(cpuUsage) + L"%";
  870. std::wstring ramLabel = L"Загрузка Памяти: " + std::to_wstring(ramUsage) + L"%";
  871.  
  872. SetWindowText(hLabelCPU, cpuLabel.c_str());
  873. SetWindowText(hLabelRAM, ramLabel.c_str());
  874. SetWindowText(hLabelUptime, pcTime.c_str());
  875. SetWindowText(hLabelMemoryInfo, GetMemoryInfo().c_str());
  876.  
  877. PushValue(cpuUsageHistory, cpuUsageHistoryMax, cpuUsage);
  878. PushValue(ramUsageHistory, ramUsageHistoryMax, ramUsage);
  879.  
  880. DrawGraph(hPerfomanceCPU, cpuUsageHistory, cpuUsageHistoryMax);
  881. DrawGraph(hPerfomanceRAM, ramUsageHistory, ramUsageHistoryMax);
  882. }
  883. }
  884.  
  885. /*case WM_DRAWITEM:
  886. {
  887. LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT)lParam;
  888. if (lpDrawItem->CtlID == ID_SELECT_BTN)
  889. {
  890.  
  891. }
  892. break;
  893. }*/
  894.  
  895. case WM_KEYDOWN:
  896. {
  897. int wmId = LOWORD(wParam);
  898. int wmEvent = HIWORD(wParam);
  899.  
  900. /*if (wParam == VK_RETURN) {
  901.  
  902. }*/
  903. }
  904. break;
  905.  
  906.  
  907. case WM_NOTIFY:
  908. {
  909. NMHDR* nmhdr = (NMHDR*)lParam;
  910.  
  911. if (nmhdr->hwndFrom == hTabControl && nmhdr->code == TCN_SELCHANGE) {
  912. int tabIndex = TabCtrl_GetCurSel(hTabControl);
  913. ShowWindow(hListViewProcesses, tabIndex == 0 ? SW_SHOW : SW_HIDE);
  914. ShowWindow(hProgressBarCPU, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  915. ShowWindow(hProgressBarRAM, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  916. ShowWindow(hLabelUptime, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  917. ShowWindow(hLabelMemoryInfo, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  918. ShowWindow(hLabelCPU, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  919. ShowWindow(hLabelRAM, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  920. ShowWindow(hPerfomanceCPU, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  921. ShowWindow(hPerfomanceRAM, tabIndex == 1 ? SW_SHOW : SW_HIDE);
  922. }
  923.  
  924. if (nmhdr->hwndFrom == hListViewProcesses && nmhdr->code == LVN_COLUMNCLICK)
  925. {
  926. NMITEMACTIVATE* pnmItem = (NMITEMACTIVATE*)lParam;
  927. LVCOLUMN lvColumn;
  928. ZeroMemory(&lvColumn, sizeof(lvColumn));
  929.  
  930. static int nSortColumn = 0;
  931. static BOOL bSortAscending = TRUE;
  932.  
  933. if (pnmItem->iSubItem == nSortColumn)
  934. {
  935. bSortAscending = !bSortAscending;
  936. }
  937. else
  938. {
  939. nSortColumn = pnmItem->iSubItem;
  940. bSortAscending = TRUE;
  941. }
  942. //SortListView(hListViewProcesses, nSortColumn, bSortAscending);
  943. }
  944. }
  945. break;
  946.  
  947.  
  948.  
  949. case WM_COMMAND:
  950. {
  951. int wmId = LOWORD(wParam);
  952. int wmEvent = HIWORD(wParam);
  953.  
  954. switch (wmId)
  955. {
  956. case ID_MENU_EXIT:
  957. {
  958. SendMessage(hwnd, WM_CLOSE, wParam, lParam);
  959. }
  960. break;
  961. case ID_MENU_ABOUT:
  962. {
  963. MessageBox(hwnd, L"Task Manager App\nDeveloped by Krutko Andrey\nBSUIR 2024", L"About", MB_OK | MB_ICONINFORMATION);
  964. }
  965. break;
  966. case ID_MENU_UPDATE:
  967. {
  968. PopulateProcessListView(hListViewProcesses, iconMap);
  969. }
  970. break;
  971.  
  972. case ID_MENU_RARE:
  973. updateInterval = 5000;
  974. break;
  975. case ID_MENU_NORMAL:
  976. updateInterval = 3000;
  977. break;
  978. case ID_MENU_OFTEN:
  979. updateInterval = 1000;
  980. break;
  981. case ID_MENU_NONE:
  982. KillTimer(hwnd, TIMER_PROCESSES);
  983. timerId = 0;
  984. return 0;
  985. }
  986.  
  987. if (timerId) {
  988. KillTimer(hwnd, TIMER_PROCESSES);
  989. }
  990. timerId = SetTimer(hwnd, TIMER_PROCESSES, updateInterval, NULL);
  991. }
  992. break;
  993.  
  994. case WM_CLOSE:
  995. if (MessageBox(hwnd, L"Вы действительно хотите выйти?", L"Внимание", MB_OKCANCEL) == IDOK)
  996. {
  997. DestroyWindow(hwnd);
  998. }
  999. break;
  1000.  
  1001. case WM_SIZE:
  1002. {
  1003. int width = LOWORD(lParam);
  1004. int height = HIWORD(lParam);
  1005. MoveWindow(hTabControl, TabControlY, TabControlY, width - 20, height - 40, TRUE);
  1006. MoveWindow(hListViewProcesses, ProcessListViewX, ProcessListViewY, width - 40, height - 70, TRUE);
  1007.  
  1008. return 0;
  1009. }
  1010.  
  1011. case WM_DESTROY:
  1012. {
  1013. if (lib) {
  1014. FreeLibrary(lib);
  1015. }
  1016.  
  1017. delete[] CurrentSysProcTimes;
  1018. delete[] PreviousSysProcTimes;
  1019.  
  1020. KillTimer(hwnd, TIMER_PROCESSES);
  1021. HIMAGELIST hImageList = ListView_GetImageList(hListViewProcesses, LVSIL_SMALL);
  1022. if (hImageList) ImageList_Destroy(hImageList);
  1023. hImageList = TabCtrl_GetImageList(hTabControl);
  1024. if (hImageList) ImageList_Destroy(hImageList);
  1025. PostQuitMessage(0);
  1026. }
  1027. return 0;
  1028.  
  1029.  
  1030. default:
  1031. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  1032. }
  1033. return 0;
  1034. }
  1035.  
  1036. int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
  1037. _In_ PWSTR pCmdLine, _In_ int nCmdShow)
  1038. {
  1039. WNDCLASS wc = { 0 };
  1040. wc.lpfnWndProc = WindowProc;
  1041. wc.hInstance = hInstance;
  1042. wc.lpszClassName = MainName;
  1043. wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
  1044. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  1045. wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINICON));
  1046.  
  1047. RegisterClass(&wc);
  1048.  
  1049. HWND hwnd = CreateWindowEx(0, MainName, MainName, WS_OVERLAPPEDWINDOW,
  1050. CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT,
  1051. NULL, NULL, hInstance, NULL
  1052. );
  1053.  
  1054. if (hwnd == NULL)
  1055. {
  1056. return 0;
  1057. }
  1058.  
  1059. /*LONG style = GetWindowLong(hwnd, GWL_STYLE);
  1060. style &= ~(WS_CAPTION | WS_THICKFRAME);
  1061. SetWindowLong(hwnd, GWL_STYLE, style);
  1062.  
  1063. LONG exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
  1064. exStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
  1065. SetWindowLong(hwnd, GWL_EXSTYLE, exStyle);*/
  1066.  
  1067. MONITORINFO mi = { sizeof(mi) };
  1068. if (GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &mi)) {
  1069. SetWindowPos(hwnd, HWND_TOP,
  1070. mi.rcMonitor.left, mi.rcMonitor.top,
  1071. mi.rcMonitor.right - mi.rcMonitor.left,
  1072. mi.rcMonitor.bottom - mi.rcMonitor.top,
  1073. SWP_NOZORDER | SWP_FRAMECHANGED);
  1074. }
  1075.  
  1076. ShowWindow(hwnd, SW_SHOWMAXIMIZED);
  1077.  
  1078. MSG msg;
  1079. while (GetMessage(&msg, NULL, 0, 0))
  1080. {
  1081. TranslateMessage(&msg);
  1082. DispatchMessage(&msg);
  1083. }
  1084.  
  1085. return 0;
  1086. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement