4 * taskmgr.c : Defines the entry point for the application.
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * Copyright (C) 2008 Vladimir Pankratov
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.
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.
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
24 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
32 #include "wine/unicode.h"
38 #define STATUS_WINDOW 2001
40 /* Global Variables: */
41 HINSTANCE hInst; /* current instance */
43 HWND hMainWnd; /* Main Window */
44 HWND hStatusWnd; /* Status Bar Window */
45 HWND hTabWnd; /* Tab Control Window */
47 int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */
48 int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */
50 int nOldWidth; /* Holds the previous client area width */
51 int nOldHeight; /* Holds the previous client area height */
53 BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
55 TASKMANAGER_SETTINGS TaskManagerSettings;
58 void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
61 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
64 static void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
73 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
76 static void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
78 FillSolidRect2(hDC, x, y, cx - 1, 1, clrTopLeft);
79 FillSolidRect2(hDC, x, y, 1, cy - 1, clrTopLeft);
80 FillSolidRect2(hDC, x + cx, y, -1, cy, clrBottomRight);
81 FillSolidRect2(hDC, x, y + cy, cx, -1, clrBottomRight);
84 void Font_DrawText(HDC hDC, LPWSTR lpwszText, int x, int y)
91 hFontDC = CreateCompatibleDC(hDC);
92 hFontBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FONT));
93 hOldBitmap = SelectObject(hFontDC, hFontBitmap);
95 for (i = 0; lpwszText[i]; i++) {
96 if ((lpwszText[i] >= '0') && (lpwszText[i] <= '9')) {
97 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpwszText[i] - '0') * 8, 0, SRCCOPY);
99 else if (lpwszText[i] == 'K')
101 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
103 else if (lpwszText[i] == '%')
105 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
108 SelectObject(hFontDC, hOldBitmap);
109 DeleteObject(hFontBitmap);
113 static BOOL OnCreate(HWND hWnd)
118 HMENU hUpdateSpeedMenu;
119 HMENU hCPUHistoryMenu;
125 static WCHAR wszApplications[255];
126 static WCHAR wszProcesses[255];
127 static WCHAR wszPerformance[255];
129 LoadStringW(hInst, IDS_APPLICATIONS, wszApplications, sizeof(wszApplications)/sizeof(WCHAR));
130 LoadStringW(hInst, IDS_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR));
131 LoadStringW(hInst, IDS_PERFORMANCE, wszPerformance, sizeof(wszPerformance)/sizeof(WCHAR));
133 SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER)));
134 SendMessageW(hMainWnd, WM_SETICON, ICON_SMALL,
135 (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER), IMAGE_ICON,
136 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
139 /* Initialize the Windows Common Controls DLL */
140 InitCommonControls();
142 /* Get the minimum window sizes */
143 GetWindowRect(hWnd, &rc);
144 nMinimumWidth = (rc.right - rc.left);
145 nMinimumHeight = (rc.bottom - rc.top);
147 /* Create the status bar */
148 hStatusWnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, NULL, hWnd, STATUS_WINDOW);
152 /* Create the status bar panes */
156 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
158 /* Create tab pages */
159 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
161 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hWnd, ApplicationPageWndProc);
162 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hWnd, ProcessPageWndProc);
163 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hWnd, PerformancePageWndProc);
165 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hTabWnd, ApplicationPageWndProc);
166 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hTabWnd, ProcessPageWndProc);
167 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hTabWnd, PerformancePageWndProc);
171 memset(&item, 0, sizeof(TCITEMW));
172 item.mask = TCIF_TEXT;
173 item.pszText = wszApplications;
174 SendMessageW(hTabWnd, TCM_INSERTITEMW, 0, (LPARAM)&item);
175 memset(&item, 0, sizeof(TCITEMW));
176 item.mask = TCIF_TEXT;
177 item.pszText = wszProcesses;
178 SendMessageW(hTabWnd, TCM_INSERTITEMW, 1, (LPARAM)&item);
179 memset(&item, 0, sizeof(TCITEMW));
180 item.mask = TCIF_TEXT;
181 item.pszText = wszPerformance;
182 SendMessageW(hTabWnd, TCM_INSERTITEMW, 2, (LPARAM)&item);
184 /* Size everything correctly */
185 GetClientRect(hWnd, &rc);
186 nOldWidth = rc.right;
187 nOldHeight = rc.bottom;
188 /* nOldStartX = rc.left; */
189 /*nOldStartY = rc.top; */
191 #define PAGE_OFFSET_LEFT 17
192 #define PAGE_OFFSET_TOP 72
193 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
194 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
196 if ((TaskManagerSettings.Left != 0) ||
197 (TaskManagerSettings.Top != 0) ||
198 (TaskManagerSettings.Right != 0) ||
199 (TaskManagerSettings.Bottom != 0))
201 MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE);
202 #ifdef __GNUC__TEST__
203 MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
204 MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
205 MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
208 if (TaskManagerSettings.Maximized)
209 ShowWindow(hWnd, SW_MAXIMIZE);
211 /* Set the always on top style */
212 hMenu = GetMenu(hWnd);
213 hEditMenu = GetSubMenu(hMenu, 1);
214 hViewMenu = GetSubMenu(hMenu, 2);
215 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
216 hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
218 /* Check or uncheck the always on top menu item */
219 if (TaskManagerSettings.AlwaysOnTop) {
220 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED);
221 SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
223 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
224 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
227 /* Check or uncheck the minimize on use menu item */
228 if (TaskManagerSettings.MinimizeOnUse)
229 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
231 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
233 /* Check or uncheck the hide when minimized menu item */
234 if (TaskManagerSettings.HideWhenMinimized)
235 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
237 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
239 /* Check or uncheck the show 16-bit tasks menu item */
240 if (TaskManagerSettings.Show16BitTasks)
241 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
243 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
245 if (TaskManagerSettings.View_LargeIcons)
246 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
247 else if (TaskManagerSettings.View_SmallIcons)
248 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
250 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
252 if (TaskManagerSettings.ShowKernelTimes)
253 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
255 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
257 if (TaskManagerSettings.UpdateSpeed == 1)
258 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
259 else if (TaskManagerSettings.UpdateSpeed == 2)
260 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
261 else if (TaskManagerSettings.UpdateSpeed == 4)
262 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
264 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
266 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
267 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
269 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
271 nActivePage = TaskManagerSettings.ActiveTabPage;
272 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0);
273 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1);
274 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2);
275 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage);
277 if (TaskManagerSettings.UpdateSpeed == 1)
278 SetTimer(hWnd, 1, 1000, NULL);
279 else if (TaskManagerSettings.UpdateSpeed == 2)
280 SetTimer(hWnd, 1, 2000, NULL);
281 else if (TaskManagerSettings.UpdateSpeed == 4)
282 SetTimer(hWnd, 1, 4000, NULL);
285 * Refresh the performance data
286 * Sample it twice so we can establish
287 * the delta values & cpu usage
292 RefreshApplicationPage();
293 RefreshProcessPage();
294 RefreshPerformancePage();
296 TrayIcon_ShellAddTrayIcon();
302 * This function handles all the moving events for the application
303 * It moves every child window that needs moving
305 static void OnMove( UINT nType, int cx, int cy )
307 #ifdef __GNUC__TEST__
308 MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
309 MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
310 MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
315 * This function handles all the sizing events for the application
316 * It re-sizes every window, and child window that needs re-sizing
318 static void OnSize( UINT nType, int cx, int cy )
325 if (nType == SIZE_MINIMIZED)
327 if(TaskManagerSettings.HideWhenMinimized)
329 ShowWindow(hMainWnd, SW_HIDE);
334 nXDifference = cx - nOldWidth;
335 nYDifference = cy - nOldHeight;
339 /* Update the status bar size */
340 GetWindowRect(hStatusWnd, &rc);
341 SendMessageW(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
343 /* Update the status bar pane sizes */
344 nParts[0] = bInMenuLoop ? -1 : 100;
347 SendMessageW(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (LPARAM)nParts);
349 /* Resize the tab control */
350 GetWindowRect(hTabWnd, &rc);
351 cx = (rc.right - rc.left) + nXDifference;
352 cy = (rc.bottom - rc.top) + nYDifference;
353 SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
355 /* Resize the application page */
356 GetWindowRect(hApplicationPage, &rc);
357 cx = (rc.right - rc.left) + nXDifference;
358 cy = (rc.bottom - rc.top) + nYDifference;
359 SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
361 /* Resize the process page */
362 GetWindowRect(hProcessPage, &rc);
363 cx = (rc.right - rc.left) + nXDifference;
364 cy = (rc.bottom - rc.top) + nYDifference;
365 SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
367 /* Resize the performance page */
368 GetWindowRect(hPerformancePage, &rc);
369 cx = (rc.right - rc.left) + nXDifference;
370 cy = (rc.bottom - rc.top) + nYDifference;
371 SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
374 static void LoadSettings(void)
380 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
381 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
382 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
384 /* Window size & position settings */
385 TaskManagerSettings.Maximized = FALSE;
386 TaskManagerSettings.Left = 0;
387 TaskManagerSettings.Top = 0;
388 TaskManagerSettings.Right = 0;
389 TaskManagerSettings.Bottom = 0;
392 TaskManagerSettings.ActiveTabPage = 0;
394 /* Options menu settings */
395 TaskManagerSettings.AlwaysOnTop = FALSE;
396 TaskManagerSettings.MinimizeOnUse = TRUE;
397 TaskManagerSettings.HideWhenMinimized = TRUE;
398 TaskManagerSettings.Show16BitTasks = TRUE;
400 /* Update speed settings */
401 TaskManagerSettings.UpdateSpeed = 2;
403 /* Applications page settings */
404 TaskManagerSettings.View_LargeIcons = FALSE;
405 TaskManagerSettings.View_SmallIcons = FALSE;
406 TaskManagerSettings.View_Details = TRUE;
408 /* Processes page settings */
409 TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */
410 TaskManagerSettings.Column_ImageName = TRUE;
411 TaskManagerSettings.Column_PID = TRUE;
412 TaskManagerSettings.Column_CPUUsage = TRUE;
413 TaskManagerSettings.Column_CPUTime = TRUE;
414 TaskManagerSettings.Column_MemoryUsage = TRUE;
415 TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
416 TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
417 TaskManagerSettings.Column_PageFaults = FALSE;
418 TaskManagerSettings.Column_USERObjects = FALSE;
419 TaskManagerSettings.Column_IOReads = FALSE;
420 TaskManagerSettings.Column_IOReadBytes = FALSE;
421 TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */
422 TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */
423 TaskManagerSettings.Column_PageFaultsDelta = FALSE;
424 TaskManagerSettings.Column_VirtualMemorySize = FALSE;
425 TaskManagerSettings.Column_PagedPool = FALSE;
426 TaskManagerSettings.Column_NonPagedPool = FALSE;
427 TaskManagerSettings.Column_BasePriority = FALSE;
428 TaskManagerSettings.Column_HandleCount = FALSE;
429 TaskManagerSettings.Column_ThreadCount = FALSE;
430 TaskManagerSettings.Column_GDIObjects = FALSE;
431 TaskManagerSettings.Column_IOWrites = FALSE;
432 TaskManagerSettings.Column_IOWriteBytes = FALSE;
433 TaskManagerSettings.Column_IOOther = FALSE;
434 TaskManagerSettings.Column_IOOtherBytes = FALSE;
436 for (i = 0; i < 25; i++) {
437 TaskManagerSettings.ColumnOrderArray[i] = i;
439 TaskManagerSettings.ColumnSizeArray[0] = 105;
440 TaskManagerSettings.ColumnSizeArray[1] = 50;
441 TaskManagerSettings.ColumnSizeArray[2] = 107;
442 TaskManagerSettings.ColumnSizeArray[3] = 70;
443 TaskManagerSettings.ColumnSizeArray[4] = 35;
444 TaskManagerSettings.ColumnSizeArray[5] = 70;
445 TaskManagerSettings.ColumnSizeArray[6] = 70;
446 TaskManagerSettings.ColumnSizeArray[7] = 100;
447 TaskManagerSettings.ColumnSizeArray[8] = 70;
448 TaskManagerSettings.ColumnSizeArray[9] = 70;
449 TaskManagerSettings.ColumnSizeArray[10] = 70;
450 TaskManagerSettings.ColumnSizeArray[11] = 70;
451 TaskManagerSettings.ColumnSizeArray[12] = 70;
452 TaskManagerSettings.ColumnSizeArray[13] = 70;
453 TaskManagerSettings.ColumnSizeArray[14] = 60;
454 TaskManagerSettings.ColumnSizeArray[15] = 60;
455 TaskManagerSettings.ColumnSizeArray[16] = 60;
456 TaskManagerSettings.ColumnSizeArray[17] = 60;
457 TaskManagerSettings.ColumnSizeArray[18] = 60;
458 TaskManagerSettings.ColumnSizeArray[19] = 70;
459 TaskManagerSettings.ColumnSizeArray[20] = 70;
460 TaskManagerSettings.ColumnSizeArray[21] = 70;
461 TaskManagerSettings.ColumnSizeArray[22] = 70;
462 TaskManagerSettings.ColumnSizeArray[23] = 70;
463 TaskManagerSettings.ColumnSizeArray[24] = 70;
465 TaskManagerSettings.SortColumn = 1;
466 TaskManagerSettings.SortAscending = TRUE;
468 /* Performance page settings */
469 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
470 TaskManagerSettings.ShowKernelTimes = FALSE;
473 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
474 if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
476 /* Read the settings */
477 dwSize = sizeof(TASKMANAGER_SETTINGS);
478 RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
484 static void SaveSettings(void)
488 static const WCHAR wszSubKey3[] = {'S','o','f','t','w','a','r','e','\\',
489 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
490 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
492 /* Open (or create) the key */
494 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
495 if (RegCreateKeyExW(HKEY_CURRENT_USER, wszSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
497 /* Save the settings */
498 RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
503 static void TaskManager_OnRestoreMainWindow(void)
507 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
510 SetForegroundWindow(hMainWnd);
511 SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
514 static void TaskManager_OnEnterMenuLoop(HWND hWnd)
518 /* Update the status bar pane sizes */
520 SendMessageW(hStatusWnd, SB_SETPARTS, 1, (LPARAM)&nParts);
522 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
525 static void TaskManager_OnExitMenuLoop(HWND hWnd)
531 WCHAR wszCPU_Usage[255];
532 WCHAR wszProcesses[255];
534 LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
535 LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR));
538 /* Update the status bar pane sizes */
539 GetClientRect(hWnd, &rc);
542 nParts[2] = rc.right;
543 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
544 SendMessageW(hStatusWnd, SB_SETTEXT, 0, 0);
545 wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage());
546 SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text);
547 wsprintfW(text, wszProcesses, PerfDataGetProcessCount());
548 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text);
551 static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
553 WCHAR wstr[256] = {0};
555 LoadStringW(hInst, nItemID, wstr, sizeof(wstr)/sizeof(WCHAR));
556 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)wstr);
559 static void TaskManager_OnViewUpdateSpeedHigh(void)
563 HMENU hUpdateSpeedMenu;
565 hMenu = GetMenu(hMainWnd);
566 hViewMenu = GetSubMenu(hMenu, 2);
567 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
569 TaskManagerSettings.UpdateSpeed = 1;
570 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
572 KillTimer(hMainWnd, 1);
573 SetTimer(hMainWnd, 1, 1000, NULL);
576 static void TaskManager_OnViewUpdateSpeedNormal(void)
580 HMENU hUpdateSpeedMenu;
582 hMenu = GetMenu(hMainWnd);
583 hViewMenu = GetSubMenu(hMenu, 2);
584 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
586 TaskManagerSettings.UpdateSpeed = 2;
587 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
589 KillTimer(hMainWnd, 1);
590 SetTimer(hMainWnd, 1, 2000, NULL);
593 static void TaskManager_OnViewUpdateSpeedLow(void)
597 HMENU hUpdateSpeedMenu;
599 hMenu = GetMenu(hMainWnd);
600 hViewMenu = GetSubMenu(hMenu, 2);
601 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
603 TaskManagerSettings.UpdateSpeed = 4;
604 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
606 KillTimer(hMainWnd, 1);
607 SetTimer(hMainWnd, 1, 4000, NULL);
610 static void TaskManager_OnViewUpdateSpeedPaused(void)
614 HMENU hUpdateSpeedMenu;
616 hMenu = GetMenu(hMainWnd);
617 hViewMenu = GetSubMenu(hMenu, 2);
618 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
619 TaskManagerSettings.UpdateSpeed = 0;
620 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
621 KillTimer(hMainWnd, 1);
624 static void TaskManager_OnTabWndSelChange(void)
632 WCHAR wszLargeIcons[255];
633 WCHAR wszSmallIcons[255];
634 WCHAR wszDetails[255];
635 WCHAR wszWindows[255];
636 WCHAR wszSelectColumns[255];
637 WCHAR wszShow16bTasks[255];
638 WCHAR wszOneGraphAllCPU[255];
639 WCHAR wszOneGraphPerCPU[255];
640 WCHAR wszCPUHistory[255];
641 WCHAR wszShowKernelTimes[255];
643 LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, sizeof(wszLargeIcons)/sizeof(WCHAR));
644 LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, sizeof(wszSmallIcons)/sizeof(WCHAR));
645 LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, sizeof(wszDetails)/sizeof(WCHAR));
646 LoadStringW(hInst, IDS_WINDOWS, wszWindows, sizeof(wszWindows)/sizeof(WCHAR));
647 LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, sizeof(wszSelectColumns)/sizeof(WCHAR));
648 LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, sizeof(wszShow16bTasks)/sizeof(WCHAR));
649 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, sizeof(wszOneGraphAllCPU)/sizeof(WCHAR));
650 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, sizeof(wszOneGraphPerCPU)/sizeof(WCHAR));
651 LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, sizeof(wszCPUHistory)/sizeof(WCHAR));
652 LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, sizeof(wszShowKernelTimes)/sizeof(WCHAR));
654 hMenu = GetMenu(hMainWnd);
655 hViewMenu = GetSubMenu(hMenu, 2);
656 hOptionsMenu = GetSubMenu(hMenu, 1);
657 TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
658 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
659 hSubMenu = GetSubMenu(hViewMenu, i);
661 DestroyMenu(hSubMenu);
662 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
664 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
665 switch (TaskManagerSettings.ActiveTabPage) {
667 ShowWindow(hApplicationPage, SW_SHOW);
668 ShowWindow(hProcessPage, SW_HIDE);
669 ShowWindow(hPerformancePage, SW_HIDE);
670 BringWindowToTop(hApplicationPage);
671 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
672 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
673 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);
675 if (GetMenuItemCount(hMenu) <= 4) {
676 hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
677 InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
678 DrawMenuBar(hMainWnd);
680 if (TaskManagerSettings.View_LargeIcons)
681 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
682 else if (TaskManagerSettings.View_SmallIcons)
683 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
685 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
687 * Give the application list control focus
689 SetFocus(hApplicationPageListCtrl);
693 ShowWindow(hApplicationPage, SW_HIDE);
694 ShowWindow(hProcessPage, SW_SHOW);
695 ShowWindow(hPerformancePage, SW_HIDE);
696 BringWindowToTop(hProcessPage);
697 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
698 AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
699 if (TaskManagerSettings.Show16BitTasks)
700 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
701 if (GetMenuItemCount(hMenu) > 4)
703 RemoveMenu(hMenu, 3, MF_BYPOSITION);
704 DrawMenuBar(hMainWnd);
707 * Give the process list control focus
709 SetFocus(hProcessPageListCtrl);
713 ShowWindow(hApplicationPage, SW_HIDE);
714 ShowWindow(hProcessPage, SW_HIDE);
715 ShowWindow(hPerformancePage, SW_SHOW);
716 BringWindowToTop(hPerformancePage);
717 if (GetMenuItemCount(hMenu) > 4) {
718 RemoveMenu(hMenu, 3, MF_BYPOSITION);
719 DrawMenuBar(hMainWnd);
721 hSubMenu = CreatePopupMenu();
722 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
723 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
724 AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
725 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
726 if (TaskManagerSettings.ShowKernelTimes)
727 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
729 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
730 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
731 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
733 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
735 * Give the tab control focus
742 LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
745 LPWSTR lpwszTemp = NULL;
746 static const WCHAR wszFormat[] = {'%','s',' ','(','%','u',')',0};
748 dwRet = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
756 /* supplied buffer is not long enough */
757 if (!dwRet || ( dwSize < dwRet+14)) {
760 lpwszTemp[strlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
761 sprintfW(lpwszBuf, wszFormat, lpwszTemp, GetLastError());
764 LocalFree(lpwszTemp);
769 /* Message handler for dialog box. */
770 static INT_PTR CALLBACK
771 TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
773 static const WCHAR wszTaskmgr[] = {'t','a','s','k','m','g','r',0};
784 return OnCreate(hDlg);
787 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
788 EndDialog(hDlg, LOWORD(wParam));
791 /* Process menu commands */
792 switch (LOWORD(wParam))
795 TaskManager_OnFileNew();
797 case ID_OPTIONS_ALWAYSONTOP:
798 TaskManager_OnOptionsAlwaysOnTop();
800 case ID_OPTIONS_MINIMIZEONUSE:
801 TaskManager_OnOptionsMinimizeOnUse();
803 case ID_OPTIONS_HIDEWHENMINIMIZED:
804 TaskManager_OnOptionsHideWhenMinimized();
806 case ID_OPTIONS_SHOW16BITTASKS:
807 TaskManager_OnOptionsShow16BitTasks();
810 TaskManager_OnRestoreMainWindow();
813 ApplicationPage_OnViewLargeIcons();
816 ApplicationPage_OnViewSmallIcons();
818 case ID_VIEW_DETAILS:
819 ApplicationPage_OnViewDetails();
821 case ID_VIEW_SHOWKERNELTIMES:
822 PerformancePage_OnViewShowKernelTimes();
824 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
825 PerformancePage_OnViewCPUHistoryOneGraphAll();
827 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
828 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
830 case ID_VIEW_UPDATESPEED_HIGH:
831 TaskManager_OnViewUpdateSpeedHigh();
833 case ID_VIEW_UPDATESPEED_NORMAL:
834 TaskManager_OnViewUpdateSpeedNormal();
836 case ID_VIEW_UPDATESPEED_LOW:
837 TaskManager_OnViewUpdateSpeedLow();
839 case ID_VIEW_UPDATESPEED_PAUSED:
840 TaskManager_OnViewUpdateSpeedPaused();
842 case ID_VIEW_SELECTCOLUMNS:
843 ProcessPage_OnViewSelectColumns();
845 case ID_VIEW_REFRESH:
846 PostMessage(hDlg, WM_TIMER, 0, 0);
848 case ID_WINDOWS_TILEHORIZONTALLY:
849 ApplicationPage_OnWindowsTileHorizontally();
851 case ID_WINDOWS_TILEVERTICALLY:
852 ApplicationPage_OnWindowsTileVertically();
854 case ID_WINDOWS_MINIMIZE:
855 ApplicationPage_OnWindowsMinimize();
857 case ID_WINDOWS_MAXIMIZE:
858 ApplicationPage_OnWindowsMaximize();
860 case ID_WINDOWS_CASCADE:
861 ApplicationPage_OnWindowsCascade();
863 case ID_WINDOWS_BRINGTOFRONT:
864 ApplicationPage_OnWindowsBringToFront();
866 case ID_APPLICATION_PAGE_SWITCHTO:
867 ApplicationPage_OnSwitchTo();
869 case ID_APPLICATION_PAGE_ENDTASK:
870 ApplicationPage_OnEndTask();
872 case ID_APPLICATION_PAGE_GOTOPROCESS:
873 ApplicationPage_OnGotoProcess();
875 case ID_PROCESS_PAGE_ENDPROCESS:
876 ProcessPage_OnEndProcess();
878 case ID_PROCESS_PAGE_ENDPROCESSTREE:
879 ProcessPage_OnEndProcessTree();
881 case ID_PROCESS_PAGE_DEBUG:
882 ProcessPage_OnDebug();
884 case ID_PROCESS_PAGE_SETAFFINITY:
885 ProcessPage_OnSetAffinity();
887 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
888 ProcessPage_OnSetPriorityRealTime();
890 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
891 ProcessPage_OnSetPriorityHigh();
893 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
894 ProcessPage_OnSetPriorityAboveNormal();
896 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
897 ProcessPage_OnSetPriorityNormal();
899 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
900 ProcessPage_OnSetPriorityBelowNormal();
902 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
903 ProcessPage_OnSetPriorityLow();
905 case ID_PROCESS_PAGE_DEBUGCHANNELS:
906 ProcessPage_OnDebugChannels();
909 WinHelpW(hDlg, wszTaskmgr, HELP_FINDER, 0);
915 EndDialog(hDlg, IDOK);
927 HMENU hMenu, hPopupMenu;
931 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
933 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
934 hPopupMenu = GetSubMenu(hMenu, 0);
936 if(IsWindowVisible(hMainWnd))
938 DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
942 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
947 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
950 SetForegroundWindow(hMainWnd);
951 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
956 case WM_LBUTTONDBLCLK:
957 TaskManager_OnRestoreMainWindow();
963 pnmh = (LPNMHDR)lParam;
964 if ((pnmh->hwndFrom == hTabWnd) &&
965 (pnmh->idFrom == IDC_TAB) &&
966 (pnmh->code == TCN_SELCHANGE))
968 TaskManager_OnTabWndSelChange();
974 GetClientRect(hDlg, &rc);
975 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
976 ReleaseDC(hDlg, hdc);
980 hdc = BeginPaint(hDlg, &ps);
981 GetClientRect(hDlg, &rc);
982 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
987 /* Make sure the user is sizing the dialog */
988 /* in an acceptable range */
989 pRC = (LPRECT)lParam;
990 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
991 /* If the width is too small enlarge it to the minimum */
992 if (nMinimumWidth > (pRC->right - pRC->left))
993 pRC->left = pRC->right - nMinimumWidth;
995 /* If the width is too small enlarge it to the minimum */
996 if (nMinimumWidth > (pRC->right - pRC->left))
997 pRC->right = pRC->left + nMinimumWidth;
999 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
1000 /* If the height is too small enlarge it to the minimum */
1001 if (nMinimumHeight > (pRC->bottom - pRC->top))
1002 pRC->top = pRC->bottom - nMinimumHeight;
1004 /* If the height is too small enlarge it to the minimum */
1005 if (nMinimumHeight > (pRC->bottom - pRC->top))
1006 pRC->bottom = pRC->top + nMinimumHeight;
1011 /* Handle the window sizing in it's own function */
1012 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
1016 /* Handle the window moving in it's own function */
1017 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
1021 ShowWindow(hDlg, SW_HIDE);
1022 TrayIcon_ShellRemoveTrayIcon();
1023 wp.length = sizeof(WINDOWPLACEMENT);
1024 GetWindowPlacement(hDlg, &wp);
1025 TaskManagerSettings.Left = wp.rcNormalPosition.left;
1026 TaskManagerSettings.Top = wp.rcNormalPosition.top;
1027 TaskManagerSettings.Right = wp.rcNormalPosition.right;
1028 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
1029 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
1030 TaskManagerSettings.Maximized = TRUE;
1032 TaskManagerSettings.Maximized = FALSE;
1033 return DefWindowProc(hDlg, message, wParam, lParam);
1036 /* Refresh the performance data */
1038 RefreshApplicationPage();
1039 RefreshProcessPage();
1040 RefreshPerformancePage();
1041 TrayIcon_ShellUpdateTrayIcon();
1044 case WM_ENTERMENULOOP:
1045 TaskManager_OnEnterMenuLoop(hDlg);
1047 case WM_EXITMENULOOP:
1048 TaskManager_OnExitMenuLoop(hDlg);
1051 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
1058 int APIENTRY WinMain(HINSTANCE hInstance,
1059 HINSTANCE hPrevInstance,
1065 TOKEN_PRIVILEGES tkp;
1067 /* Initialize global variables */
1070 /* Change our priority class to HIGH */
1071 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
1072 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
1073 CloseHandle(hProcess);
1075 /* Now let's get the SE_DEBUG_NAME privilege
1076 * so that we can debug processes
1079 /* Get a token for this process. */
1080 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
1081 /* Get the LUID for the debug privilege. */
1082 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
1084 tkp.PrivilegeCount = 1; /* one privilege to set */
1085 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1087 /* Get the debug privilege for this process. */
1088 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
1091 /* Load our settings from the registry */
1094 /* Initialize perf data */
1095 if (!PerfDataInitialize()) {
1099 DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
1101 /* Save our settings to the registry */
1103 PerfDataUninitialize();