Advertisement
Old_But_Gold

Untitled

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