winex11: Add some sanity checks on bitmap formats before creating a pixmap.
[wine/zf.git] / programs / taskmgr / taskmgr.c
blobb7ffd3defd906a7aaa65948bd1af0e65279f45a7
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 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
25 #include <windows.h>
26 #include <commctrl.h>
27 #include <stdlib.h>
28 #include <memory.h>
29 #include <stdio.h>
30 #include <winnt.h>
32 #include "wine/unicode.h"
33 #include "resource.h"
34 #include "taskmgr.h"
35 #include "perfdata.h"
36 #include "column.h"
38 #define STATUS_WINDOW 2001
40 /* Global Variables: */
41 HINSTANCE hInst; /* current instance */
43 HWND hMainWnd; /* Main Window */
44 HWND hStatusWnd; /* Status Bar Window */
45 HWND hTabWnd; /* Tab Control Window */
47 int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */
48 int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */
50 int nOldWidth; /* Holds the previous client area width */
51 int nOldHeight; /* Holds the previous client area height */
53 BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
55 TASKMANAGER_SETTINGS TaskManagerSettings;
58 void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
60 SetBkColor(hDC, clr);
61 ExtTextOutW(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
64 static void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
66 RECT rect;
68 SetBkColor(hDC, clr);
69 rect.left = x;
70 rect.top = y;
71 rect.right = x + cx;
72 rect.bottom = y + cy;
73 ExtTextOutW(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
76 static void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
78 FillSolidRect2(hDC, x, y, cx - 1, 1, clrTopLeft);
79 FillSolidRect2(hDC, x, y, 1, cy - 1, clrTopLeft);
80 FillSolidRect2(hDC, x + cx, y, -1, cy, clrBottomRight);
81 FillSolidRect2(hDC, x, y + cy, cx, -1, clrBottomRight);
84 void Font_DrawText(HDC hDC, LPWSTR lpwszText, int x, int y)
86 HDC hFontDC;
87 HBITMAP hFontBitmap;
88 HBITMAP hOldBitmap;
89 int i;
91 hFontDC = CreateCompatibleDC(hDC);
92 hFontBitmap = LoadBitmapW(hInst, MAKEINTRESOURCEW(IDB_FONT));
93 hOldBitmap = SelectObject(hFontDC, hFontBitmap);
95 for (i = 0; lpwszText[i]; i++) {
96 if ((lpwszText[i] >= '0') && (lpwszText[i] <= '9')) {
97 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpwszText[i] - '0') * 8, 0, SRCCOPY);
99 else if (lpwszText[i] == 'K')
101 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
103 else if (lpwszText[i] == '%')
105 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
108 SelectObject(hFontDC, hOldBitmap);
109 DeleteObject(hFontBitmap);
110 DeleteDC(hFontDC);
113 static BOOL OnCreate(HWND hWnd)
115 HMENU hMenu;
116 HMENU hEditMenu;
117 HMENU hViewMenu;
118 HMENU hUpdateSpeedMenu;
119 HMENU hCPUHistoryMenu;
120 int nActivePage;
121 int nParts[3];
122 RECT rc;
123 TCITEMW item;
125 static WCHAR wszApplications[255];
126 static WCHAR wszProcesses[255];
127 static WCHAR wszPerformance[255];
129 LoadStringW(hInst, IDS_APPLICATIONS, wszApplications, sizeof(wszApplications)/sizeof(WCHAR));
130 LoadStringW(hInst, IDS_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR));
131 LoadStringW(hInst, IDS_PERFORMANCE, wszPerformance, sizeof(wszPerformance)/sizeof(WCHAR));
133 SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW(hInst, MAKEINTRESOURCEW(IDI_TASKMANAGER)));
134 SendMessageW(hMainWnd, WM_SETICON, ICON_SMALL,
135 (LPARAM)LoadImageW(hInst, MAKEINTRESOURCEW(IDI_TASKMANAGER), IMAGE_ICON,
136 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
137 LR_SHARED));
139 /* Initialize the Windows Common Controls DLL */
140 InitCommonControls();
142 /* Get the minimum window sizes */
143 GetWindowRect(hWnd, &rc);
144 nMinimumWidth = (rc.right - rc.left);
145 nMinimumHeight = (rc.bottom - rc.top);
147 /* Create the status bar */
148 hStatusWnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, NULL, hWnd, STATUS_WINDOW);
149 if(!hStatusWnd)
150 return FALSE;
152 /* Create the status bar panes */
153 nParts[0] = 100;
154 nParts[1] = 210;
155 nParts[2] = 400;
156 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
158 /* Create tab pages */
159 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
160 #if 1
161 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hWnd, ApplicationPageWndProc);
162 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hWnd, ProcessPageWndProc);
163 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hWnd, PerformancePageWndProc);
164 #else
165 hApplicationPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE), hTabWnd, ApplicationPageWndProc);
166 hProcessPage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PROCESS_PAGE), hTabWnd, ProcessPageWndProc);
167 hPerformancePage = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE), hTabWnd, PerformancePageWndProc);
168 #endif
170 /* Insert tabs */
171 memset(&item, 0, sizeof(TCITEMW));
172 item.mask = TCIF_TEXT;
173 item.pszText = wszApplications;
174 SendMessageW(hTabWnd, TCM_INSERTITEMW, 0, (LPARAM)&item);
175 memset(&item, 0, sizeof(TCITEMW));
176 item.mask = TCIF_TEXT;
177 item.pszText = wszProcesses;
178 SendMessageW(hTabWnd, TCM_INSERTITEMW, 1, (LPARAM)&item);
179 memset(&item, 0, sizeof(TCITEMW));
180 item.mask = TCIF_TEXT;
181 item.pszText = wszPerformance;
182 SendMessageW(hTabWnd, TCM_INSERTITEMW, 2, (LPARAM)&item);
184 /* Size everything correctly */
185 GetClientRect(hWnd, &rc);
186 nOldWidth = rc.right;
187 nOldHeight = rc.bottom;
188 /* nOldStartX = rc.left; */
189 /*nOldStartY = rc.top; */
191 #define PAGE_OFFSET_LEFT 17
192 #define PAGE_OFFSET_TOP 72
193 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
194 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
196 if ((TaskManagerSettings.Left != 0) ||
197 (TaskManagerSettings.Top != 0) ||
198 (TaskManagerSettings.Right != 0) ||
199 (TaskManagerSettings.Bottom != 0))
201 MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE);
202 #ifdef __GNUC__TEST__
203 MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
204 MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
205 MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
206 #endif
208 if (TaskManagerSettings.Maximized)
209 ShowWindow(hWnd, SW_MAXIMIZE);
211 /* Set the always on top style */
212 hMenu = GetMenu(hWnd);
213 hEditMenu = GetSubMenu(hMenu, 1);
214 hViewMenu = GetSubMenu(hMenu, 2);
215 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
216 hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
218 /* Check or uncheck the always on top menu item */
219 if (TaskManagerSettings.AlwaysOnTop) {
220 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED);
221 SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
222 } else {
223 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
224 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
227 /* Check or uncheck the minimize on use menu item */
228 if (TaskManagerSettings.MinimizeOnUse)
229 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
230 else
231 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
233 /* Check or uncheck the hide when minimized menu item */
234 if (TaskManagerSettings.HideWhenMinimized)
235 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
236 else
237 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
239 /* Check or uncheck the show 16-bit tasks menu item */
240 if (TaskManagerSettings.Show16BitTasks)
241 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
242 else
243 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
245 if (TaskManagerSettings.View_LargeIcons)
246 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
247 else if (TaskManagerSettings.View_SmallIcons)
248 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
249 else
250 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
252 if (TaskManagerSettings.ShowKernelTimes)
253 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
254 else
255 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
257 if (TaskManagerSettings.UpdateSpeed == 1)
258 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
259 else if (TaskManagerSettings.UpdateSpeed == 2)
260 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
261 else if (TaskManagerSettings.UpdateSpeed == 4)
262 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
263 else
264 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
266 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
267 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
268 else
269 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
271 nActivePage = TaskManagerSettings.ActiveTabPage;
272 SendMessageW(hTabWnd, TCM_SETCURFOCUS, 0, 0);
273 SendMessageW(hTabWnd, TCM_SETCURFOCUS, 1, 0);
274 SendMessageW(hTabWnd, TCM_SETCURFOCUS, 2, 0);
275 SendMessageW(hTabWnd, TCM_SETCURFOCUS, nActivePage, 0);
277 if (TaskManagerSettings.UpdateSpeed == 1)
278 SetTimer(hWnd, 1, 1000, NULL);
279 else if (TaskManagerSettings.UpdateSpeed == 2)
280 SetTimer(hWnd, 1, 2000, NULL);
281 else if (TaskManagerSettings.UpdateSpeed == 4)
282 SetTimer(hWnd, 1, 4000, NULL);
285 * Refresh the performance data
286 * Sample it twice so we can establish
287 * the delta values & cpu usage
289 PerfDataRefresh();
290 PerfDataRefresh();
292 RefreshApplicationPage();
293 RefreshProcessPage();
294 RefreshPerformancePage();
296 TrayIcon_ShellAddTrayIcon();
298 return TRUE;
301 /* OnMove()
302 * This function handles all the moving events for the application
303 * It moves every child window that needs moving
305 static void OnMove( UINT nType, int cx, int cy )
307 #ifdef __GNUC__TEST__
308 MoveWindow(hApplicationPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
309 MoveWindow(hProcessPage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
310 MoveWindow(hPerformancePage, TaskManagerSettings.Left + PAGE_OFFSET_LEFT, TaskManagerSettings.Top + PAGE_OFFSET_TOP, TaskManagerSettings.Right - TaskManagerSettings.Left - PAGE_OFFSET_WIDTH, TaskManagerSettings.Bottom - TaskManagerSettings.Top - PAGE_OFFSET_HEIGHT, FALSE);
311 #endif
314 /* OnSize()
315 * This function handles all the sizing events for the application
316 * It re-sizes every window, and child window that needs re-sizing
318 static void OnSize( UINT nType, int cx, int cy )
320 int nParts[3];
321 int nXDifference;
322 int nYDifference;
323 RECT rc;
325 if (nType == SIZE_MINIMIZED)
327 if(TaskManagerSettings.HideWhenMinimized)
329 ShowWindow(hMainWnd, SW_HIDE);
331 return;
334 nXDifference = cx - nOldWidth;
335 nYDifference = cy - nOldHeight;
336 nOldWidth = cx;
337 nOldHeight = cy;
339 /* Update the status bar size */
340 GetWindowRect(hStatusWnd, &rc);
341 SendMessageW(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
343 /* Update the status bar pane sizes */
344 nParts[0] = bInMenuLoop ? -1 : 100;
345 nParts[1] = 210;
346 nParts[2] = cx;
347 SendMessageW(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (LPARAM)nParts);
349 /* Resize the tab control */
350 GetWindowRect(hTabWnd, &rc);
351 cx = (rc.right - rc.left) + nXDifference;
352 cy = (rc.bottom - rc.top) + nYDifference;
353 SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
355 /* Resize the application page */
356 GetWindowRect(hApplicationPage, &rc);
357 cx = (rc.right - rc.left) + nXDifference;
358 cy = (rc.bottom - rc.top) + nYDifference;
359 SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
361 /* Resize the process page */
362 GetWindowRect(hProcessPage, &rc);
363 cx = (rc.right - rc.left) + nXDifference;
364 cy = (rc.bottom - rc.top) + nYDifference;
365 SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
367 /* Resize the performance page */
368 GetWindowRect(hPerformancePage, &rc);
369 cx = (rc.right - rc.left) + nXDifference;
370 cy = (rc.bottom - rc.top) + nYDifference;
371 SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
374 static void LoadSettings(void)
376 HKEY hKey;
377 int i;
378 DWORD dwSize;
380 static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
381 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
382 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
384 /* Window size & position settings */
385 TaskManagerSettings.Maximized = FALSE;
386 TaskManagerSettings.Left = 0;
387 TaskManagerSettings.Top = 0;
388 TaskManagerSettings.Right = 0;
389 TaskManagerSettings.Bottom = 0;
391 /* Tab settings */
392 TaskManagerSettings.ActiveTabPage = 0;
394 /* Options menu settings */
395 TaskManagerSettings.AlwaysOnTop = FALSE;
396 TaskManagerSettings.MinimizeOnUse = TRUE;
397 TaskManagerSettings.HideWhenMinimized = TRUE;
398 TaskManagerSettings.Show16BitTasks = TRUE;
400 /* Update speed settings */
401 TaskManagerSettings.UpdateSpeed = 2;
403 /* Applications page settings */
404 TaskManagerSettings.View_LargeIcons = FALSE;
405 TaskManagerSettings.View_SmallIcons = FALSE;
406 TaskManagerSettings.View_Details = TRUE;
408 /* Processes page settings */
409 TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */
410 TaskManagerSettings.Column_ImageName = TRUE;
411 TaskManagerSettings.Column_PID = TRUE;
412 TaskManagerSettings.Column_CPUUsage = TRUE;
413 TaskManagerSettings.Column_CPUTime = TRUE;
414 TaskManagerSettings.Column_MemoryUsage = TRUE;
415 TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
416 TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
417 TaskManagerSettings.Column_PageFaults = FALSE;
418 TaskManagerSettings.Column_USERObjects = FALSE;
419 TaskManagerSettings.Column_IOReads = FALSE;
420 TaskManagerSettings.Column_IOReadBytes = FALSE;
421 TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */
422 TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */
423 TaskManagerSettings.Column_PageFaultsDelta = FALSE;
424 TaskManagerSettings.Column_VirtualMemorySize = FALSE;
425 TaskManagerSettings.Column_PagedPool = FALSE;
426 TaskManagerSettings.Column_NonPagedPool = FALSE;
427 TaskManagerSettings.Column_BasePriority = FALSE;
428 TaskManagerSettings.Column_HandleCount = FALSE;
429 TaskManagerSettings.Column_ThreadCount = FALSE;
430 TaskManagerSettings.Column_GDIObjects = FALSE;
431 TaskManagerSettings.Column_IOWrites = FALSE;
432 TaskManagerSettings.Column_IOWriteBytes = FALSE;
433 TaskManagerSettings.Column_IOOther = FALSE;
434 TaskManagerSettings.Column_IOOtherBytes = FALSE;
436 for (i = 0; i < 25; i++) {
437 TaskManagerSettings.ColumnOrderArray[i] = i;
439 TaskManagerSettings.ColumnSizeArray[0] = 105;
440 TaskManagerSettings.ColumnSizeArray[1] = 50;
441 TaskManagerSettings.ColumnSizeArray[2] = 107;
442 TaskManagerSettings.ColumnSizeArray[3] = 70;
443 TaskManagerSettings.ColumnSizeArray[4] = 35;
444 TaskManagerSettings.ColumnSizeArray[5] = 70;
445 TaskManagerSettings.ColumnSizeArray[6] = 70;
446 TaskManagerSettings.ColumnSizeArray[7] = 100;
447 TaskManagerSettings.ColumnSizeArray[8] = 70;
448 TaskManagerSettings.ColumnSizeArray[9] = 70;
449 TaskManagerSettings.ColumnSizeArray[10] = 70;
450 TaskManagerSettings.ColumnSizeArray[11] = 70;
451 TaskManagerSettings.ColumnSizeArray[12] = 70;
452 TaskManagerSettings.ColumnSizeArray[13] = 70;
453 TaskManagerSettings.ColumnSizeArray[14] = 60;
454 TaskManagerSettings.ColumnSizeArray[15] = 60;
455 TaskManagerSettings.ColumnSizeArray[16] = 60;
456 TaskManagerSettings.ColumnSizeArray[17] = 60;
457 TaskManagerSettings.ColumnSizeArray[18] = 60;
458 TaskManagerSettings.ColumnSizeArray[19] = 70;
459 TaskManagerSettings.ColumnSizeArray[20] = 70;
460 TaskManagerSettings.ColumnSizeArray[21] = 70;
461 TaskManagerSettings.ColumnSizeArray[22] = 70;
462 TaskManagerSettings.ColumnSizeArray[23] = 70;
463 TaskManagerSettings.ColumnSizeArray[24] = 70;
465 TaskManagerSettings.SortColumn = 1;
466 TaskManagerSettings.SortAscending = TRUE;
468 /* Performance page settings */
469 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
470 TaskManagerSettings.ShowKernelTimes = FALSE;
472 /* Open the key */
473 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
474 if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
475 return;
476 /* Read the settings */
477 dwSize = sizeof(TASKMANAGER_SETTINGS);
478 RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
480 /* Close the key */
481 RegCloseKey(hKey);
484 static void SaveSettings(void)
486 HKEY hKey;
488 static const WCHAR wszSubKey3[] = {'S','o','f','t','w','a','r','e','\\',
489 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
490 static const WCHAR wszPreferences[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
492 /* Open (or create) the key */
494 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
495 if (RegCreateKeyExW(HKEY_CURRENT_USER, wszSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
496 return;
497 /* Save the settings */
498 RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
499 /* Close the key */
500 RegCloseKey(hKey);
503 static void TaskManager_OnRestoreMainWindow(void)
505 BOOL OnTop;
507 OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
509 OpenIcon(hMainWnd);
510 SetForegroundWindow(hMainWnd);
511 SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
514 static void TaskManager_OnEnterMenuLoop(HWND hWnd)
516 int nParts;
518 /* Update the status bar pane sizes */
519 nParts = -1;
520 SendMessageW(hStatusWnd, SB_SETPARTS, 1, (LPARAM)&nParts);
521 bInMenuLoop = TRUE;
522 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
525 static void TaskManager_OnExitMenuLoop(HWND hWnd)
527 RECT rc;
528 int nParts[3];
529 WCHAR text[256];
531 WCHAR wszCPU_Usage[255];
532 WCHAR wszProcesses[255];
534 LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
535 LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR));
537 bInMenuLoop = FALSE;
538 /* Update the status bar pane sizes */
539 GetClientRect(hWnd, &rc);
540 nParts[0] = 100;
541 nParts[1] = 210;
542 nParts[2] = rc.right;
543 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
544 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
545 wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage());
546 SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text);
547 wsprintfW(text, wszProcesses, PerfDataGetProcessCount());
548 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text);
551 static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
553 WCHAR wstr[256] = {0};
555 LoadStringW(hInst, nItemID, wstr, sizeof(wstr)/sizeof(WCHAR));
556 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)wstr);
559 static void TaskManager_OnViewUpdateSpeedHigh(void)
561 HMENU hMenu;
562 HMENU hViewMenu;
563 HMENU hUpdateSpeedMenu;
565 hMenu = GetMenu(hMainWnd);
566 hViewMenu = GetSubMenu(hMenu, 2);
567 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
569 TaskManagerSettings.UpdateSpeed = 1;
570 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
572 KillTimer(hMainWnd, 1);
573 SetTimer(hMainWnd, 1, 1000, NULL);
576 static void TaskManager_OnViewUpdateSpeedNormal(void)
578 HMENU hMenu;
579 HMENU hViewMenu;
580 HMENU hUpdateSpeedMenu;
582 hMenu = GetMenu(hMainWnd);
583 hViewMenu = GetSubMenu(hMenu, 2);
584 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
586 TaskManagerSettings.UpdateSpeed = 2;
587 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
589 KillTimer(hMainWnd, 1);
590 SetTimer(hMainWnd, 1, 2000, NULL);
593 static void TaskManager_OnViewUpdateSpeedLow(void)
595 HMENU hMenu;
596 HMENU hViewMenu;
597 HMENU hUpdateSpeedMenu;
599 hMenu = GetMenu(hMainWnd);
600 hViewMenu = GetSubMenu(hMenu, 2);
601 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
603 TaskManagerSettings.UpdateSpeed = 4;
604 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
606 KillTimer(hMainWnd, 1);
607 SetTimer(hMainWnd, 1, 4000, NULL);
610 static void TaskManager_OnViewUpdateSpeedPaused(void)
612 HMENU hMenu;
613 HMENU hViewMenu;
614 HMENU hUpdateSpeedMenu;
616 hMenu = GetMenu(hMainWnd);
617 hViewMenu = GetSubMenu(hMenu, 2);
618 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
619 TaskManagerSettings.UpdateSpeed = 0;
620 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
621 KillTimer(hMainWnd, 1);
624 static void TaskManager_OnTabWndSelChange(void)
626 int i;
627 HMENU hMenu;
628 HMENU hOptionsMenu;
629 HMENU hViewMenu;
630 HMENU hSubMenu;
632 WCHAR wszLargeIcons[255];
633 WCHAR wszSmallIcons[255];
634 WCHAR wszDetails[255];
635 WCHAR wszWindows[255];
636 WCHAR wszSelectColumns[255];
637 WCHAR wszShow16bTasks[255];
638 WCHAR wszOneGraphAllCPU[255];
639 WCHAR wszOneGraphPerCPU[255];
640 WCHAR wszCPUHistory[255];
641 WCHAR wszShowKernelTimes[255];
643 LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, sizeof(wszLargeIcons)/sizeof(WCHAR));
644 LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, sizeof(wszSmallIcons)/sizeof(WCHAR));
645 LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, sizeof(wszDetails)/sizeof(WCHAR));
646 LoadStringW(hInst, IDS_WINDOWS, wszWindows, sizeof(wszWindows)/sizeof(WCHAR));
647 LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, sizeof(wszSelectColumns)/sizeof(WCHAR));
648 LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, sizeof(wszShow16bTasks)/sizeof(WCHAR));
649 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, sizeof(wszOneGraphAllCPU)/sizeof(WCHAR));
650 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, sizeof(wszOneGraphPerCPU)/sizeof(WCHAR));
651 LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, sizeof(wszCPUHistory)/sizeof(WCHAR));
652 LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, sizeof(wszShowKernelTimes)/sizeof(WCHAR));
654 hMenu = GetMenu(hMainWnd);
655 hViewMenu = GetSubMenu(hMenu, 2);
656 hOptionsMenu = GetSubMenu(hMenu, 1);
657 TaskManagerSettings.ActiveTabPage = SendMessageW(hTabWnd, TCM_GETCURSEL, 0, 0);
658 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
659 hSubMenu = GetSubMenu(hViewMenu, i);
660 if (hSubMenu)
661 DestroyMenu(hSubMenu);
662 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
664 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
665 switch (TaskManagerSettings.ActiveTabPage) {
666 case 0:
667 ShowWindow(hApplicationPage, SW_SHOW);
668 ShowWindow(hProcessPage, SW_HIDE);
669 ShowWindow(hPerformancePage, SW_HIDE);
670 BringWindowToTop(hApplicationPage);
671 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
672 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
673 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);
675 if (GetMenuItemCount(hMenu) <= 4) {
676 hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
677 InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
678 DrawMenuBar(hMainWnd);
680 if (TaskManagerSettings.View_LargeIcons)
681 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
682 else if (TaskManagerSettings.View_SmallIcons)
683 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
684 else
685 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
687 * Give the application list control focus
689 SetFocus(hApplicationPageListCtrl);
690 break;
692 case 1:
693 ShowWindow(hApplicationPage, SW_HIDE);
694 ShowWindow(hProcessPage, SW_SHOW);
695 ShowWindow(hPerformancePage, SW_HIDE);
696 BringWindowToTop(hProcessPage);
697 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
698 AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
699 if (TaskManagerSettings.Show16BitTasks)
700 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
701 if (GetMenuItemCount(hMenu) > 4)
703 RemoveMenu(hMenu, 3, MF_BYPOSITION);
704 DrawMenuBar(hMainWnd);
707 * Give the process list control focus
709 SetFocus(hProcessPageListCtrl);
710 break;
712 case 2:
713 ShowWindow(hApplicationPage, SW_HIDE);
714 ShowWindow(hProcessPage, SW_HIDE);
715 ShowWindow(hPerformancePage, SW_SHOW);
716 BringWindowToTop(hPerformancePage);
717 if (GetMenuItemCount(hMenu) > 4) {
718 RemoveMenu(hMenu, 3, MF_BYPOSITION);
719 DrawMenuBar(hMainWnd);
721 hSubMenu = CreatePopupMenu();
722 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
723 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
724 AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
725 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
726 if (TaskManagerSettings.ShowKernelTimes)
727 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
728 else
729 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
730 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
731 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
732 else
733 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
735 * Give the tab control focus
737 SetFocus(hTabWnd);
738 break;
742 LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
744 DWORD dwRet;
745 LPWSTR lpwszTemp = NULL;
746 static const WCHAR wszFormat[] = {'%','s',' ','(','%','u',')',0};
748 dwRet = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
749 NULL,
750 GetLastError(),
751 LANG_NEUTRAL,
752 (LPWSTR)&lpwszTemp,
754 NULL );
756 /* supplied buffer is not long enough */
757 if (!dwRet || ( dwSize < dwRet+14)) {
758 lpwszBuf[0] = '\0';
759 } else {
760 lpwszTemp[strlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
761 sprintfW(lpwszBuf, wszFormat, lpwszTemp, GetLastError());
763 if (lpwszTemp) {
764 LocalFree(lpwszTemp);
766 return lpwszBuf;
769 /* Message handler for dialog box. */
770 static INT_PTR CALLBACK
771 TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
773 static const WCHAR wszTaskmgr[] = {'t','a','s','k','m','g','r',0};
774 HDC hdc;
775 PAINTSTRUCT ps;
776 LPRECT pRC;
777 RECT rc;
778 LPNMHDR pnmh;
779 WINDOWPLACEMENT wp;
781 switch (message) {
782 case WM_INITDIALOG:
783 hMainWnd = hDlg;
784 return OnCreate(hDlg);
786 case WM_COMMAND:
787 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
788 EndDialog(hDlg, LOWORD(wParam));
789 return TRUE;
791 /* Process menu commands */
792 switch (LOWORD(wParam))
794 case ID_FILE_NEW:
795 TaskManager_OnFileNew();
796 break;
797 case ID_OPTIONS_ALWAYSONTOP:
798 TaskManager_OnOptionsAlwaysOnTop();
799 break;
800 case ID_OPTIONS_MINIMIZEONUSE:
801 TaskManager_OnOptionsMinimizeOnUse();
802 break;
803 case ID_OPTIONS_HIDEWHENMINIMIZED:
804 TaskManager_OnOptionsHideWhenMinimized();
805 break;
806 case ID_OPTIONS_SHOW16BITTASKS:
807 TaskManager_OnOptionsShow16BitTasks();
808 break;
809 case ID_RESTORE:
810 TaskManager_OnRestoreMainWindow();
811 break;
812 case ID_VIEW_LARGE:
813 ApplicationPage_OnViewLargeIcons();
814 break;
815 case ID_VIEW_SMALL:
816 ApplicationPage_OnViewSmallIcons();
817 break;
818 case ID_VIEW_DETAILS:
819 ApplicationPage_OnViewDetails();
820 break;
821 case ID_VIEW_SHOWKERNELTIMES:
822 PerformancePage_OnViewShowKernelTimes();
823 break;
824 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
825 PerformancePage_OnViewCPUHistoryOneGraphAll();
826 break;
827 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
828 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
829 break;
830 case ID_VIEW_UPDATESPEED_HIGH:
831 TaskManager_OnViewUpdateSpeedHigh();
832 break;
833 case ID_VIEW_UPDATESPEED_NORMAL:
834 TaskManager_OnViewUpdateSpeedNormal();
835 break;
836 case ID_VIEW_UPDATESPEED_LOW:
837 TaskManager_OnViewUpdateSpeedLow();
838 break;
839 case ID_VIEW_UPDATESPEED_PAUSED:
840 TaskManager_OnViewUpdateSpeedPaused();
841 break;
842 case ID_VIEW_SELECTCOLUMNS:
843 ProcessPage_OnViewSelectColumns();
844 break;
845 case ID_VIEW_REFRESH:
846 PostMessageW(hDlg, WM_TIMER, 0, 0);
847 break;
848 case ID_WINDOWS_TILEHORIZONTALLY:
849 ApplicationPage_OnWindowsTileHorizontally();
850 break;
851 case ID_WINDOWS_TILEVERTICALLY:
852 ApplicationPage_OnWindowsTileVertically();
853 break;
854 case ID_WINDOWS_MINIMIZE:
855 ApplicationPage_OnWindowsMinimize();
856 break;
857 case ID_WINDOWS_MAXIMIZE:
858 ApplicationPage_OnWindowsMaximize();
859 break;
860 case ID_WINDOWS_CASCADE:
861 ApplicationPage_OnWindowsCascade();
862 break;
863 case ID_WINDOWS_BRINGTOFRONT:
864 ApplicationPage_OnWindowsBringToFront();
865 break;
866 case ID_APPLICATION_PAGE_SWITCHTO:
867 ApplicationPage_OnSwitchTo();
868 break;
869 case ID_APPLICATION_PAGE_ENDTASK:
870 ApplicationPage_OnEndTask();
871 break;
872 case ID_APPLICATION_PAGE_GOTOPROCESS:
873 ApplicationPage_OnGotoProcess();
874 break;
875 case ID_PROCESS_PAGE_ENDPROCESS:
876 ProcessPage_OnEndProcess();
877 break;
878 case ID_PROCESS_PAGE_ENDPROCESSTREE:
879 ProcessPage_OnEndProcessTree();
880 break;
881 case ID_PROCESS_PAGE_DEBUG:
882 ProcessPage_OnDebug();
883 break;
884 case ID_PROCESS_PAGE_SETAFFINITY:
885 ProcessPage_OnSetAffinity();
886 break;
887 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
888 ProcessPage_OnSetPriorityRealTime();
889 break;
890 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
891 ProcessPage_OnSetPriorityHigh();
892 break;
893 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
894 ProcessPage_OnSetPriorityAboveNormal();
895 break;
896 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
897 ProcessPage_OnSetPriorityNormal();
898 break;
899 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
900 ProcessPage_OnSetPriorityBelowNormal();
901 break;
902 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
903 ProcessPage_OnSetPriorityLow();
904 break;
905 case ID_PROCESS_PAGE_DEBUGCHANNELS:
906 ProcessPage_OnDebugChannels();
907 break;
908 case ID_HELP_TOPICS:
909 WinHelpW(hDlg, wszTaskmgr, HELP_FINDER, 0);
910 break;
911 case ID_HELP_ABOUT:
912 OnAbout();
913 break;
914 case ID_FILE_EXIT:
915 EndDialog(hDlg, IDOK);
916 break;
918 break;
920 case WM_ONTRAYICON:
921 switch(lParam)
923 case WM_RBUTTONDOWN:
925 POINT pt;
926 BOOL OnTop;
927 HMENU hMenu, hPopupMenu;
929 GetCursorPos(&pt);
931 OnTop = (GetWindowLongW(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
933 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
934 hPopupMenu = GetSubMenu(hMenu, 0);
936 if(IsWindowVisible(hMainWnd))
938 DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
940 else
942 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
945 if(OnTop)
947 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
950 SetForegroundWindow(hMainWnd);
951 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
953 DestroyMenu(hMenu);
954 break;
956 case WM_LBUTTONDBLCLK:
957 TaskManager_OnRestoreMainWindow();
958 break;
960 break;
962 case WM_NOTIFY:
963 pnmh = (LPNMHDR)lParam;
964 if ((pnmh->hwndFrom == hTabWnd) &&
965 (pnmh->idFrom == IDC_TAB) &&
966 (pnmh->code == TCN_SELCHANGE))
968 TaskManager_OnTabWndSelChange();
970 break;
972 case WM_NCPAINT:
973 hdc = GetDC(hDlg);
974 GetClientRect(hDlg, &rc);
975 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
976 ReleaseDC(hDlg, hdc);
977 break;
979 case WM_PAINT:
980 hdc = BeginPaint(hDlg, &ps);
981 GetClientRect(hDlg, &rc);
982 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
983 EndPaint(hDlg, &ps);
984 break;
986 case WM_SIZING:
987 /* Make sure the user is sizing the dialog */
988 /* in an acceptable range */
989 pRC = (LPRECT)lParam;
990 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
991 /* If the width is too small enlarge it to the minimum */
992 if (nMinimumWidth > (pRC->right - pRC->left))
993 pRC->left = pRC->right - nMinimumWidth;
994 } else {
995 /* If the width is too small enlarge it to the minimum */
996 if (nMinimumWidth > (pRC->right - pRC->left))
997 pRC->right = pRC->left + nMinimumWidth;
999 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
1000 /* If the height is too small enlarge it to the minimum */
1001 if (nMinimumHeight > (pRC->bottom - pRC->top))
1002 pRC->top = pRC->bottom - nMinimumHeight;
1003 } else {
1004 /* If the height is too small enlarge it to the minimum */
1005 if (nMinimumHeight > (pRC->bottom - pRC->top))
1006 pRC->bottom = pRC->top + nMinimumHeight;
1008 return TRUE;
1010 case WM_SIZE:
1011 /* Handle the window sizing in it's own function */
1012 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
1013 break;
1015 case WM_MOVE:
1016 /* Handle the window moving in it's own function */
1017 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
1018 break;
1020 case WM_DESTROY:
1021 ShowWindow(hDlg, SW_HIDE);
1022 TrayIcon_ShellRemoveTrayIcon();
1023 wp.length = sizeof(WINDOWPLACEMENT);
1024 GetWindowPlacement(hDlg, &wp);
1025 TaskManagerSettings.Left = wp.rcNormalPosition.left;
1026 TaskManagerSettings.Top = wp.rcNormalPosition.top;
1027 TaskManagerSettings.Right = wp.rcNormalPosition.right;
1028 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
1029 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
1030 TaskManagerSettings.Maximized = TRUE;
1031 else
1032 TaskManagerSettings.Maximized = FALSE;
1033 return DefWindowProcW(hDlg, message, wParam, lParam);
1035 case WM_TIMER:
1036 /* Refresh the performance data */
1037 PerfDataRefresh();
1038 RefreshApplicationPage();
1039 RefreshProcessPage();
1040 RefreshPerformancePage();
1041 TrayIcon_ShellUpdateTrayIcon();
1042 break;
1044 case WM_ENTERMENULOOP:
1045 TaskManager_OnEnterMenuLoop(hDlg);
1046 break;
1047 case WM_EXITMENULOOP:
1048 TaskManager_OnExitMenuLoop(hDlg);
1049 break;
1050 case WM_MENUSELECT:
1051 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
1052 break;
1055 return 0;
1058 int APIENTRY WinMain(HINSTANCE hInstance,
1059 HINSTANCE hPrevInstance,
1060 LPSTR lpCmdLine,
1061 int nCmdShow)
1063 HANDLE hProcess;
1064 HANDLE hToken;
1065 TOKEN_PRIVILEGES tkp;
1067 /* Initialize global variables */
1068 hInst = hInstance;
1070 /* Change our priority class to HIGH */
1071 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
1072 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
1073 CloseHandle(hProcess);
1075 /* Now let's get the SE_DEBUG_NAME privilege
1076 * so that we can debug processes
1079 /* Get a token for this process. */
1080 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
1081 static const WCHAR SeDebugPrivilegeW[] = {'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0};
1083 /* Get the LUID for the debug privilege. */
1084 LookupPrivilegeValueW(NULL, SeDebugPrivilegeW, &tkp.Privileges[0].Luid);
1086 tkp.PrivilegeCount = 1; /* one privilege to set */
1087 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1089 /* Get the debug privilege for this process. */
1090 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
1093 /* Load our settings from the registry */
1094 LoadSettings();
1096 /* Initialize perf data */
1097 if (!PerfDataInitialize()) {
1098 return -1;
1101 DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
1103 /* Save our settings to the registry */
1104 SaveSettings();
1105 PerfDataUninitialize();
1106 return 0;