taskmgr.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. /*
  2. * ReactOS Task Manager
  3. *
  4. * taskmgr.c : Defines the entry point for the application.
  5. *
  6. * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
  7. * Copyright (C) 2008 Vladimir Pankratov
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include <winnt.h>
  28. #include "resource.h"
  29. #include "taskmgr.h"
  30. #include "perfdata.h"
  31. #include "column.h"
  32. #define STATUS_WINDOW 2001
  33. /* Global Variables: */
  34. HINSTANCE hInst; /* current instance */
  35. HWND hMainWnd; /* Main Window */
  36. HWND hStatusWnd; /* Status Bar Window */
  37. HWND hTabWnd; /* Tab Control Window */
  38. int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */
  39. int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */
  40. int nOldWidth; /* Holds the previous client area width */
  41. int nOldHeight; /* Holds the previous client area height */
  42. BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
  43. TASKMANAGER_SETTINGS TaskManagerSettings;
  44. void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
  45. {
  46. SetBkColor(hDC, clr);
  47. ExtTextOutW(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
  48. }
  49. static void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
  50. {
  51. RECT rect;
  52. SetBkColor(hDC, clr);
  53. SetRect(&rect, x, y, x + cx, y + cy);
  54. ExtTextOutW(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
  55. }
  56. static void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
  57. {
  58. FillSolidRect2(hDC, x, y, cx - 1, 1, clrTopLeft);
  59. FillSolidRect2(hDC, x, y, 1, cy - 1, clrTopLeft);
  60. FillSolidRect2(hDC, x + cx, y, -1, cy, clrBottomRight);
  61. FillSolidRect2(hDC, x, y + cy, cx, -1, clrBottomRight);
  62. }
  63. static BOOL OnCreate(HWND hWnd)
  64. {
  65. HMENU hMenu;
  66. HMENU hEditMenu;
  67. HMENU hViewMenu;
  68. HMENU hUpdateSpeedMenu;
  69. HMENU hCPUHistoryMenu;
  70. int nActivePage;
  71. int nParts[3];
  72. RECT rc;
  73. TCITEMW item;
  74. static WCHAR wszApplications[255];
  75. static WCHAR wszProcesses[255];
  76. static WCHAR wszPerformance[255];
  77. LoadStringW(hInst, IDS_APPLICATIONS, wszApplications, ARRAY_SIZE(wszApplications));
  78. LoadStringW(hInst, IDS_PROCESSES, wszProcesses, ARRAY_SIZE(wszProcesses));
  79. LoadStringW(hInst, IDS_PERFORMANCE, wszPerformance, ARRAY_SIZE(wszPerformance));
  80. SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW(hInst, MAKEINTRESOURCEW(IDI_TASKMANAGER)));
  81. SendMessageW(hMainWnd, WM_SETICON, ICON_SMALL,
  82. (LPARAM)LoadImageW(hInst, MAKEINTRESOURCEW(IDI_TASKMANAGER), IMAGE_ICON,
  83. GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
  84. LR_SHARED));
  85. /* Initialize the Windows Common Controls DLL */
  86. InitCommonControls();
  87. /* Get the minimum window sizes */
  88. GetWindowRect(hWnd, &rc);
  89. nMinimumWidth = (rc.right - rc.left);
  90. nMinimumHeight = (rc.bottom - rc.top);
  91. /* Create the status bar */
  92. hStatusWnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, NULL, hWnd, STATUS_WINDOW);
  93. if(!hStatusWnd)
  94. return FALSE;
  95. /* Create the status bar panes */
  96. nParts[0] = 100;
  97. nParts[1] = 210;
  98. nParts[2] = 400;
  99. SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
  100. /* Create tab pages */
  101. hTabWnd = GetDlgItem(hWnd, IDC_TAB);
  102. #if 1
  103. hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hWnd, ApplicationPageWndProc);
  104. hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hWnd, ProcessPageWndProc);
  105. hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hWnd, PerformancePageWndProc);
  106. #else
  107. hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hTabWnd, ApplicationPageWndProc);
  108. hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hTabWnd, ProcessPageWndProc);
  109. hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hTabWnd, PerformancePageWndProc);
  110. #endif
  111. /* Insert tabs */
  112. memset(&item, 0, sizeof(TCITEMW));
  113. item.mask = TCIF_TEXT;
  114. item.pszText = wszApplications;
  115. SendMessageW(hTabWnd, TCM_INSERTITEMW, 0, (LPARAM)&item);
  116. memset(&item, 0, sizeof(TCITEMW));
  117. item.mask = TCIF_TEXT;
  118. item.pszText = wszProcesses;
  119. SendMessageW(hTabWnd, TCM_INSERTITEMW, 1, (LPARAM)&item);
  120. memset(&item, 0, sizeof(TCITEMW));
  121. item.mask = TCIF_TEXT;
  122. item.pszText = wszPerformance;
  123. SendMessageW(hTabWnd, TCM_INSERTITEMW, 2, (LPARAM)&item);
  124. /* Size everything correctly */
  125. GetClientRect(hWnd, &rc);
  126. nOldWidth = rc.right;
  127. nOldHeight = rc.bottom;
  128. if ((TaskManagerSettings.Left != 0) ||
  129. (TaskManagerSettings.Top != 0) ||
  130. (TaskManagerSettings.Right != 0) ||
  131. (TaskManagerSettings.Bottom != 0))
  132. MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE);
  133. if (TaskManagerSettings.Maximized)
  134. ShowWindow(hWnd, SW_MAXIMIZE);
  135. /* Set the always on top style */
  136. hMenu = GetMenu(hWnd);
  137. hEditMenu = GetSubMenu(hMenu, 1);
  138. hViewMenu = GetSubMenu(hMenu, 2);
  139. hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
  140. hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
  141. /* Check or uncheck the always on top menu item */
  142. if (TaskManagerSettings.AlwaysOnTop) {
  143. CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED);
  144. SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  145. } else {
  146. CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
  147. SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
  148. }
  149. /* Check or uncheck the minimize on use menu item */
  150. if (TaskManagerSettings.MinimizeOnUse)
  151. CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
  152. else
  153. CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
  154. /* Check or uncheck the hide when minimized menu item */
  155. if (TaskManagerSettings.HideWhenMinimized)
  156. CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
  157. else
  158. CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
  159. /* Check or uncheck the show 16-bit tasks menu item */
  160. if (TaskManagerSettings.Show16BitTasks)
  161. CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
  162. else
  163. CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
  164. if (TaskManagerSettings.View_LargeIcons)
  165. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
  166. else if (TaskManagerSettings.View_SmallIcons)
  167. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
  168. else
  169. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
  170. if (TaskManagerSettings.ShowKernelTimes)
  171. CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
  172. else
  173. CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
  174. if (TaskManagerSettings.UpdateSpeed == 1)
  175. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
  176. else if (TaskManagerSettings.UpdateSpeed == 2)
  177. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
  178. else if (TaskManagerSettings.UpdateSpeed == 4)
  179. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
  180. else
  181. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
  182. if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
  183. CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
  184. else
  185. CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
  186. nActivePage = TaskManagerSettings.ActiveTabPage;
  187. SendMessageW(hTabWnd, TCM_SETCURFOCUS, 0, 0);
  188. SendMessageW(hTabWnd, TCM_SETCURFOCUS, 1, 0);
  189. SendMessageW(hTabWnd, TCM_SETCURFOCUS, 2, 0);
  190. SendMessageW(hTabWnd, TCM_SETCURFOCUS, nActivePage, 0);
  191. if (TaskManagerSettings.UpdateSpeed == 1)
  192. SetTimer(hWnd, 1, 1000, NULL);
  193. else if (TaskManagerSettings.UpdateSpeed == 2)
  194. SetTimer(hWnd, 1, 2000, NULL);
  195. else if (TaskManagerSettings.UpdateSpeed == 4)
  196. SetTimer(hWnd, 1, 4000, NULL);
  197. /*
  198. * Refresh the performance data
  199. * Sample it twice so we can establish
  200. * the delta values & cpu usage
  201. */
  202. PerfDataRefresh();
  203. PerfDataRefresh();
  204. RefreshApplicationPage();
  205. RefreshProcessPage();
  206. RefreshPerformancePage();
  207. TrayIcon_ShellAddTrayIcon();
  208. return TRUE;
  209. }
  210. /* OnSize()
  211. * This function handles all the sizing events for the application
  212. * It re-sizes every window, and child window that needs re-sizing
  213. */
  214. static void OnSize( UINT nType, int cx, int cy )
  215. {
  216. int nParts[3];
  217. int nXDifference;
  218. int nYDifference;
  219. RECT rc;
  220. if (nType == SIZE_MINIMIZED)
  221. {
  222. if(TaskManagerSettings.HideWhenMinimized)
  223. {
  224. ShowWindow(hMainWnd, SW_HIDE);
  225. }
  226. return;
  227. }
  228. nXDifference = cx - nOldWidth;
  229. nYDifference = cy - nOldHeight;
  230. nOldWidth = cx;
  231. nOldHeight = cy;
  232. /* Update the status bar size */
  233. GetWindowRect(hStatusWnd, &rc);
  234. SendMessageW(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
  235. /* Update the status bar pane sizes */
  236. nParts[0] = bInMenuLoop ? -1 : 100;
  237. nParts[1] = 210;
  238. nParts[2] = cx;
  239. SendMessageW(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (LPARAM)nParts);
  240. /* Resize the tab control */
  241. GetWindowRect(hTabWnd, &rc);
  242. cx = (rc.right - rc.left) + nXDifference;
  243. cy = (rc.bottom - rc.top) + nYDifference;
  244. SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
  245. /* Resize the application page */
  246. GetWindowRect(hApplicationPage, &rc);
  247. cx = (rc.right - rc.left) + nXDifference;
  248. cy = (rc.bottom - rc.top) + nYDifference;
  249. SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
  250. /* Resize the process page */
  251. GetWindowRect(hProcessPage, &rc);
  252. cx = (rc.right - rc.left) + nXDifference;
  253. cy = (rc.bottom - rc.top) + nYDifference;
  254. SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
  255. /* Resize the performance page */
  256. GetWindowRect(hPerformancePage, &rc);
  257. cx = (rc.right - rc.left) + nXDifference;
  258. cy = (rc.bottom - rc.top) + nYDifference;
  259. SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
  260. }
  261. static void LoadSettings(void)
  262. {
  263. HKEY hKey;
  264. int i;
  265. DWORD dwSize;
  266. static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
  267. 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
  268. static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
  269. /* Window size & position settings */
  270. TaskManagerSettings.Maximized = FALSE;
  271. TaskManagerSettings.Left = 0;
  272. TaskManagerSettings.Top = 0;
  273. TaskManagerSettings.Right = 0;
  274. TaskManagerSettings.Bottom = 0;
  275. /* Tab settings */
  276. TaskManagerSettings.ActiveTabPage = 0;
  277. /* Options menu settings */
  278. TaskManagerSettings.AlwaysOnTop = FALSE;
  279. TaskManagerSettings.MinimizeOnUse = TRUE;
  280. TaskManagerSettings.HideWhenMinimized = TRUE;
  281. TaskManagerSettings.Show16BitTasks = TRUE;
  282. /* Update speed settings */
  283. TaskManagerSettings.UpdateSpeed = 2;
  284. /* Applications page settings */
  285. TaskManagerSettings.View_LargeIcons = FALSE;
  286. TaskManagerSettings.View_SmallIcons = FALSE;
  287. TaskManagerSettings.View_Details = TRUE;
  288. /* Processes page settings */
  289. TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */
  290. TaskManagerSettings.Column_ImageName = TRUE;
  291. TaskManagerSettings.Column_PID = TRUE;
  292. TaskManagerSettings.Column_CPUUsage = TRUE;
  293. TaskManagerSettings.Column_CPUTime = TRUE;
  294. TaskManagerSettings.Column_MemoryUsage = TRUE;
  295. TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
  296. TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
  297. TaskManagerSettings.Column_PageFaults = FALSE;
  298. TaskManagerSettings.Column_USERObjects = FALSE;
  299. TaskManagerSettings.Column_IOReads = FALSE;
  300. TaskManagerSettings.Column_IOReadBytes = FALSE;
  301. TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */
  302. TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */
  303. TaskManagerSettings.Column_PageFaultsDelta = FALSE;
  304. TaskManagerSettings.Column_VirtualMemorySize = FALSE;
  305. TaskManagerSettings.Column_PagedPool = FALSE;
  306. TaskManagerSettings.Column_NonPagedPool = FALSE;
  307. TaskManagerSettings.Column_BasePriority = FALSE;
  308. TaskManagerSettings.Column_HandleCount = FALSE;
  309. TaskManagerSettings.Column_ThreadCount = FALSE;
  310. TaskManagerSettings.Column_GDIObjects = FALSE;
  311. TaskManagerSettings.Column_IOWrites = FALSE;
  312. TaskManagerSettings.Column_IOWriteBytes = FALSE;
  313. TaskManagerSettings.Column_IOOther = FALSE;
  314. TaskManagerSettings.Column_IOOtherBytes = FALSE;
  315. for (i = 0; i < 25; i++) {
  316. TaskManagerSettings.ColumnOrderArray[i] = i;
  317. }
  318. TaskManagerSettings.ColumnSizeArray[0] = 105;
  319. TaskManagerSettings.ColumnSizeArray[1] = 50;
  320. TaskManagerSettings.ColumnSizeArray[2] = 107;
  321. TaskManagerSettings.ColumnSizeArray[3] = 70;
  322. TaskManagerSettings.ColumnSizeArray[4] = 35;
  323. TaskManagerSettings.ColumnSizeArray[5] = 70;
  324. TaskManagerSettings.ColumnSizeArray[6] = 70;
  325. TaskManagerSettings.ColumnSizeArray[7] = 100;
  326. TaskManagerSettings.ColumnSizeArray[8] = 70;
  327. TaskManagerSettings.ColumnSizeArray[9] = 70;
  328. TaskManagerSettings.ColumnSizeArray[10] = 70;
  329. TaskManagerSettings.ColumnSizeArray[11] = 70;
  330. TaskManagerSettings.ColumnSizeArray[12] = 70;
  331. TaskManagerSettings.ColumnSizeArray[13] = 70;
  332. TaskManagerSettings.ColumnSizeArray[14] = 60;
  333. TaskManagerSettings.ColumnSizeArray[15] = 60;
  334. TaskManagerSettings.ColumnSizeArray[16] = 60;
  335. TaskManagerSettings.ColumnSizeArray[17] = 60;
  336. TaskManagerSettings.ColumnSizeArray[18] = 60;
  337. TaskManagerSettings.ColumnSizeArray[19] = 70;
  338. TaskManagerSettings.ColumnSizeArray[20] = 70;
  339. TaskManagerSettings.ColumnSizeArray[21] = 70;
  340. TaskManagerSettings.ColumnSizeArray[22] = 70;
  341. TaskManagerSettings.ColumnSizeArray[23] = 70;
  342. TaskManagerSettings.ColumnSizeArray[24] = 70;
  343. TaskManagerSettings.SortColumn = 1;
  344. TaskManagerSettings.SortAscending = TRUE;
  345. /* Performance page settings */
  346. TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
  347. TaskManagerSettings.ShowKernelTimes = FALSE;
  348. /* Open the key */
  349. /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
  350. if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  351. return;
  352. /* Read the settings */
  353. dwSize = sizeof(TASKMANAGER_SETTINGS);
  354. RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
  355. /* Close the key */
  356. RegCloseKey(hKey);
  357. }
  358. static void SaveSettings(void)
  359. {
  360. HKEY hKey;
  361. static const WCHAR wszSubKey3[] = {'S','o','f','t','w','a','r','e','\\',
  362. 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
  363. static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
  364. /* Open (or create) the key */
  365. /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
  366. if (RegCreateKeyExW(HKEY_CURRENT_USER, wszSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
  367. return;
  368. /* Save the settings */
  369. RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
  370. /* Close the key */
  371. RegCloseKey(hKey);
  372. }
  373. static void TaskManager_OnRestoreMainWindow(void)
  374. {
  375. BOOL OnTop;
  376. OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
  377. OpenIcon(hMainWnd);
  378. SetForegroundWindow(hMainWnd);
  379. SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
  380. }
  381. static void TaskManager_OnEnterMenuLoop(HWND hWnd)
  382. {
  383. int nParts;
  384. /* Update the status bar pane sizes */
  385. nParts = -1;
  386. SendMessageW(hStatusWnd, SB_SETPARTS, 1, (LPARAM)&nParts);
  387. bInMenuLoop = TRUE;
  388. SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
  389. }
  390. static void TaskManager_OnExitMenuLoop(HWND hWnd)
  391. {
  392. RECT rc;
  393. int nParts[3];
  394. WCHAR text[256];
  395. WCHAR wszCPU_Usage[255];
  396. WCHAR wszProcesses[255];
  397. LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, ARRAY_SIZE(wszCPU_Usage));
  398. LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, ARRAY_SIZE(wszProcesses));
  399. bInMenuLoop = FALSE;
  400. /* Update the status bar pane sizes */
  401. GetClientRect(hWnd, &rc);
  402. nParts[0] = 100;
  403. nParts[1] = 210;
  404. nParts[2] = rc.right;
  405. SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
  406. SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
  407. wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage());
  408. SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text);
  409. wsprintfW(text, wszProcesses, PerfDataGetProcessCount());
  410. SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text);
  411. }
  412. static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
  413. {
  414. WCHAR wstr[256] = {0};
  415. LoadStringW(hInst, nItemID, wstr, ARRAY_SIZE(wstr));
  416. SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)wstr);
  417. }
  418. static void TaskManager_OnViewUpdateSpeedHigh(void)
  419. {
  420. HMENU hMenu;
  421. HMENU hViewMenu;
  422. HMENU hUpdateSpeedMenu;
  423. hMenu = GetMenu(hMainWnd);
  424. hViewMenu = GetSubMenu(hMenu, 2);
  425. hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
  426. TaskManagerSettings.UpdateSpeed = 1;
  427. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
  428. KillTimer(hMainWnd, 1);
  429. SetTimer(hMainWnd, 1, 1000, NULL);
  430. }
  431. static void TaskManager_OnViewUpdateSpeedNormal(void)
  432. {
  433. HMENU hMenu;
  434. HMENU hViewMenu;
  435. HMENU hUpdateSpeedMenu;
  436. hMenu = GetMenu(hMainWnd);
  437. hViewMenu = GetSubMenu(hMenu, 2);
  438. hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
  439. TaskManagerSettings.UpdateSpeed = 2;
  440. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
  441. KillTimer(hMainWnd, 1);
  442. SetTimer(hMainWnd, 1, 2000, NULL);
  443. }
  444. static void TaskManager_OnViewUpdateSpeedLow(void)
  445. {
  446. HMENU hMenu;
  447. HMENU hViewMenu;
  448. HMENU hUpdateSpeedMenu;
  449. hMenu = GetMenu(hMainWnd);
  450. hViewMenu = GetSubMenu(hMenu, 2);
  451. hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
  452. TaskManagerSettings.UpdateSpeed = 4;
  453. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
  454. KillTimer(hMainWnd, 1);
  455. SetTimer(hMainWnd, 1, 4000, NULL);
  456. }
  457. static void TaskManager_OnViewUpdateSpeedPaused(void)
  458. {
  459. HMENU hMenu;
  460. HMENU hViewMenu;
  461. HMENU hUpdateSpeedMenu;
  462. hMenu = GetMenu(hMainWnd);
  463. hViewMenu = GetSubMenu(hMenu, 2);
  464. hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
  465. TaskManagerSettings.UpdateSpeed = 0;
  466. CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
  467. KillTimer(hMainWnd, 1);
  468. }
  469. static void TaskManager_OnTabWndSelChange(void)
  470. {
  471. int i;
  472. HMENU hMenu;
  473. HMENU hOptionsMenu;
  474. HMENU hViewMenu;
  475. HMENU hSubMenu;
  476. WCHAR wszLargeIcons[255];
  477. WCHAR wszSmallIcons[255];
  478. WCHAR wszDetails[255];
  479. WCHAR wszWindows[255];
  480. WCHAR wszSelectColumns[255];
  481. WCHAR wszShow16bTasks[255];
  482. WCHAR wszOneGraphAllCPU[255];
  483. WCHAR wszOneGraphPerCPU[255];
  484. WCHAR wszCPUHistory[255];
  485. WCHAR wszShowKernelTimes[255];
  486. LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, ARRAY_SIZE(wszLargeIcons));
  487. LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, ARRAY_SIZE(wszSmallIcons));
  488. LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, ARRAY_SIZE(wszDetails));
  489. LoadStringW(hInst, IDS_WINDOWS, wszWindows, ARRAY_SIZE(wszWindows));
  490. LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, ARRAY_SIZE(wszSelectColumns));
  491. LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, ARRAY_SIZE(wszShow16bTasks));
  492. LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, ARRAY_SIZE(wszOneGraphAllCPU));
  493. LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, ARRAY_SIZE(wszOneGraphPerCPU));
  494. LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, ARRAY_SIZE(wszCPUHistory));
  495. LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, ARRAY_SIZE(wszShowKernelTimes));
  496. hMenu = GetMenu(hMainWnd);
  497. hViewMenu = GetSubMenu(hMenu, 2);
  498. hOptionsMenu = GetSubMenu(hMenu, 1);
  499. TaskManagerSettings.ActiveTabPage = SendMessageW(hTabWnd, TCM_GETCURSEL, 0, 0);
  500. for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
  501. hSubMenu = GetSubMenu(hViewMenu, i);
  502. if (hSubMenu)
  503. DestroyMenu(hSubMenu);
  504. RemoveMenu(hViewMenu, i, MF_BYPOSITION);
  505. }
  506. RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
  507. switch (TaskManagerSettings.ActiveTabPage) {
  508. case 0:
  509. ShowWindow(hApplicationPage, SW_SHOW);
  510. ShowWindow(hProcessPage, SW_HIDE);
  511. ShowWindow(hPerformancePage, SW_HIDE);
  512. BringWindowToTop(hApplicationPage);
  513. AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
  514. AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
  515. AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);
  516. if (GetMenuItemCount(hMenu) <= 4) {
  517. hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
  518. InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
  519. DrawMenuBar(hMainWnd);
  520. }
  521. if (TaskManagerSettings.View_LargeIcons)
  522. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
  523. else if (TaskManagerSettings.View_SmallIcons)
  524. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
  525. else
  526. CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
  527. /*
  528. * Give the application list control focus
  529. */
  530. SetFocus(hApplicationPageListCtrl);
  531. break;
  532. case 1:
  533. ShowWindow(hApplicationPage, SW_HIDE);
  534. ShowWindow(hProcessPage, SW_SHOW);
  535. ShowWindow(hPerformancePage, SW_HIDE);
  536. BringWindowToTop(hProcessPage);
  537. AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
  538. AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
  539. if (TaskManagerSettings.Show16BitTasks)
  540. CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
  541. if (GetMenuItemCount(hMenu) > 4)
  542. {
  543. RemoveMenu(hMenu, 3, MF_BYPOSITION);
  544. DrawMenuBar(hMainWnd);
  545. }
  546. /*
  547. * Give the process list control focus
  548. */
  549. SetFocus(hProcessPageListCtrl);
  550. break;
  551. case 2:
  552. ShowWindow(hApplicationPage, SW_HIDE);
  553. ShowWindow(hProcessPage, SW_HIDE);
  554. ShowWindow(hPerformancePage, SW_SHOW);
  555. BringWindowToTop(hPerformancePage);
  556. if (GetMenuItemCount(hMenu) > 4) {
  557. RemoveMenu(hMenu, 3, MF_BYPOSITION);
  558. DrawMenuBar(hMainWnd);
  559. }
  560. hSubMenu = CreatePopupMenu();
  561. AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
  562. AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
  563. AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
  564. AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
  565. if (TaskManagerSettings.ShowKernelTimes)
  566. CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
  567. else
  568. CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
  569. if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
  570. CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
  571. else
  572. CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
  573. /*
  574. * Give the tab control focus
  575. */
  576. SetFocus(hTabWnd);
  577. break;
  578. }
  579. }
  580. LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
  581. {
  582. DWORD dwRet;
  583. LPWSTR lpwszTemp = NULL;
  584. static const WCHAR wszFormat[] = {'%','s',' ','(','%','u',')',0};
  585. dwRet = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
  586. NULL,
  587. GetLastError(),
  588. LANG_NEUTRAL,
  589. (LPWSTR)&lpwszTemp,
  590. 0,
  591. NULL );
  592. /* supplied buffer is not long enough */
  593. if (!dwRet || ( dwSize < dwRet+14)) {
  594. lpwszBuf[0] = '\0';
  595. } else {
  596. lpwszTemp[lstrlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
  597. swprintf(lpwszBuf, dwSize, wszFormat, lpwszTemp, GetLastError());
  598. }
  599. if (lpwszTemp) {
  600. LocalFree(lpwszTemp);
  601. }
  602. return lpwszBuf;
  603. }
  604. /* Message handler for dialog box. */
  605. static INT_PTR CALLBACK
  606. TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  607. {
  608. static const WCHAR wszTaskmgr[] = {'t','a','s','k','m','g','r',0};
  609. HDC hdc;
  610. PAINTSTRUCT ps;
  611. LPRECT pRC;
  612. RECT rc;
  613. LPNMHDR pnmh;
  614. WINDOWPLACEMENT wp;
  615. switch (message) {
  616. case WM_INITDIALOG:
  617. hMainWnd = hDlg;
  618. return OnCreate(hDlg);
  619. case WM_COMMAND:
  620. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
  621. EndDialog(hDlg, LOWORD(wParam));
  622. return TRUE;
  623. }
  624. /* Process menu commands */
  625. switch (LOWORD(wParam))
  626. {
  627. case ID_FILE_NEW:
  628. TaskManager_OnFileNew();
  629. break;
  630. case ID_OPTIONS_ALWAYSONTOP:
  631. TaskManager_OnOptionsAlwaysOnTop();
  632. break;
  633. case ID_OPTIONS_MINIMIZEONUSE:
  634. TaskManager_OnOptionsMinimizeOnUse();
  635. break;
  636. case ID_OPTIONS_HIDEWHENMINIMIZED:
  637. TaskManager_OnOptionsHideWhenMinimized();
  638. break;
  639. case ID_OPTIONS_SHOW16BITTASKS:
  640. TaskManager_OnOptionsShow16BitTasks();
  641. break;
  642. case ID_RESTORE:
  643. TaskManager_OnRestoreMainWindow();
  644. break;
  645. case ID_VIEW_LARGE:
  646. ApplicationPage_OnViewLargeIcons();
  647. break;
  648. case ID_VIEW_SMALL:
  649. ApplicationPage_OnViewSmallIcons();
  650. break;
  651. case ID_VIEW_DETAILS:
  652. ApplicationPage_OnViewDetails();
  653. break;
  654. case ID_VIEW_SHOWKERNELTIMES:
  655. PerformancePage_OnViewShowKernelTimes();
  656. break;
  657. case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
  658. PerformancePage_OnViewCPUHistoryOneGraphAll();
  659. break;
  660. case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
  661. PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
  662. break;
  663. case ID_VIEW_UPDATESPEED_HIGH:
  664. TaskManager_OnViewUpdateSpeedHigh();
  665. break;
  666. case ID_VIEW_UPDATESPEED_NORMAL:
  667. TaskManager_OnViewUpdateSpeedNormal();
  668. break;
  669. case ID_VIEW_UPDATESPEED_LOW:
  670. TaskManager_OnViewUpdateSpeedLow();
  671. break;
  672. case ID_VIEW_UPDATESPEED_PAUSED:
  673. TaskManager_OnViewUpdateSpeedPaused();
  674. break;
  675. case ID_VIEW_SELECTCOLUMNS:
  676. ProcessPage_OnViewSelectColumns();
  677. break;
  678. case ID_VIEW_REFRESH:
  679. PostMessageW(hDlg, WM_TIMER, 0, 0);
  680. break;
  681. case ID_WINDOWS_TILEHORIZONTALLY:
  682. ApplicationPage_OnWindowsTileHorizontally();
  683. break;
  684. case ID_WINDOWS_TILEVERTICALLY:
  685. ApplicationPage_OnWindowsTileVertically();
  686. break;
  687. case ID_WINDOWS_MINIMIZE:
  688. ApplicationPage_OnWindowsMinimize();
  689. break;
  690. case ID_WINDOWS_MAXIMIZE:
  691. ApplicationPage_OnWindowsMaximize();
  692. break;
  693. case ID_WINDOWS_CASCADE:
  694. ApplicationPage_OnWindowsCascade();
  695. break;
  696. case ID_WINDOWS_BRINGTOFRONT:
  697. ApplicationPage_OnWindowsBringToFront();
  698. break;
  699. case ID_APPLICATION_PAGE_SWITCHTO:
  700. ApplicationPage_OnSwitchTo();
  701. break;
  702. case ID_APPLICATION_PAGE_ENDTASK:
  703. ApplicationPage_OnEndTask();
  704. break;
  705. case ID_APPLICATION_PAGE_GOTOPROCESS:
  706. ApplicationPage_OnGotoProcess();
  707. break;
  708. case ID_PROCESS_PAGE_ENDPROCESS:
  709. ProcessPage_OnEndProcess();
  710. break;
  711. case ID_PROCESS_PAGE_ENDPROCESSTREE:
  712. ProcessPage_OnEndProcessTree();
  713. break;
  714. case ID_PROCESS_PAGE_DEBUG:
  715. ProcessPage_OnDebug();
  716. break;
  717. case ID_PROCESS_PAGE_SETAFFINITY:
  718. ProcessPage_OnSetAffinity();
  719. break;
  720. case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
  721. ProcessPage_OnSetPriorityRealTime();
  722. break;
  723. case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
  724. ProcessPage_OnSetPriorityHigh();
  725. break;
  726. case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
  727. ProcessPage_OnSetPriorityAboveNormal();
  728. break;
  729. case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
  730. ProcessPage_OnSetPriorityNormal();
  731. break;
  732. case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
  733. ProcessPage_OnSetPriorityBelowNormal();
  734. break;
  735. case ID_PROCESS_PAGE_SETPRIORITY_LOW:
  736. ProcessPage_OnSetPriorityLow();
  737. break;
  738. case ID_PROCESS_PAGE_DEBUGCHANNELS:
  739. ProcessPage_OnDebugChannels();
  740. break;
  741. case ID_HELP_TOPICS:
  742. WinHelpW(hDlg, wszTaskmgr, HELP_FINDER, 0);
  743. break;
  744. case ID_HELP_ABOUT:
  745. OnAbout();
  746. break;
  747. case ID_FILE_EXIT:
  748. EndDialog(hDlg, IDOK);
  749. break;
  750. }
  751. break;
  752. case WM_ONTRAYICON:
  753. switch(lParam)
  754. {
  755. case WM_RBUTTONDOWN:
  756. {
  757. POINT pt;
  758. BOOL OnTop;
  759. HMENU hMenu, hPopupMenu;
  760. GetCursorPos(&pt);
  761. OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
  762. hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
  763. hPopupMenu = GetSubMenu(hMenu, 0);
  764. if(IsWindowVisible(hMainWnd))
  765. {
  766. DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
  767. }
  768. else
  769. {
  770. SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
  771. }
  772. if(OnTop)
  773. {
  774. CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
  775. }
  776. SetForegroundWindow(hMainWnd);
  777. TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
  778. DestroyMenu(hMenu);
  779. break;
  780. }
  781. case WM_LBUTTONDBLCLK:
  782. TaskManager_OnRestoreMainWindow();
  783. break;
  784. }
  785. break;
  786. case WM_NOTIFY:
  787. pnmh = (LPNMHDR)lParam;
  788. if ((pnmh->hwndFrom == hTabWnd) &&
  789. (pnmh->idFrom == IDC_TAB) &&
  790. (pnmh->code == TCN_SELCHANGE))
  791. {
  792. TaskManager_OnTabWndSelChange();
  793. }
  794. break;
  795. case WM_NCPAINT:
  796. hdc = GetDC(hDlg);
  797. GetClientRect(hDlg, &rc);
  798. Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
  799. ReleaseDC(hDlg, hdc);
  800. break;
  801. case WM_PAINT:
  802. hdc = BeginPaint(hDlg, &ps);
  803. GetClientRect(hDlg, &rc);
  804. Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
  805. EndPaint(hDlg, &ps);
  806. break;
  807. case WM_SIZING:
  808. /* Make sure the user is sizing the dialog */
  809. /* in an acceptable range */
  810. pRC = (LPRECT)lParam;
  811. if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
  812. /* If the width is too small enlarge it to the minimum */
  813. if (nMinimumWidth > (pRC->right - pRC->left))
  814. pRC->left = pRC->right - nMinimumWidth;
  815. } else {
  816. /* If the width is too small enlarge it to the minimum */
  817. if (nMinimumWidth > (pRC->right - pRC->left))
  818. pRC->right = pRC->left + nMinimumWidth;
  819. }
  820. if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
  821. /* If the height is too small enlarge it to the minimum */
  822. if (nMinimumHeight > (pRC->bottom - pRC->top))
  823. pRC->top = pRC->bottom - nMinimumHeight;
  824. } else {
  825. /* If the height is too small enlarge it to the minimum */
  826. if (nMinimumHeight > (pRC->bottom - pRC->top))
  827. pRC->bottom = pRC->top + nMinimumHeight;
  828. }
  829. return TRUE;
  830. case WM_SIZE:
  831. /* Handle the window sizing in its own function */
  832. OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
  833. break;
  834. case WM_DESTROY:
  835. ShowWindow(hDlg, SW_HIDE);
  836. TrayIcon_ShellRemoveTrayIcon();
  837. wp.length = sizeof(WINDOWPLACEMENT);
  838. GetWindowPlacement(hDlg, &wp);
  839. TaskManagerSettings.Left = wp.rcNormalPosition.left;
  840. TaskManagerSettings.Top = wp.rcNormalPosition.top;
  841. TaskManagerSettings.Right = wp.rcNormalPosition.right;
  842. TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
  843. if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
  844. TaskManagerSettings.Maximized = TRUE;
  845. else
  846. TaskManagerSettings.Maximized = FALSE;
  847. return DefWindowProcW(hDlg, message, wParam, lParam);
  848. case WM_TIMER:
  849. /* Refresh the performance data */
  850. PerfDataRefresh();
  851. RefreshApplicationPage();
  852. RefreshProcessPage();
  853. RefreshPerformancePage();
  854. TrayIcon_ShellUpdateTrayIcon();
  855. break;
  856. case WM_ENTERMENULOOP:
  857. TaskManager_OnEnterMenuLoop(hDlg);
  858. break;
  859. case WM_EXITMENULOOP:
  860. TaskManager_OnExitMenuLoop(hDlg);
  861. break;
  862. case WM_MENUSELECT:
  863. TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
  864. break;
  865. }
  866. return 0;
  867. }
  868. int APIENTRY WinMain(HINSTANCE hInstance,
  869. HINSTANCE hPrevInstance,
  870. LPSTR lpCmdLine,
  871. int nCmdShow)
  872. {
  873. HANDLE hProcess;
  874. HANDLE hToken;
  875. TOKEN_PRIVILEGES tkp;
  876. InitCommonControls();
  877. /* Initialize global variables */
  878. hInst = hInstance;
  879. /* Change our priority class to HIGH */
  880. hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
  881. SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
  882. CloseHandle(hProcess);
  883. /* Now let's get the SE_DEBUG_NAME privilege
  884. * so that we can debug processes
  885. */
  886. /* Get a token for this process. */
  887. if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
  888. static const WCHAR SeDebugPrivilegeW[] = {'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0};
  889. /* Get the LUID for the debug privilege. */
  890. LookupPrivilegeValueW(NULL, SeDebugPrivilegeW, &tkp.Privileges[0].Luid);
  891. tkp.PrivilegeCount = 1; /* one privilege to set */
  892. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  893. /* Get the debug privilege for this process. */
  894. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
  895. }
  896. /* Load our settings from the registry */
  897. LoadSettings();
  898. /* Initialize perf data */
  899. if (!PerfDataInitialize()) {
  900. return -1;
  901. }
  902. DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
  903. /* Save our settings to the registry */
  904. SaveSettings();
  905. return 0;
  906. }