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 */
33 #include "wine/unicode.h"
39 #define STATUS_WINDOW 2001
41 /* Global Variables: */
42 HINSTANCE hInst; /* current instance */
44 HWND hMainWnd; /* Main Window */
45 HWND hStatusWnd; /* Status Bar Window */
46 HWND hTabWnd; /* Tab Control Window */
48 int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */
49 int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */
51 int nOldWidth; /* Holds the previous client area width */
52 int nOldHeight; /* Holds the previous client area height */
54 BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
56 TASKMANAGER_SETTINGS TaskManagerSettings;
59 void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
62 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
65 void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
74 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
77 void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
79 FillSolidRect2(hDC, x, y, cx - 1, 1, clrTopLeft);
80 FillSolidRect2(hDC, x, y, 1, cy - 1, clrTopLeft);
81 FillSolidRect2(hDC, x + cx, y, -1, cy, clrBottomRight);
82 FillSolidRect2(hDC, x, y + cy, cx, -1, clrBottomRight);
85 void Draw3dRect2(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight)
87 Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left,
88 lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight);
91 void Font_DrawText(HDC hDC, LPWSTR lpwszText, int x, int y)
98 hFontDC = CreateCompatibleDC(hDC);
99 hFontBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FONT));
100 hOldBitmap = (HBITMAP)SelectObject(hFontDC, hFontBitmap);
102 for (i = 0; lpwszText[i]; i++) {
103 if ((lpwszText[i] >= '0') && (lpwszText[i] <= '9')) {
104 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpwszText[i] - '0') * 8, 0, SRCCOPY);
106 else if (lpwszText[i] == 'K')
108 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
110 else if (lpwszText[i] == '%')
112 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
115 SelectObject(hFontDC, hOldBitmap);
116 DeleteObject(hFontBitmap);
120 static BOOL OnCreate(HWND hWnd)
125 HMENU hUpdateSpeedMenu;
126 HMENU hCPUHistoryMenu;
132 static WCHAR wszApplications[] = {'A','p','p','l','i','c','a','t','i','o','n','s',0};
133 static WCHAR wszProcesses[] = {'P','r','o','c','e','s','s','e','s',0};
134 static WCHAR wszPerformance[] = {'P','e','r','f','o','r','m','a','n','c','e',0};
136 SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER)));
138 /* Initialize the Windows Common Controls DLL */
139 InitCommonControls();
141 /* Get the minimum window sizes */
142 GetWindowRect(hWnd, &rc);
143 nMinimumWidth = (rc.right - rc.left);
144 nMinimumHeight = (rc.bottom - rc.top);
146 /* Create the status bar */
147 hStatusWnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, NULL, hWnd, STATUS_WINDOW);
151 /* Create the status bar panes */
155 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
157 /* Create tab pages */
158 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
160 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hWnd, ApplicationPageWndProc);
161 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hWnd, ProcessPageWndProc);
162 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hWnd, PerformancePageWndProc);
164 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hTabWnd, ApplicationPageWndProc);
165 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hTabWnd, ProcessPageWndProc);
166 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hTabWnd, PerformancePageWndProc);
170 memset(&item, 0, sizeof(TCITEMW));
171 item.mask = TCIF_TEXT;
172 item.pszText = wszApplications;
173 SendMessageW(hTabWnd, TCM_INSERTITEMW, 0, (LPARAM)&item);
174 memset(&item, 0, sizeof(TCITEMW));
175 item.mask = TCIF_TEXT;
176 item.pszText = wszProcesses;
177 SendMessageW(hTabWnd, TCM_INSERTITEMW, 1, (LPARAM)&item);
178 memset(&item, 0, sizeof(TCITEMW));
179 item.mask = TCIF_TEXT;
180 item.pszText = wszPerformance;
181 SendMessageW(hTabWnd, TCM_INSERTITEMW, 2, (LPARAM)&item);
183 /* Size everything correctly */
184 GetClientRect(hWnd, &rc);
185 nOldWidth = rc.right;
186 nOldHeight = rc.bottom;
187 /* nOldStartX = rc.left; */
188 /*nOldStartY = rc.top; */
190 #define PAGE_OFFSET_LEFT 17
191 #define PAGE_OFFSET_TOP 72
192 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
193 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
195 if ((TaskManagerSettings.Left != 0) ||
196 (TaskManagerSettings.Top != 0) ||
197 (TaskManagerSettings.Right != 0) ||
198 (TaskManagerSettings.Bottom != 0))
200 MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE);
201 #ifdef __GNUC__TEST__
202 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);
203 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);
204 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);
207 if (TaskManagerSettings.Maximized)
208 ShowWindow(hWnd, SW_MAXIMIZE);
210 /* Set the always on top style */
211 hMenu = GetMenu(hWnd);
212 hEditMenu = GetSubMenu(hMenu, 1);
213 hViewMenu = GetSubMenu(hMenu, 2);
214 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
215 hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
217 /* Check or uncheck the always on top menu item */
218 if (TaskManagerSettings.AlwaysOnTop) {
219 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED);
220 SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
222 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
223 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
226 /* Check or uncheck the minimize on use menu item */
227 if (TaskManagerSettings.MinimizeOnUse)
228 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
230 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
232 /* Check or uncheck the hide when minimized menu item */
233 if (TaskManagerSettings.HideWhenMinimized)
234 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
236 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
238 /* Check or uncheck the show 16-bit tasks menu item */
239 if (TaskManagerSettings.Show16BitTasks)
240 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
242 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
244 if (TaskManagerSettings.View_LargeIcons)
245 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
246 else if (TaskManagerSettings.View_SmallIcons)
247 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
249 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
251 if (TaskManagerSettings.ShowKernelTimes)
252 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
254 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
256 if (TaskManagerSettings.UpdateSpeed == 1)
257 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
258 else if (TaskManagerSettings.UpdateSpeed == 2)
259 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
260 else if (TaskManagerSettings.UpdateSpeed == 4)
261 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
263 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
265 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
266 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
268 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
270 nActivePage = TaskManagerSettings.ActiveTabPage;
271 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0);
272 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1);
273 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2);
274 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage);
276 if (TaskManagerSettings.UpdateSpeed == 1)
277 SetTimer(hWnd, 1, 1000, NULL);
278 else if (TaskManagerSettings.UpdateSpeed == 2)
279 SetTimer(hWnd, 1, 2000, NULL);
280 else if (TaskManagerSettings.UpdateSpeed == 4)
281 SetTimer(hWnd, 1, 4000, NULL);
284 * Refresh the performance data
285 * Sample it twice so we can establish
286 * the delta values & cpu usage
291 RefreshApplicationPage();
292 RefreshProcessPage();
293 RefreshPerformancePage();
295 TrayIcon_ShellAddTrayIcon();
301 * This function handles all the moving events for the application
302 * It moves every child window that needs moving
304 static void OnMove( UINT nType, int cx, int cy )
306 #ifdef __GNUC__TEST__
307 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);
308 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);
309 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);
314 * This function handles all the sizing events for the application
315 * It re-sizes every window, and child window that needs re-sizing
317 static void OnSize( UINT nType, int cx, int cy )
324 if (nType == SIZE_MINIMIZED)
326 if(TaskManagerSettings.HideWhenMinimized)
328 ShowWindow(hMainWnd, SW_HIDE);
333 nXDifference = cx - nOldWidth;
334 nYDifference = cy - nOldHeight;
338 /* Update the status bar size */
339 GetWindowRect(hStatusWnd, &rc);
340 SendMessageW(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
342 /* Update the status bar pane sizes */
343 nParts[0] = bInMenuLoop ? -1 : 100;
346 SendMessageW(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (LPARAM)nParts);
348 /* Resize the tab control */
349 GetWindowRect(hTabWnd, &rc);
350 cx = (rc.right - rc.left) + nXDifference;
351 cy = (rc.bottom - rc.top) + nYDifference;
352 SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
354 /* Resize the application page */
355 GetWindowRect(hApplicationPage, &rc);
356 cx = (rc.right - rc.left) + nXDifference;
357 cy = (rc.bottom - rc.top) + nYDifference;
358 SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
360 /* Resize the process page */
361 GetWindowRect(hProcessPage, &rc);
362 cx = (rc.right - rc.left) + nXDifference;
363 cy = (rc.bottom - rc.top) + nYDifference;
364 SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
366 /* Resize the performance page */
367 GetWindowRect(hPerformancePage, &rc);
368 cx = (rc.right - rc.left) + nXDifference;
369 cy = (rc.bottom - rc.top) + nYDifference;
370 SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
373 static void LoadSettings(void)
379 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
380 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
381 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
383 /* Window size & position settings */
384 TaskManagerSettings.Maximized = FALSE;
385 TaskManagerSettings.Left = 0;
386 TaskManagerSettings.Top = 0;
387 TaskManagerSettings.Right = 0;
388 TaskManagerSettings.Bottom = 0;
391 TaskManagerSettings.ActiveTabPage = 0;
393 /* Options menu settings */
394 TaskManagerSettings.AlwaysOnTop = FALSE;
395 TaskManagerSettings.MinimizeOnUse = TRUE;
396 TaskManagerSettings.HideWhenMinimized = TRUE;
397 TaskManagerSettings.Show16BitTasks = TRUE;
399 /* Update speed settings */
400 TaskManagerSettings.UpdateSpeed = 2;
402 /* Applications page settings */
403 TaskManagerSettings.View_LargeIcons = FALSE;
404 TaskManagerSettings.View_SmallIcons = FALSE;
405 TaskManagerSettings.View_Details = TRUE;
407 /* Processes page settings */
408 TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */
409 TaskManagerSettings.Column_ImageName = TRUE;
410 TaskManagerSettings.Column_PID = TRUE;
411 TaskManagerSettings.Column_CPUUsage = TRUE;
412 TaskManagerSettings.Column_CPUTime = TRUE;
413 TaskManagerSettings.Column_MemoryUsage = TRUE;
414 TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
415 TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
416 TaskManagerSettings.Column_PageFaults = FALSE;
417 TaskManagerSettings.Column_USERObjects = FALSE;
418 TaskManagerSettings.Column_IOReads = FALSE;
419 TaskManagerSettings.Column_IOReadBytes = FALSE;
420 TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */
421 TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */
422 TaskManagerSettings.Column_PageFaultsDelta = FALSE;
423 TaskManagerSettings.Column_VirtualMemorySize = FALSE;
424 TaskManagerSettings.Column_PagedPool = FALSE;
425 TaskManagerSettings.Column_NonPagedPool = FALSE;
426 TaskManagerSettings.Column_BasePriority = FALSE;
427 TaskManagerSettings.Column_HandleCount = FALSE;
428 TaskManagerSettings.Column_ThreadCount = FALSE;
429 TaskManagerSettings.Column_GDIObjects = FALSE;
430 TaskManagerSettings.Column_IOWrites = FALSE;
431 TaskManagerSettings.Column_IOWriteBytes = FALSE;
432 TaskManagerSettings.Column_IOOther = FALSE;
433 TaskManagerSettings.Column_IOOtherBytes = FALSE;
435 for (i = 0; i < 25; i++) {
436 TaskManagerSettings.ColumnOrderArray[i] = i;
438 TaskManagerSettings.ColumnSizeArray[0] = 105;
439 TaskManagerSettings.ColumnSizeArray[1] = 50;
440 TaskManagerSettings.ColumnSizeArray[2] = 107;
441 TaskManagerSettings.ColumnSizeArray[3] = 70;
442 TaskManagerSettings.ColumnSizeArray[4] = 35;
443 TaskManagerSettings.ColumnSizeArray[5] = 70;
444 TaskManagerSettings.ColumnSizeArray[6] = 70;
445 TaskManagerSettings.ColumnSizeArray[7] = 100;
446 TaskManagerSettings.ColumnSizeArray[8] = 70;
447 TaskManagerSettings.ColumnSizeArray[9] = 70;
448 TaskManagerSettings.ColumnSizeArray[10] = 70;
449 TaskManagerSettings.ColumnSizeArray[11] = 70;
450 TaskManagerSettings.ColumnSizeArray[12] = 70;
451 TaskManagerSettings.ColumnSizeArray[13] = 70;
452 TaskManagerSettings.ColumnSizeArray[14] = 60;
453 TaskManagerSettings.ColumnSizeArray[15] = 60;
454 TaskManagerSettings.ColumnSizeArray[16] = 60;
455 TaskManagerSettings.ColumnSizeArray[17] = 60;
456 TaskManagerSettings.ColumnSizeArray[18] = 60;
457 TaskManagerSettings.ColumnSizeArray[19] = 70;
458 TaskManagerSettings.ColumnSizeArray[20] = 70;
459 TaskManagerSettings.ColumnSizeArray[21] = 70;
460 TaskManagerSettings.ColumnSizeArray[22] = 70;
461 TaskManagerSettings.ColumnSizeArray[23] = 70;
462 TaskManagerSettings.ColumnSizeArray[24] = 70;
464 TaskManagerSettings.SortColumn = 1;
465 TaskManagerSettings.SortAscending = TRUE;
467 /* Performance page settings */
468 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
469 TaskManagerSettings.ShowKernelTimes = FALSE;
472 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
473 if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
475 /* Read the settings */
476 dwSize = sizeof(TASKMANAGER_SETTINGS);
477 RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
483 static void SaveSettings(void)
487 static const WCHAR wszSubKey3[] = {'S','o','f','t','w','a','r','e','\\',
488 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
489 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
491 /* Open (or create) the key */
493 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
494 if (RegCreateKeyExW(HKEY_CURRENT_USER, wszSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
496 /* Save the settings */
497 RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
502 static void TaskManager_OnRestoreMainWindow(void)
504 HMENU hMenu, hOptionsMenu;
507 hMenu = GetMenu(hMainWnd);
508 hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
509 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
512 SetForegroundWindow(hMainWnd);
513 SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
516 static void TaskManager_OnEnterMenuLoop(HWND hWnd)
520 /* Update the status bar pane sizes */
522 SendMessageW(hStatusWnd, SB_SETPARTS, 1, (long)&nParts);
524 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
527 static void TaskManager_OnExitMenuLoop(HWND hWnd)
533 static const WCHAR wszCPU_Usage[] = {'C','P','U',' ','U','s','a','g','e',':',' ','%','3','d','%','%',0};
534 static const WCHAR wszProcesses[] = {'P','r','o','c','e','s','s','e','s',':',' ','%','d',0};
537 /* Update the status bar pane sizes */
538 GetClientRect(hWnd, &rc);
541 nParts[2] = rc.right;
542 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
543 SendMessageW(hStatusWnd, SB_SETTEXT, 0, 0);
544 wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage());
545 SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text);
546 wsprintfW(text, wszProcesses, PerfDataGetProcessCount());
547 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text);
550 static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
552 WCHAR wstr[256] = {0};
554 LoadStringW(hInst, nItemID, wstr, sizeof(wstr)/sizeof(WCHAR));
555 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)wstr);
558 static void TaskManager_OnViewUpdateSpeedHigh(void)
562 HMENU hUpdateSpeedMenu;
564 hMenu = GetMenu(hMainWnd);
565 hViewMenu = GetSubMenu(hMenu, 2);
566 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
568 TaskManagerSettings.UpdateSpeed = 1;
569 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
571 KillTimer(hMainWnd, 1);
572 SetTimer(hMainWnd, 1, 1000, NULL);
575 static void TaskManager_OnViewUpdateSpeedNormal(void)
579 HMENU hUpdateSpeedMenu;
581 hMenu = GetMenu(hMainWnd);
582 hViewMenu = GetSubMenu(hMenu, 2);
583 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
585 TaskManagerSettings.UpdateSpeed = 2;
586 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
588 KillTimer(hMainWnd, 1);
589 SetTimer(hMainWnd, 1, 2000, NULL);
592 static void TaskManager_OnViewUpdateSpeedLow(void)
596 HMENU hUpdateSpeedMenu;
598 hMenu = GetMenu(hMainWnd);
599 hViewMenu = GetSubMenu(hMenu, 2);
600 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
602 TaskManagerSettings.UpdateSpeed = 4;
603 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
605 KillTimer(hMainWnd, 1);
606 SetTimer(hMainWnd, 1, 4000, NULL);
609 static void TaskManager_OnViewUpdateSpeedPaused(void)
613 HMENU hUpdateSpeedMenu;
615 hMenu = GetMenu(hMainWnd);
616 hViewMenu = GetSubMenu(hMenu, 2);
617 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
618 TaskManagerSettings.UpdateSpeed = 0;
619 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
620 KillTimer(hMainWnd, 1);
623 static void TaskManager_OnTabWndSelChange(void)
631 static const WCHAR wszLargeIcons[] = {'L','a','r','&','g','e',' ','I','c','o','n','s',0};
632 static const WCHAR wszSmallIcons[] = {'S','&','m','a','l','l',' ','I','c','o','n','s',0};
633 static const WCHAR wszDetails[] = {'&','D','e','t','a','i','l','s',0};
634 static const WCHAR wszWindows[] = {'&','W','i','n','d','o','w','s',0};
635 static const WCHAR wszSelectColumns[] = {'&','S','e','l','e','c','t',' ',
636 'C','o','l','u','m','n','s','.','.','.',0};
637 static const WCHAR wszShow16bTasks[] = {'&','S','h','o','w',' ','1','6','-','b','i','t',' ',
638 't','a','s','k','s',0};
639 static const WCHAR wszOneGraphAllCPU[] = {'&','O','n','e',' ','G','r','a','p','h',',',' ',
640 'A','l','l',' ','C','P','U','s',0};
641 static const WCHAR wszOneGraphPerCPU[] = {'O','n','e',' ','G','r','a','p','h',' ',
642 '&','P','e','r',' ','C','P','U',0};
643 static const WCHAR wszCPUHistory[] = {'&','C','P','U',' ','H','i','s','t','o','r','y',0};
644 static const WCHAR wszShowKernelTimes[] = {'&','S','h','o','w',' ','K','e','r','n','e','l',' ',
645 'T','i','m','e','s',0};
647 hMenu = GetMenu(hMainWnd);
648 hViewMenu = GetSubMenu(hMenu, 2);
649 hOptionsMenu = GetSubMenu(hMenu, 1);
650 TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
651 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
652 hSubMenu = GetSubMenu(hViewMenu, i);
654 DestroyMenu(hSubMenu);
655 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
657 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
658 switch (TaskManagerSettings.ActiveTabPage) {
660 ShowWindow(hApplicationPage, SW_SHOW);
661 ShowWindow(hProcessPage, SW_HIDE);
662 ShowWindow(hPerformancePage, SW_HIDE);
663 BringWindowToTop(hApplicationPage);
664 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
665 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
666 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);
668 if (GetMenuItemCount(hMenu) <= 4) {
669 hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
670 InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
671 DrawMenuBar(hMainWnd);
673 if (TaskManagerSettings.View_LargeIcons)
674 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
675 else if (TaskManagerSettings.View_SmallIcons)
676 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
678 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
680 * Give the application list control focus
682 SetFocus(hApplicationPageListCtrl);
686 ShowWindow(hApplicationPage, SW_HIDE);
687 ShowWindow(hProcessPage, SW_SHOW);
688 ShowWindow(hPerformancePage, SW_HIDE);
689 BringWindowToTop(hProcessPage);
690 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
691 AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
692 if (TaskManagerSettings.Show16BitTasks)
693 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
694 if (GetMenuItemCount(hMenu) > 4)
696 RemoveMenu(hMenu, 3, MF_BYPOSITION);
697 DrawMenuBar(hMainWnd);
700 * Give the process list control focus
702 SetFocus(hProcessPageListCtrl);
706 ShowWindow(hApplicationPage, SW_HIDE);
707 ShowWindow(hProcessPage, SW_HIDE);
708 ShowWindow(hPerformancePage, SW_SHOW);
709 BringWindowToTop(hPerformancePage);
710 if (GetMenuItemCount(hMenu) > 4) {
711 RemoveMenu(hMenu, 3, MF_BYPOSITION);
712 DrawMenuBar(hMainWnd);
714 hSubMenu = CreatePopupMenu();
715 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
716 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
717 AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
718 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
719 if (TaskManagerSettings.ShowKernelTimes)
720 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
722 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
723 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
724 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
726 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
728 * Give the tab control focus
735 LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
738 LPWSTR lpwszTemp = NULL;
739 static const WCHAR wszFormat[] = {'%','s',' ','(','%','u',')',0};
741 dwRet = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
749 /* supplied buffer is not long enough */
750 if (!dwRet || ( (long)dwSize < (long)dwRet+14)) {
753 lpwszTemp[strlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
754 sprintfW(lpwszBuf, wszFormat, lpwszTemp, GetLastError());
757 LocalFree((HLOCAL)lpwszTemp);
762 /* Message handler for dialog box. */
763 static INT_PTR CALLBACK
764 TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
777 return OnCreate(hDlg);
780 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
781 EndDialog(hDlg, LOWORD(wParam));
784 /* Process menu commands */
785 switch (LOWORD(wParam))
788 TaskManager_OnFileNew();
790 case ID_OPTIONS_ALWAYSONTOP:
791 TaskManager_OnOptionsAlwaysOnTop();
793 case ID_OPTIONS_MINIMIZEONUSE:
794 TaskManager_OnOptionsMinimizeOnUse();
796 case ID_OPTIONS_HIDEWHENMINIMIZED:
797 TaskManager_OnOptionsHideWhenMinimized();
799 case ID_OPTIONS_SHOW16BITTASKS:
800 TaskManager_OnOptionsShow16BitTasks();
803 TaskManager_OnRestoreMainWindow();
806 ApplicationPage_OnViewLargeIcons();
809 ApplicationPage_OnViewSmallIcons();
811 case ID_VIEW_DETAILS:
812 ApplicationPage_OnViewDetails();
814 case ID_VIEW_SHOWKERNELTIMES:
815 PerformancePage_OnViewShowKernelTimes();
817 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
818 PerformancePage_OnViewCPUHistoryOneGraphAll();
820 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
821 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
823 case ID_VIEW_UPDATESPEED_HIGH:
824 TaskManager_OnViewUpdateSpeedHigh();
826 case ID_VIEW_UPDATESPEED_NORMAL:
827 TaskManager_OnViewUpdateSpeedNormal();
829 case ID_VIEW_UPDATESPEED_LOW:
830 TaskManager_OnViewUpdateSpeedLow();
832 case ID_VIEW_UPDATESPEED_PAUSED:
833 TaskManager_OnViewUpdateSpeedPaused();
835 case ID_VIEW_SELECTCOLUMNS:
836 ProcessPage_OnViewSelectColumns();
838 case ID_VIEW_REFRESH:
839 PostMessage(hDlg, WM_TIMER, 0, 0);
841 case ID_WINDOWS_TILEHORIZONTALLY:
842 ApplicationPage_OnWindowsTileHorizontally();
844 case ID_WINDOWS_TILEVERTICALLY:
845 ApplicationPage_OnWindowsTileVertically();
847 case ID_WINDOWS_MINIMIZE:
848 ApplicationPage_OnWindowsMinimize();
850 case ID_WINDOWS_MAXIMIZE:
851 ApplicationPage_OnWindowsMaximize();
853 case ID_WINDOWS_CASCADE:
854 ApplicationPage_OnWindowsCascade();
856 case ID_WINDOWS_BRINGTOFRONT:
857 ApplicationPage_OnWindowsBringToFront();
859 case ID_APPLICATION_PAGE_SWITCHTO:
860 ApplicationPage_OnSwitchTo();
862 case ID_APPLICATION_PAGE_ENDTASK:
863 ApplicationPage_OnEndTask();
865 case ID_APPLICATION_PAGE_GOTOPROCESS:
866 ApplicationPage_OnGotoProcess();
868 case ID_PROCESS_PAGE_ENDPROCESS:
869 ProcessPage_OnEndProcess();
871 case ID_PROCESS_PAGE_ENDPROCESSTREE:
872 ProcessPage_OnEndProcessTree();
874 case ID_PROCESS_PAGE_DEBUG:
875 ProcessPage_OnDebug();
877 case ID_PROCESS_PAGE_SETAFFINITY:
878 ProcessPage_OnSetAffinity();
880 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
881 ProcessPage_OnSetPriorityRealTime();
883 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
884 ProcessPage_OnSetPriorityHigh();
886 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
887 ProcessPage_OnSetPriorityAboveNormal();
889 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
890 ProcessPage_OnSetPriorityNormal();
892 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
893 ProcessPage_OnSetPriorityBelowNormal();
895 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
896 ProcessPage_OnSetPriorityLow();
898 case ID_PROCESS_PAGE_DEBUGCHANNELS:
899 ProcessPage_OnDebugChannels();
905 EndDialog(hDlg, IDOK);
917 HMENU hMenu, hPopupMenu;
921 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
923 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
924 hPopupMenu = GetSubMenu(hMenu, 0);
926 if(IsWindowVisible(hMainWnd))
928 DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
932 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
937 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
940 SetForegroundWindow(hMainWnd);
941 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
946 case WM_LBUTTONDBLCLK:
947 TaskManager_OnRestoreMainWindow();
953 idctrl = (int)wParam;
954 pnmh = (LPNMHDR)lParam;
955 if ((pnmh->hwndFrom == hTabWnd) &&
956 (pnmh->idFrom == IDC_TAB) &&
957 (pnmh->code == TCN_SELCHANGE))
959 TaskManager_OnTabWndSelChange();
965 GetClientRect(hDlg, &rc);
966 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
967 ReleaseDC(hDlg, hdc);
971 hdc = BeginPaint(hDlg, &ps);
972 GetClientRect(hDlg, &rc);
973 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
978 /* Make sure the user is sizing the dialog */
979 /* in an acceptable range */
980 pRC = (LPRECT)lParam;
981 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
982 /* If the width is too small enlarge it to the minimum */
983 if (nMinimumWidth > (pRC->right - pRC->left))
984 pRC->left = pRC->right - nMinimumWidth;
986 /* If the width is too small enlarge it to the minimum */
987 if (nMinimumWidth > (pRC->right - pRC->left))
988 pRC->right = pRC->left + nMinimumWidth;
990 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
991 /* If the height is too small enlarge it to the minimum */
992 if (nMinimumHeight > (pRC->bottom - pRC->top))
993 pRC->top = pRC->bottom - nMinimumHeight;
995 /* If the height is too small enlarge it to the minimum */
996 if (nMinimumHeight > (pRC->bottom - pRC->top))
997 pRC->bottom = pRC->top + nMinimumHeight;
1002 /* Handle the window sizing in it's own function */
1003 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
1007 /* Handle the window moving in it's own function */
1008 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
1012 ShowWindow(hDlg, SW_HIDE);
1013 TrayIcon_ShellRemoveTrayIcon();
1014 wp.length = sizeof(WINDOWPLACEMENT);
1015 GetWindowPlacement(hDlg, &wp);
1016 TaskManagerSettings.Left = wp.rcNormalPosition.left;
1017 TaskManagerSettings.Top = wp.rcNormalPosition.top;
1018 TaskManagerSettings.Right = wp.rcNormalPosition.right;
1019 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
1020 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
1021 TaskManagerSettings.Maximized = TRUE;
1023 TaskManagerSettings.Maximized = FALSE;
1024 return DefWindowProc(hDlg, message, wParam, lParam);
1027 /* Refresh the performance data */
1029 RefreshApplicationPage();
1030 RefreshProcessPage();
1031 RefreshPerformancePage();
1032 TrayIcon_ShellUpdateTrayIcon();
1035 case WM_ENTERMENULOOP:
1036 TaskManager_OnEnterMenuLoop(hDlg);
1038 case WM_EXITMENULOOP:
1039 TaskManager_OnExitMenuLoop(hDlg);
1042 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
1049 int APIENTRY WinMain(HINSTANCE hInstance,
1050 HINSTANCE hPrevInstance,
1056 TOKEN_PRIVILEGES tkp;
1058 /* Initialize global variables */
1061 /* Change our priority class to HIGH */
1062 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
1063 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
1064 CloseHandle(hProcess);
1066 /* Now let's get the SE_DEBUG_NAME privilege
1067 * so that we can debug processes
1070 /* Get a token for this process. */
1071 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
1072 /* Get the LUID for the debug privilege. */
1073 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
1075 tkp.PrivilegeCount = 1; /* one privilege to set */
1076 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1078 /* Get the debug privilege for this process. */
1079 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
1082 /* Load our settings from the registry */
1085 /* Initialize perf data */
1086 if (!PerfDataInitialize()) {
1090 DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
1092 /* Save our settings to the registry */
1094 PerfDataUninitialize();