d2d1: Make some strings const.
[wine.git] / programs / taskmgr / taskmgr.c
blobd779e5d893ad0421a037d4abe483f17ba0afc9fd
1 /*
2 * ReactOS Task Manager
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 #include <stdio.h>
25 #include <stdlib.h>
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <winnt.h>
31 #include "resource.h"
32 #include "taskmgr.h"
33 #include "perfdata.h"
34 #include "column.h"
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)
58 SetBkColor(hDC, 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)
64 RECT rect;
66 SetBkColor(hDC, 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)
81 HMENU hMenu;
82 HMENU hEditMenu;
83 HMENU hViewMenu;
84 HMENU hUpdateSpeedMenu;
85 HMENU hCPUHistoryMenu;
86 int nActivePage;
87 int nParts[3];
88 RECT rc;
89 TCITEMW item;
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),
103 LR_SHARED));
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);
115 if(!hStatusWnd)
116 return FALSE;
118 /* Create the status bar panes */
119 nParts[0] = 100;
120 nParts[1] = 210;
121 nParts[2] = 400;
122 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
124 /* Create tab pages */
125 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
126 #if 1
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);
130 #else
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);
134 #endif
136 /* Insert tabs */
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);
175 } else {
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);
183 else
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);
189 else
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);
195 else
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);
202 else
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);
207 else
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);
216 else
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);
221 else
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
242 PerfDataRefresh();
243 PerfDataRefresh();
245 RefreshApplicationPage();
246 RefreshProcessPage();
247 RefreshPerformancePage();
249 TrayIcon_ShellAddTrayIcon();
251 return TRUE;
254 /* OnSize()
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 )
260 int nParts[3];
261 int nXDifference;
262 int nYDifference;
263 RECT rc;
265 if (nType == SIZE_MINIMIZED)
267 if(TaskManagerSettings.HideWhenMinimized)
269 ShowWindow(hMainWnd, SW_HIDE);
271 return;
274 nXDifference = cx - nOldWidth;
275 nYDifference = cy - nOldHeight;
276 nOldWidth = cx;
277 nOldHeight = cy;
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;
285 nParts[1] = 210;
286 nParts[2] = cx;
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)
316 HKEY hKey;
317 int i;
318 DWORD dwSize;
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;
331 /* Tab settings */
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;
412 /* Open the key */
413 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
414 if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
415 return;
416 /* Read the settings */
417 dwSize = sizeof(TASKMANAGER_SETTINGS);
418 RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
420 /* Close the key */
421 RegCloseKey(hKey);
424 static void SaveSettings(void)
426 HKEY hKey;
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)
436 return;
437 /* Save the settings */
438 RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
439 /* Close the key */
440 RegCloseKey(hKey);
443 static void TaskManager_OnRestoreMainWindow(void)
445 BOOL OnTop;
447 OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
449 OpenIcon(hMainWnd);
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)
456 int nParts;
458 /* Update the status bar pane sizes */
459 nParts = -1;
460 SendMessageW(hStatusWnd, SB_SETPARTS, 1, (LPARAM)&nParts);
461 bInMenuLoop = TRUE;
462 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
465 static void TaskManager_OnExitMenuLoop(HWND hWnd)
467 RECT rc;
468 int nParts[3];
469 WCHAR text[256];
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));
477 bInMenuLoop = FALSE;
478 /* Update the status bar pane sizes */
479 GetClientRect(hWnd, &rc);
480 nParts[0] = 100;
481 nParts[1] = 210;
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)
501 HMENU hMenu;
502 HMENU hViewMenu;
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)
518 HMENU hMenu;
519 HMENU hViewMenu;
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)
535 HMENU hMenu;
536 HMENU hViewMenu;
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)
552 HMENU hMenu;
553 HMENU hViewMenu;
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)
566 int i;
567 HMENU hMenu;
568 HMENU hOptionsMenu;
569 HMENU hViewMenu;
570 HMENU hSubMenu;
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);
600 if (hSubMenu)
601 DestroyMenu(hSubMenu);
602 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
604 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
605 switch (TaskManagerSettings.ActiveTabPage) {
606 case 0:
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);
624 else
625 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
627 * Give the application list control focus
629 SetFocus(hApplicationPageListCtrl);
630 break;
632 case 1:
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);
650 break;
652 case 2:
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);
668 else
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);
672 else
673 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
675 * Give the tab control focus
677 SetFocus(hTabWnd);
678 break;
682 LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
684 DWORD dwRet;
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,
689 NULL,
690 GetLastError(),
691 LANG_NEUTRAL,
692 (LPWSTR)&lpwszTemp,
694 NULL );
696 /* supplied buffer is not long enough */
697 if (!dwRet || ( dwSize < dwRet+14)) {
698 lpwszBuf[0] = '\0';
699 } else {
700 lpwszTemp[lstrlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
701 swprintf(lpwszBuf, dwSize, wszFormat, lpwszTemp, GetLastError());
703 if (lpwszTemp) {
704 LocalFree(lpwszTemp);
706 return lpwszBuf;
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};
714 HDC hdc;
715 PAINTSTRUCT ps;
716 LPRECT pRC;
717 RECT rc;
718 LPNMHDR pnmh;
719 WINDOWPLACEMENT wp;
721 switch (message) {
722 case WM_INITDIALOG:
723 hMainWnd = hDlg;
724 return OnCreate(hDlg);
726 case WM_COMMAND:
727 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
728 EndDialog(hDlg, LOWORD(wParam));
729 return TRUE;
731 /* Process menu commands */
732 switch (LOWORD(wParam))
734 case ID_FILE_NEW:
735 TaskManager_OnFileNew();
736 break;
737 case ID_OPTIONS_ALWAYSONTOP:
738 TaskManager_OnOptionsAlwaysOnTop();
739 break;
740 case ID_OPTIONS_MINIMIZEONUSE:
741 TaskManager_OnOptionsMinimizeOnUse();
742 break;
743 case ID_OPTIONS_HIDEWHENMINIMIZED:
744 TaskManager_OnOptionsHideWhenMinimized();
745 break;
746 case ID_OPTIONS_SHOW16BITTASKS:
747 TaskManager_OnOptionsShow16BitTasks();
748 break;
749 case ID_RESTORE:
750 TaskManager_OnRestoreMainWindow();
751 break;
752 case ID_VIEW_LARGE:
753 ApplicationPage_OnViewLargeIcons();
754 break;
755 case ID_VIEW_SMALL:
756 ApplicationPage_OnViewSmallIcons();
757 break;
758 case ID_VIEW_DETAILS:
759 ApplicationPage_OnViewDetails();
760 break;
761 case ID_VIEW_SHOWKERNELTIMES:
762 PerformancePage_OnViewShowKernelTimes();
763 break;
764 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
765 PerformancePage_OnViewCPUHistoryOneGraphAll();
766 break;
767 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
768 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
769 break;
770 case ID_VIEW_UPDATESPEED_HIGH:
771 TaskManager_OnViewUpdateSpeedHigh();
772 break;
773 case ID_VIEW_UPDATESPEED_NORMAL:
774 TaskManager_OnViewUpdateSpeedNormal();
775 break;
776 case ID_VIEW_UPDATESPEED_LOW:
777 TaskManager_OnViewUpdateSpeedLow();
778 break;
779 case ID_VIEW_UPDATESPEED_PAUSED:
780 TaskManager_OnViewUpdateSpeedPaused();
781 break;
782 case ID_VIEW_SELECTCOLUMNS:
783 ProcessPage_OnViewSelectColumns();
784 break;
785 case ID_VIEW_REFRESH:
786 PostMessageW(hDlg, WM_TIMER, 0, 0);
787 break;
788 case ID_WINDOWS_TILEHORIZONTALLY:
789 ApplicationPage_OnWindowsTileHorizontally();
790 break;
791 case ID_WINDOWS_TILEVERTICALLY:
792 ApplicationPage_OnWindowsTileVertically();
793 break;
794 case ID_WINDOWS_MINIMIZE:
795 ApplicationPage_OnWindowsMinimize();
796 break;
797 case ID_WINDOWS_MAXIMIZE:
798 ApplicationPage_OnWindowsMaximize();
799 break;
800 case ID_WINDOWS_CASCADE:
801 ApplicationPage_OnWindowsCascade();
802 break;
803 case ID_WINDOWS_BRINGTOFRONT:
804 ApplicationPage_OnWindowsBringToFront();
805 break;
806 case ID_APPLICATION_PAGE_SWITCHTO:
807 ApplicationPage_OnSwitchTo();
808 break;
809 case ID_APPLICATION_PAGE_ENDTASK:
810 ApplicationPage_OnEndTask();
811 break;
812 case ID_APPLICATION_PAGE_GOTOPROCESS:
813 ApplicationPage_OnGotoProcess();
814 break;
815 case ID_PROCESS_PAGE_ENDPROCESS:
816 ProcessPage_OnEndProcess();
817 break;
818 case ID_PROCESS_PAGE_ENDPROCESSTREE:
819 ProcessPage_OnEndProcessTree();
820 break;
821 case ID_PROCESS_PAGE_DEBUG:
822 ProcessPage_OnDebug();
823 break;
824 case ID_PROCESS_PAGE_SETAFFINITY:
825 ProcessPage_OnSetAffinity();
826 break;
827 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
828 ProcessPage_OnSetPriorityRealTime();
829 break;
830 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
831 ProcessPage_OnSetPriorityHigh();
832 break;
833 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
834 ProcessPage_OnSetPriorityAboveNormal();
835 break;
836 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
837 ProcessPage_OnSetPriorityNormal();
838 break;
839 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
840 ProcessPage_OnSetPriorityBelowNormal();
841 break;
842 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
843 ProcessPage_OnSetPriorityLow();
844 break;
845 case ID_PROCESS_PAGE_DEBUGCHANNELS:
846 ProcessPage_OnDebugChannels();
847 break;
848 case ID_HELP_TOPICS:
849 WinHelpW(hDlg, wszTaskmgr, HELP_FINDER, 0);
850 break;
851 case ID_HELP_ABOUT:
852 OnAbout();
853 break;
854 case ID_FILE_EXIT:
855 EndDialog(hDlg, IDOK);
856 break;
858 break;
860 case WM_ONTRAYICON:
861 switch(lParam)
863 case WM_RBUTTONDOWN:
865 POINT pt;
866 BOOL OnTop;
867 HMENU hMenu, hPopupMenu;
869 GetCursorPos(&pt);
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);
880 else
882 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
885 if(OnTop)
887 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
890 SetForegroundWindow(hMainWnd);
891 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
893 DestroyMenu(hMenu);
894 break;
896 case WM_LBUTTONDBLCLK:
897 TaskManager_OnRestoreMainWindow();
898 break;
900 break;
902 case WM_NOTIFY:
903 pnmh = (LPNMHDR)lParam;
904 if ((pnmh->hwndFrom == hTabWnd) &&
905 (pnmh->idFrom == IDC_TAB) &&
906 (pnmh->code == TCN_SELCHANGE))
908 TaskManager_OnTabWndSelChange();
910 break;
912 case WM_NCPAINT:
913 hdc = GetDC(hDlg);
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);
917 break;
919 case WM_PAINT:
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));
923 EndPaint(hDlg, &ps);
924 break;
926 case WM_SIZING:
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;
934 } else {
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;
943 } else {
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;
948 return TRUE;
950 case WM_SIZE:
951 /* Handle the window sizing in its own function */
952 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
953 break;
955 case WM_DESTROY:
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;
966 else
967 TaskManagerSettings.Maximized = FALSE;
968 return DefWindowProcW(hDlg, message, wParam, lParam);
970 case WM_TIMER:
971 /* Refresh the performance data */
972 PerfDataRefresh();
973 RefreshApplicationPage();
974 RefreshProcessPage();
975 RefreshPerformancePage();
976 TrayIcon_ShellUpdateTrayIcon();
977 break;
979 case WM_ENTERMENULOOP:
980 TaskManager_OnEnterMenuLoop(hDlg);
981 break;
982 case WM_EXITMENULOOP:
983 TaskManager_OnExitMenuLoop(hDlg);
984 break;
985 case WM_MENUSELECT:
986 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
987 break;
990 return 0;
993 int APIENTRY WinMain(HINSTANCE hInstance,
994 HINSTANCE hPrevInstance,
995 LPSTR lpCmdLine,
996 int nCmdShow)
998 HANDLE hProcess;
999 HANDLE hToken;
1000 TOKEN_PRIVILEGES tkp;
1002 InitCommonControls();
1004 /* Initialize global variables */
1005 hInst = hInstance;
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 */
1031 LoadSettings();
1033 /* Initialize perf data */
1034 if (!PerfDataInitialize()) {
1035 return -1;
1038 DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
1040 /* Save our settings to the registry */
1041 SaveSettings();
1042 return 0;