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
36 #define STATUS_WINDOW 2001
38 /* Global Variables: */
39 HINSTANCE hInst
; /* current instance */
41 HWND hMainWnd
; /* Main Window */
42 HWND hStatusWnd
; /* Status Bar Window */
43 HWND hTabWnd
; /* Tab Control Window */
45 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
46 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
48 int nOldWidth
; /* Holds the previous client area width */
49 int nOldHeight
; /* Holds the previous client area height */
51 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
53 TASKMANAGER_SETTINGS TaskManagerSettings
;
56 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
59 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
62 static void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
67 SetRect(&rect
, x
, y
, x
+ cx
, y
+ cy
);
68 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
71 static void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
73 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
74 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
75 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
76 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
79 static BOOL
OnCreate(HWND hWnd
)
84 HMENU hUpdateSpeedMenu
;
85 HMENU hCPUHistoryMenu
;
91 static WCHAR wszApplications
[255];
92 static WCHAR wszProcesses
[255];
93 static WCHAR wszPerformance
[255];
95 LoadStringW(hInst
, IDS_APPLICATIONS
, wszApplications
, ARRAY_SIZE(wszApplications
));
96 LoadStringW(hInst
, IDS_PROCESSES
, wszProcesses
, ARRAY_SIZE(wszProcesses
));
97 LoadStringW(hInst
, IDS_PERFORMANCE
, wszPerformance
, ARRAY_SIZE(wszPerformance
));
99 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
100 SendMessageW(hMainWnd
, WM_SETICON
, ICON_SMALL
,
101 (LPARAM
)LoadImageW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
), IMAGE_ICON
,
102 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
105 /* Initialize the Windows Common Controls DLL */
106 InitCommonControls();
108 /* Get the minimum window sizes */
109 GetWindowRect(hWnd
, &rc
);
110 nMinimumWidth
= (rc
.right
- rc
.left
);
111 nMinimumHeight
= (rc
.bottom
- rc
.top
);
113 /* Create the status bar */
114 hStatusWnd
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, NULL
, hWnd
, STATUS_WINDOW
);
118 /* Create the status bar panes */
122 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
124 /* Create tab pages */
125 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
127 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
128 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
129 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
131 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
132 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
133 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
137 memset(&item
, 0, sizeof(TCITEMW
));
138 item
.mask
= TCIF_TEXT
;
139 item
.pszText
= wszApplications
;
140 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 0, (LPARAM
)&item
);
141 memset(&item
, 0, sizeof(TCITEMW
));
142 item
.mask
= TCIF_TEXT
;
143 item
.pszText
= wszProcesses
;
144 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 1, (LPARAM
)&item
);
145 memset(&item
, 0, sizeof(TCITEMW
));
146 item
.mask
= TCIF_TEXT
;
147 item
.pszText
= wszPerformance
;
148 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 2, (LPARAM
)&item
);
150 /* Size everything correctly */
151 GetClientRect(hWnd
, &rc
);
152 nOldWidth
= rc
.right
;
153 nOldHeight
= rc
.bottom
;
155 if ((TaskManagerSettings
.Left
!= 0) ||
156 (TaskManagerSettings
.Top
!= 0) ||
157 (TaskManagerSettings
.Right
!= 0) ||
158 (TaskManagerSettings
.Bottom
!= 0))
159 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
161 if (TaskManagerSettings
.Maximized
)
162 ShowWindow(hWnd
, SW_MAXIMIZE
);
164 /* Set the always on top style */
165 hMenu
= GetMenu(hWnd
);
166 hEditMenu
= GetSubMenu(hMenu
, 1);
167 hViewMenu
= GetSubMenu(hMenu
, 2);
168 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
169 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
171 /* Check or uncheck the always on top menu item */
172 if (TaskManagerSettings
.AlwaysOnTop
) {
173 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
174 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
176 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
177 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
180 /* Check or uncheck the minimize on use menu item */
181 if (TaskManagerSettings
.MinimizeOnUse
)
182 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
184 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
186 /* Check or uncheck the hide when minimized menu item */
187 if (TaskManagerSettings
.HideWhenMinimized
)
188 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
190 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
192 /* Check or uncheck the show 16-bit tasks menu item */
193 if (TaskManagerSettings
.Show16BitTasks
)
194 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
196 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
198 if (TaskManagerSettings
.View_LargeIcons
)
199 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
200 else if (TaskManagerSettings
.View_SmallIcons
)
201 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
203 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
205 if (TaskManagerSettings
.ShowKernelTimes
)
206 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
208 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
210 if (TaskManagerSettings
.UpdateSpeed
== 1)
211 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
212 else if (TaskManagerSettings
.UpdateSpeed
== 2)
213 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
214 else if (TaskManagerSettings
.UpdateSpeed
== 4)
215 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
217 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
219 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
220 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
222 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
224 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
225 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 0, 0);
226 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 1, 0);
227 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 2, 0);
228 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, nActivePage
, 0);
230 if (TaskManagerSettings
.UpdateSpeed
== 1)
231 SetTimer(hWnd
, 1, 1000, NULL
);
232 else if (TaskManagerSettings
.UpdateSpeed
== 2)
233 SetTimer(hWnd
, 1, 2000, NULL
);
234 else if (TaskManagerSettings
.UpdateSpeed
== 4)
235 SetTimer(hWnd
, 1, 4000, NULL
);
238 * Refresh the performance data
239 * Sample it twice so we can establish
240 * the delta values & cpu usage
245 RefreshApplicationPage();
246 RefreshProcessPage();
247 RefreshPerformancePage();
249 TrayIcon_ShellAddTrayIcon();
255 * This function handles all the sizing events for the application
256 * It re-sizes every window, and child window that needs re-sizing
258 static void OnSize( UINT nType
, int cx
, int cy
)
265 if (nType
== SIZE_MINIMIZED
)
267 if(TaskManagerSettings
.HideWhenMinimized
)
269 ShowWindow(hMainWnd
, SW_HIDE
);
274 nXDifference
= cx
- nOldWidth
;
275 nYDifference
= cy
- nOldHeight
;
279 /* Update the status bar size */
280 GetWindowRect(hStatusWnd
, &rc
);
281 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
283 /* Update the status bar pane sizes */
284 nParts
[0] = bInMenuLoop
? -1 : 100;
287 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
)nParts
);
289 /* Resize the tab control */
290 GetWindowRect(hTabWnd
, &rc
);
291 cx
= (rc
.right
- rc
.left
) + nXDifference
;
292 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
293 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
295 /* Resize the application page */
296 GetWindowRect(hApplicationPage
, &rc
);
297 cx
= (rc
.right
- rc
.left
) + nXDifference
;
298 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
299 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
301 /* Resize the process page */
302 GetWindowRect(hProcessPage
, &rc
);
303 cx
= (rc
.right
- rc
.left
) + nXDifference
;
304 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
305 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
307 /* Resize the performance page */
308 GetWindowRect(hPerformancePage
, &rc
);
309 cx
= (rc
.right
- rc
.left
) + nXDifference
;
310 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
311 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
314 static void LoadSettings(void)
320 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
321 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
322 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
324 /* Window size & position settings */
325 TaskManagerSettings
.Maximized
= FALSE
;
326 TaskManagerSettings
.Left
= 0;
327 TaskManagerSettings
.Top
= 0;
328 TaskManagerSettings
.Right
= 0;
329 TaskManagerSettings
.Bottom
= 0;
332 TaskManagerSettings
.ActiveTabPage
= 0;
334 /* Options menu settings */
335 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
336 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
337 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
338 TaskManagerSettings
.Show16BitTasks
= TRUE
;
340 /* Update speed settings */
341 TaskManagerSettings
.UpdateSpeed
= 2;
343 /* Applications page settings */
344 TaskManagerSettings
.View_LargeIcons
= FALSE
;
345 TaskManagerSettings
.View_SmallIcons
= FALSE
;
346 TaskManagerSettings
.View_Details
= TRUE
;
348 /* Processes page settings */
349 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
350 TaskManagerSettings
.Column_ImageName
= TRUE
;
351 TaskManagerSettings
.Column_PID
= TRUE
;
352 TaskManagerSettings
.Column_CPUUsage
= TRUE
;
353 TaskManagerSettings
.Column_CPUTime
= TRUE
;
354 TaskManagerSettings
.Column_MemoryUsage
= TRUE
;
355 TaskManagerSettings
.Column_MemoryUsageDelta
= FALSE
;
356 TaskManagerSettings
.Column_PeakMemoryUsage
= FALSE
;
357 TaskManagerSettings
.Column_PageFaults
= FALSE
;
358 TaskManagerSettings
.Column_USERObjects
= FALSE
;
359 TaskManagerSettings
.Column_IOReads
= FALSE
;
360 TaskManagerSettings
.Column_IOReadBytes
= FALSE
;
361 TaskManagerSettings
.Column_SessionID
= FALSE
; /* Server-only? */
362 TaskManagerSettings
.Column_UserName
= FALSE
; /* Server-only? */
363 TaskManagerSettings
.Column_PageFaultsDelta
= FALSE
;
364 TaskManagerSettings
.Column_VirtualMemorySize
= FALSE
;
365 TaskManagerSettings
.Column_PagedPool
= FALSE
;
366 TaskManagerSettings
.Column_NonPagedPool
= FALSE
;
367 TaskManagerSettings
.Column_BasePriority
= FALSE
;
368 TaskManagerSettings
.Column_HandleCount
= FALSE
;
369 TaskManagerSettings
.Column_ThreadCount
= FALSE
;
370 TaskManagerSettings
.Column_GDIObjects
= FALSE
;
371 TaskManagerSettings
.Column_IOWrites
= FALSE
;
372 TaskManagerSettings
.Column_IOWriteBytes
= FALSE
;
373 TaskManagerSettings
.Column_IOOther
= FALSE
;
374 TaskManagerSettings
.Column_IOOtherBytes
= FALSE
;
376 for (i
= 0; i
< 25; i
++) {
377 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
379 TaskManagerSettings
.ColumnSizeArray
[0] = 105;
380 TaskManagerSettings
.ColumnSizeArray
[1] = 50;
381 TaskManagerSettings
.ColumnSizeArray
[2] = 107;
382 TaskManagerSettings
.ColumnSizeArray
[3] = 70;
383 TaskManagerSettings
.ColumnSizeArray
[4] = 35;
384 TaskManagerSettings
.ColumnSizeArray
[5] = 70;
385 TaskManagerSettings
.ColumnSizeArray
[6] = 70;
386 TaskManagerSettings
.ColumnSizeArray
[7] = 100;
387 TaskManagerSettings
.ColumnSizeArray
[8] = 70;
388 TaskManagerSettings
.ColumnSizeArray
[9] = 70;
389 TaskManagerSettings
.ColumnSizeArray
[10] = 70;
390 TaskManagerSettings
.ColumnSizeArray
[11] = 70;
391 TaskManagerSettings
.ColumnSizeArray
[12] = 70;
392 TaskManagerSettings
.ColumnSizeArray
[13] = 70;
393 TaskManagerSettings
.ColumnSizeArray
[14] = 60;
394 TaskManagerSettings
.ColumnSizeArray
[15] = 60;
395 TaskManagerSettings
.ColumnSizeArray
[16] = 60;
396 TaskManagerSettings
.ColumnSizeArray
[17] = 60;
397 TaskManagerSettings
.ColumnSizeArray
[18] = 60;
398 TaskManagerSettings
.ColumnSizeArray
[19] = 70;
399 TaskManagerSettings
.ColumnSizeArray
[20] = 70;
400 TaskManagerSettings
.ColumnSizeArray
[21] = 70;
401 TaskManagerSettings
.ColumnSizeArray
[22] = 70;
402 TaskManagerSettings
.ColumnSizeArray
[23] = 70;
403 TaskManagerSettings
.ColumnSizeArray
[24] = 70;
405 TaskManagerSettings
.SortColumn
= 1;
406 TaskManagerSettings
.SortAscending
= TRUE
;
408 /* Performance page settings */
409 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
410 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
413 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
414 if (RegOpenKeyExW(HKEY_CURRENT_USER
, wszSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
416 /* Read the settings */
417 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
418 RegQueryValueExW(hKey
, wszPreferences
, NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
424 static void SaveSettings(void)
428 static const WCHAR wszSubKey3
[] = {'S','o','f','t','w','a','r','e','\\',
429 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
430 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
432 /* Open (or create) the key */
434 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
435 if (RegCreateKeyExW(HKEY_CURRENT_USER
, wszSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
437 /* Save the settings */
438 RegSetValueExW(hKey
, wszPreferences
, 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
443 static void TaskManager_OnRestoreMainWindow(void)
447 OnTop
= (GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
450 SetForegroundWindow(hMainWnd
);
451 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
454 static void TaskManager_OnEnterMenuLoop(HWND hWnd
)
458 /* Update the status bar pane sizes */
460 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
462 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
465 static void TaskManager_OnExitMenuLoop(HWND hWnd
)
471 WCHAR wszCPU_Usage
[255];
472 WCHAR wszProcesses
[255];
474 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, ARRAY_SIZE(wszCPU_Usage
));
475 LoadStringW(hInst
, IDS_STATUS_BAR_PROCESSES
, wszProcesses
, ARRAY_SIZE(wszProcesses
));
478 /* Update the status bar pane sizes */
479 GetClientRect(hWnd
, &rc
);
482 nParts
[2] = rc
.right
;
483 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
484 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
485 wsprintfW(text
, wszCPU_Usage
, PerfDataGetProcessorUsage());
486 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 1, (LPARAM
)text
);
487 wsprintfW(text
, wszProcesses
, PerfDataGetProcessCount());
488 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)text
);
491 static void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
493 WCHAR wstr
[256] = {0};
495 LoadStringW(hInst
, nItemID
, wstr
, ARRAY_SIZE(wstr
));
496 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)wstr
);
499 static void TaskManager_OnViewUpdateSpeedHigh(void)
503 HMENU hUpdateSpeedMenu
;
505 hMenu
= GetMenu(hMainWnd
);
506 hViewMenu
= GetSubMenu(hMenu
, 2);
507 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
509 TaskManagerSettings
.UpdateSpeed
= 1;
510 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
512 KillTimer(hMainWnd
, 1);
513 SetTimer(hMainWnd
, 1, 1000, NULL
);
516 static void TaskManager_OnViewUpdateSpeedNormal(void)
520 HMENU hUpdateSpeedMenu
;
522 hMenu
= GetMenu(hMainWnd
);
523 hViewMenu
= GetSubMenu(hMenu
, 2);
524 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
526 TaskManagerSettings
.UpdateSpeed
= 2;
527 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
529 KillTimer(hMainWnd
, 1);
530 SetTimer(hMainWnd
, 1, 2000, NULL
);
533 static void TaskManager_OnViewUpdateSpeedLow(void)
537 HMENU hUpdateSpeedMenu
;
539 hMenu
= GetMenu(hMainWnd
);
540 hViewMenu
= GetSubMenu(hMenu
, 2);
541 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
543 TaskManagerSettings
.UpdateSpeed
= 4;
544 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
546 KillTimer(hMainWnd
, 1);
547 SetTimer(hMainWnd
, 1, 4000, NULL
);
550 static void TaskManager_OnViewUpdateSpeedPaused(void)
554 HMENU hUpdateSpeedMenu
;
556 hMenu
= GetMenu(hMainWnd
);
557 hViewMenu
= GetSubMenu(hMenu
, 2);
558 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
559 TaskManagerSettings
.UpdateSpeed
= 0;
560 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
561 KillTimer(hMainWnd
, 1);
564 static void TaskManager_OnTabWndSelChange(void)
572 WCHAR wszLargeIcons
[255];
573 WCHAR wszSmallIcons
[255];
574 WCHAR wszDetails
[255];
575 WCHAR wszWindows
[255];
576 WCHAR wszSelectColumns
[255];
577 WCHAR wszShow16bTasks
[255];
578 WCHAR wszOneGraphAllCPU
[255];
579 WCHAR wszOneGraphPerCPU
[255];
580 WCHAR wszCPUHistory
[255];
581 WCHAR wszShowKernelTimes
[255];
583 LoadStringW(hInst
, IDS_VIEW_LARGE
, wszLargeIcons
, ARRAY_SIZE(wszLargeIcons
));
584 LoadStringW(hInst
, IDS_VIEW_SMALL
, wszSmallIcons
, ARRAY_SIZE(wszSmallIcons
));
585 LoadStringW(hInst
, IDS_VIEW_DETAILS
, wszDetails
, ARRAY_SIZE(wszDetails
));
586 LoadStringW(hInst
, IDS_WINDOWS
, wszWindows
, ARRAY_SIZE(wszWindows
));
587 LoadStringW(hInst
, IDS_VIEW_SELECTCOLUMNS
, wszSelectColumns
, ARRAY_SIZE(wszSelectColumns
));
588 LoadStringW(hInst
, IDS_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
, ARRAY_SIZE(wszShow16bTasks
));
589 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
, ARRAY_SIZE(wszOneGraphAllCPU
));
590 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
, ARRAY_SIZE(wszOneGraphPerCPU
));
591 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY
, wszCPUHistory
, ARRAY_SIZE(wszCPUHistory
));
592 LoadStringW(hInst
, IDS_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
, ARRAY_SIZE(wszShowKernelTimes
));
594 hMenu
= GetMenu(hMainWnd
);
595 hViewMenu
= GetSubMenu(hMenu
, 2);
596 hOptionsMenu
= GetSubMenu(hMenu
, 1);
597 TaskManagerSettings
.ActiveTabPage
= SendMessageW(hTabWnd
, TCM_GETCURSEL
, 0, 0);
598 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
599 hSubMenu
= GetSubMenu(hViewMenu
, i
);
601 DestroyMenu(hSubMenu
);
602 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
604 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
605 switch (TaskManagerSettings
.ActiveTabPage
) {
607 ShowWindow(hApplicationPage
, SW_SHOW
);
608 ShowWindow(hProcessPage
, SW_HIDE
);
609 ShowWindow(hPerformancePage
, SW_HIDE
);
610 BringWindowToTop(hApplicationPage
);
611 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, wszLargeIcons
);
612 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, wszSmallIcons
);
613 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, wszDetails
);
615 if (GetMenuItemCount(hMenu
) <= 4) {
616 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
617 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszWindows
);
618 DrawMenuBar(hMainWnd
);
620 if (TaskManagerSettings
.View_LargeIcons
)
621 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
622 else if (TaskManagerSettings
.View_SmallIcons
)
623 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
625 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
627 * Give the application list control focus
629 SetFocus(hApplicationPageListCtrl
);
633 ShowWindow(hApplicationPage
, SW_HIDE
);
634 ShowWindow(hProcessPage
, SW_SHOW
);
635 ShowWindow(hPerformancePage
, SW_HIDE
);
636 BringWindowToTop(hProcessPage
);
637 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, wszSelectColumns
);
638 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
);
639 if (TaskManagerSettings
.Show16BitTasks
)
640 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
641 if (GetMenuItemCount(hMenu
) > 4)
643 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
644 DrawMenuBar(hMainWnd
);
647 * Give the process list control focus
649 SetFocus(hProcessPageListCtrl
);
653 ShowWindow(hApplicationPage
, SW_HIDE
);
654 ShowWindow(hProcessPage
, SW_HIDE
);
655 ShowWindow(hPerformancePage
, SW_SHOW
);
656 BringWindowToTop(hPerformancePage
);
657 if (GetMenuItemCount(hMenu
) > 4) {
658 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
659 DrawMenuBar(hMainWnd
);
661 hSubMenu
= CreatePopupMenu();
662 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
);
663 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
);
664 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszCPUHistory
);
665 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
);
666 if (TaskManagerSettings
.ShowKernelTimes
)
667 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
669 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
670 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
671 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
673 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
675 * Give the tab control focus
682 LPWSTR
GetLastErrorText(LPWSTR lpwszBuf
, DWORD dwSize
)
685 LPWSTR lpwszTemp
= NULL
;
686 static const WCHAR wszFormat
[] = {'%','s',' ','(','%','u',')',0};
688 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
696 /* supplied buffer is not long enough */
697 if (!dwRet
|| ( dwSize
< dwRet
+14)) {
700 lpwszTemp
[lstrlenW(lpwszTemp
)-2] = '\0'; /* remove cr and newline character */
701 swprintf(lpwszBuf
, dwSize
, wszFormat
, lpwszTemp
, GetLastError());
704 LocalFree(lpwszTemp
);
709 /* Message handler for dialog box. */
710 static INT_PTR CALLBACK
711 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
713 static const WCHAR wszTaskmgr
[] = {'t','a','s','k','m','g','r',0};
724 return OnCreate(hDlg
);
727 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
728 EndDialog(hDlg
, LOWORD(wParam
));
731 /* Process menu commands */
732 switch (LOWORD(wParam
))
735 TaskManager_OnFileNew();
737 case ID_OPTIONS_ALWAYSONTOP
:
738 TaskManager_OnOptionsAlwaysOnTop();
740 case ID_OPTIONS_MINIMIZEONUSE
:
741 TaskManager_OnOptionsMinimizeOnUse();
743 case ID_OPTIONS_HIDEWHENMINIMIZED
:
744 TaskManager_OnOptionsHideWhenMinimized();
746 case ID_OPTIONS_SHOW16BITTASKS
:
747 TaskManager_OnOptionsShow16BitTasks();
750 TaskManager_OnRestoreMainWindow();
753 ApplicationPage_OnViewLargeIcons();
756 ApplicationPage_OnViewSmallIcons();
758 case ID_VIEW_DETAILS
:
759 ApplicationPage_OnViewDetails();
761 case ID_VIEW_SHOWKERNELTIMES
:
762 PerformancePage_OnViewShowKernelTimes();
764 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
765 PerformancePage_OnViewCPUHistoryOneGraphAll();
767 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
768 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
770 case ID_VIEW_UPDATESPEED_HIGH
:
771 TaskManager_OnViewUpdateSpeedHigh();
773 case ID_VIEW_UPDATESPEED_NORMAL
:
774 TaskManager_OnViewUpdateSpeedNormal();
776 case ID_VIEW_UPDATESPEED_LOW
:
777 TaskManager_OnViewUpdateSpeedLow();
779 case ID_VIEW_UPDATESPEED_PAUSED
:
780 TaskManager_OnViewUpdateSpeedPaused();
782 case ID_VIEW_SELECTCOLUMNS
:
783 ProcessPage_OnViewSelectColumns();
785 case ID_VIEW_REFRESH
:
786 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
788 case ID_WINDOWS_TILEHORIZONTALLY
:
789 ApplicationPage_OnWindowsTileHorizontally();
791 case ID_WINDOWS_TILEVERTICALLY
:
792 ApplicationPage_OnWindowsTileVertically();
794 case ID_WINDOWS_MINIMIZE
:
795 ApplicationPage_OnWindowsMinimize();
797 case ID_WINDOWS_MAXIMIZE
:
798 ApplicationPage_OnWindowsMaximize();
800 case ID_WINDOWS_CASCADE
:
801 ApplicationPage_OnWindowsCascade();
803 case ID_WINDOWS_BRINGTOFRONT
:
804 ApplicationPage_OnWindowsBringToFront();
806 case ID_APPLICATION_PAGE_SWITCHTO
:
807 ApplicationPage_OnSwitchTo();
809 case ID_APPLICATION_PAGE_ENDTASK
:
810 ApplicationPage_OnEndTask();
812 case ID_APPLICATION_PAGE_GOTOPROCESS
:
813 ApplicationPage_OnGotoProcess();
815 case ID_PROCESS_PAGE_ENDPROCESS
:
816 ProcessPage_OnEndProcess();
818 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
819 ProcessPage_OnEndProcessTree();
821 case ID_PROCESS_PAGE_DEBUG
:
822 ProcessPage_OnDebug();
824 case ID_PROCESS_PAGE_SETAFFINITY
:
825 ProcessPage_OnSetAffinity();
827 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
828 ProcessPage_OnSetPriorityRealTime();
830 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
831 ProcessPage_OnSetPriorityHigh();
833 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
834 ProcessPage_OnSetPriorityAboveNormal();
836 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
837 ProcessPage_OnSetPriorityNormal();
839 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
840 ProcessPage_OnSetPriorityBelowNormal();
842 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
843 ProcessPage_OnSetPriorityLow();
845 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
846 ProcessPage_OnDebugChannels();
849 WinHelpW(hDlg
, wszTaskmgr
, HELP_FINDER
, 0);
855 EndDialog(hDlg
, IDOK
);
867 HMENU hMenu
, hPopupMenu
;
871 OnTop
= (GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
873 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
874 hPopupMenu
= GetSubMenu(hMenu
, 0);
876 if(IsWindowVisible(hMainWnd
))
878 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
882 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
887 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
890 SetForegroundWindow(hMainWnd
);
891 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
896 case WM_LBUTTONDBLCLK
:
897 TaskManager_OnRestoreMainWindow();
903 pnmh
= (LPNMHDR
)lParam
;
904 if ((pnmh
->hwndFrom
== hTabWnd
) &&
905 (pnmh
->idFrom
== IDC_TAB
) &&
906 (pnmh
->code
== TCN_SELCHANGE
))
908 TaskManager_OnTabWndSelChange();
914 GetClientRect(hDlg
, &rc
);
915 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
916 ReleaseDC(hDlg
, hdc
);
920 hdc
= BeginPaint(hDlg
, &ps
);
921 GetClientRect(hDlg
, &rc
);
922 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
927 /* Make sure the user is sizing the dialog */
928 /* in an acceptable range */
929 pRC
= (LPRECT
)lParam
;
930 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
931 /* If the width is too small enlarge it to the minimum */
932 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
933 pRC
->left
= pRC
->right
- nMinimumWidth
;
935 /* If the width is too small enlarge it to the minimum */
936 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
937 pRC
->right
= pRC
->left
+ nMinimumWidth
;
939 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
940 /* If the height is too small enlarge it to the minimum */
941 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
942 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
944 /* If the height is too small enlarge it to the minimum */
945 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
946 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
951 /* Handle the window sizing in its own function */
952 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
956 ShowWindow(hDlg
, SW_HIDE
);
957 TrayIcon_ShellRemoveTrayIcon();
958 wp
.length
= sizeof(WINDOWPLACEMENT
);
959 GetWindowPlacement(hDlg
, &wp
);
960 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
961 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
962 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
963 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
964 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
965 TaskManagerSettings
.Maximized
= TRUE
;
967 TaskManagerSettings
.Maximized
= FALSE
;
968 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
971 /* Refresh the performance data */
973 RefreshApplicationPage();
974 RefreshProcessPage();
975 RefreshPerformancePage();
976 TrayIcon_ShellUpdateTrayIcon();
979 case WM_ENTERMENULOOP
:
980 TaskManager_OnEnterMenuLoop(hDlg
);
982 case WM_EXITMENULOOP
:
983 TaskManager_OnExitMenuLoop(hDlg
);
986 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
993 int APIENTRY
WinMain(HINSTANCE hInstance
,
994 HINSTANCE hPrevInstance
,
1000 TOKEN_PRIVILEGES tkp
;
1002 InitCommonControls();
1004 /* Initialize global variables */
1007 /* Change our priority class to HIGH */
1008 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
1009 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
1010 CloseHandle(hProcess
);
1012 /* Now let's get the SE_DEBUG_NAME privilege
1013 * so that we can debug processes
1016 /* Get a token for this process. */
1017 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
1018 static const WCHAR SeDebugPrivilegeW
[] = {'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0};
1020 /* Get the LUID for the debug privilege. */
1021 LookupPrivilegeValueW(NULL
, SeDebugPrivilegeW
, &tkp
.Privileges
[0].Luid
);
1023 tkp
.PrivilegeCount
= 1; /* one privilege to set */
1024 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1026 /* Get the debug privilege for this process. */
1027 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, NULL
, 0);
1030 /* Load our settings from the registry */
1033 /* Initialize perf data */
1034 if (!PerfDataInitialize()) {
1038 DialogBoxW(hInst
, (LPWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
1040 /* Save our settings to the registry */