Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / programs / taskmgr / taskmgr.c
blob3eef012dae816adada8259366d2ff5a6c191eb79
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>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.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 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
64 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 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
76 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 Draw3dRect2(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight)
86 Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left,
87 lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight);
90 void Font_DrawText(HDC hDC, LPCTSTR lpszText, int x, int y)
92 HDC hFontDC;
93 HBITMAP hFontBitmap;
94 HBITMAP hOldBitmap;
95 int i;
97 hFontDC = CreateCompatibleDC(hDC);
98 hFontBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FONT));
99 hOldBitmap = (HBITMAP)SelectObject(hFontDC, hFontBitmap);
101 for (i = 0; i < (int)_tcslen(lpszText); i++) {
102 if ((lpszText[i] >= '0') && (lpszText[i] <= '9')) {
103 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, (lpszText[i] - '0') * 8, 0, SRCCOPY);
105 else if (lpszText[i] == 'K')
107 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
109 else if (lpszText[i] == '%')
111 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
114 SelectObject(hFontDC, hOldBitmap);
115 DeleteObject(hFontBitmap);
116 DeleteDC(hFontDC);
119 static BOOL OnCreate(HWND hWnd)
121 HMENU hMenu;
122 HMENU hEditMenu;
123 HMENU hViewMenu;
124 HMENU hUpdateSpeedMenu;
125 HMENU hCPUHistoryMenu;
126 int nActivePage;
127 int nParts[3];
128 RECT rc;
129 TCHAR szTemp[256];
130 TCITEM item;
132 SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER)));
134 /* Initialize the Windows Common Controls DLL */
135 InitCommonControls();
137 /* Get the minimum window sizes */
138 GetWindowRect(hWnd, &rc);
139 nMinimumWidth = (rc.right - rc.left);
140 nMinimumHeight = (rc.bottom - rc.top);
142 /* Create the status bar */
143 hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, _T(""), hWnd, STATUS_WINDOW);
144 if(!hStatusWnd)
145 return FALSE;
147 /* Create the status bar panes */
148 nParts[0] = 100;
149 nParts[1] = 210;
150 nParts[2] = 400;
151 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
153 /* Create tab pages */
154 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
155 #if 1
156 hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hWnd, ApplicationPageWndProc);
157 hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hWnd, ProcessPageWndProc);
158 #else
159 hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hTabWnd, ApplicationPageWndProc);
160 hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hTabWnd, ProcessPageWndProc);
161 hPerformancePage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE), hTabWnd, PerformancePageWndProc);
162 #endif
164 /* Insert tabs */
165 _tcscpy(szTemp, _T("Applications"));
166 memset(&item, 0, sizeof(TCITEM));
167 item.mask = TCIF_TEXT;
168 item.pszText = szTemp;
169 SendMessage(hTabWnd, TCM_INSERTITEM, 0, (LPARAM)&item);
170 _tcscpy(szTemp, _T("Processes"));
171 memset(&item, 0, sizeof(TCITEM));
172 item.mask = TCIF_TEXT;
173 item.pszText = szTemp;
174 SendMessage(hTabWnd, TCM_INSERTITEM, 1, (LPARAM)&item);
176 #if 0
177 _tcscpy(szTemp, _T("Performance"));
178 memset(&item, 0, sizeof(TCITEM));
179 item.mask = TCIF_TEXT;
180 item.pszText = szTemp;
181 SendMessage(hTabWnd, TCM_INSERTITEM, 2, (LPARAM)&item);
182 #endif
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 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0);
273 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1);
274 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2);
275 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage);
277 if (TaskManagerSettings.UpdateSpeed == 1)
278 SetTimer(hWnd, 1, 1000, NULL);
279 else if (TaskManagerSettings.UpdateSpeed == 2)
280 SetTimer(hWnd, 1, 2000, NULL);
281 else if (TaskManagerSettings.UpdateSpeed == 4)
282 SetTimer(hWnd, 1, 4000, NULL);
285 * Refresh the performance data
286 * Sample it twice so we can establish
287 * the delta values & cpu usage
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 SendMessage(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 SendMessage(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (long)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 TCHAR szSubKey[] = _T("Software\\Wine\\TaskManager");
378 int i;
379 DWORD dwSize;
381 /* Window size & position settings */
382 TaskManagerSettings.Maximized = FALSE;
383 TaskManagerSettings.Left = 0;
384 TaskManagerSettings.Top = 0;
385 TaskManagerSettings.Right = 0;
386 TaskManagerSettings.Bottom = 0;
388 /* Tab settings */
389 TaskManagerSettings.ActiveTabPage = 0;
391 /* Options menu settings */
392 TaskManagerSettings.AlwaysOnTop = FALSE;
393 TaskManagerSettings.MinimizeOnUse = TRUE;
394 TaskManagerSettings.HideWhenMinimized = TRUE;
395 TaskManagerSettings.Show16BitTasks = TRUE;
397 /* Update speed settings */
398 TaskManagerSettings.UpdateSpeed = 2;
400 /* Applications page settings */
401 TaskManagerSettings.View_LargeIcons = FALSE;
402 TaskManagerSettings.View_SmallIcons = FALSE;
403 TaskManagerSettings.View_Details = TRUE;
405 /* Processes page settings */
406 TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; /* Server-only? */
407 TaskManagerSettings.Column_ImageName = TRUE;
408 TaskManagerSettings.Column_PID = TRUE;
409 TaskManagerSettings.Column_CPUUsage = FALSE;
410 TaskManagerSettings.Column_CPUTime = FALSE;
411 TaskManagerSettings.Column_MemoryUsage = FALSE;
412 TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
413 TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
414 TaskManagerSettings.Column_PageFaults = FALSE;
415 TaskManagerSettings.Column_USERObjects = FALSE;
416 TaskManagerSettings.Column_IOReads = FALSE;
417 TaskManagerSettings.Column_IOReadBytes = FALSE;
418 TaskManagerSettings.Column_SessionID = FALSE; /* Server-only? */
419 TaskManagerSettings.Column_UserName = FALSE; /* Server-only? */
420 TaskManagerSettings.Column_PageFaultsDelta = FALSE;
421 TaskManagerSettings.Column_VirtualMemorySize = FALSE;
422 TaskManagerSettings.Column_PagedPool = FALSE;
423 TaskManagerSettings.Column_NonPagedPool = FALSE;
424 TaskManagerSettings.Column_BasePriority = FALSE;
425 TaskManagerSettings.Column_HandleCount = FALSE;
426 TaskManagerSettings.Column_ThreadCount = FALSE;
427 TaskManagerSettings.Column_GDIObjects = FALSE;
428 TaskManagerSettings.Column_IOWrites = FALSE;
429 TaskManagerSettings.Column_IOWriteBytes = FALSE;
430 TaskManagerSettings.Column_IOOther = FALSE;
431 TaskManagerSettings.Column_IOOtherBytes = FALSE;
433 for (i = 0; i < 25; i++) {
434 TaskManagerSettings.ColumnOrderArray[i] = i;
436 TaskManagerSettings.ColumnSizeArray[0] = 105;
437 TaskManagerSettings.ColumnSizeArray[1] = 50;
438 TaskManagerSettings.ColumnSizeArray[2] = 107;
439 TaskManagerSettings.ColumnSizeArray[3] = 70;
440 TaskManagerSettings.ColumnSizeArray[4] = 35;
441 TaskManagerSettings.ColumnSizeArray[5] = 70;
442 TaskManagerSettings.ColumnSizeArray[6] = 70;
443 TaskManagerSettings.ColumnSizeArray[7] = 100;
444 TaskManagerSettings.ColumnSizeArray[8] = 70;
445 TaskManagerSettings.ColumnSizeArray[9] = 70;
446 TaskManagerSettings.ColumnSizeArray[10] = 70;
447 TaskManagerSettings.ColumnSizeArray[11] = 70;
448 TaskManagerSettings.ColumnSizeArray[12] = 70;
449 TaskManagerSettings.ColumnSizeArray[13] = 70;
450 TaskManagerSettings.ColumnSizeArray[14] = 60;
451 TaskManagerSettings.ColumnSizeArray[15] = 60;
452 TaskManagerSettings.ColumnSizeArray[16] = 60;
453 TaskManagerSettings.ColumnSizeArray[17] = 60;
454 TaskManagerSettings.ColumnSizeArray[18] = 60;
455 TaskManagerSettings.ColumnSizeArray[19] = 70;
456 TaskManagerSettings.ColumnSizeArray[20] = 70;
457 TaskManagerSettings.ColumnSizeArray[21] = 70;
458 TaskManagerSettings.ColumnSizeArray[22] = 70;
459 TaskManagerSettings.ColumnSizeArray[23] = 70;
460 TaskManagerSettings.ColumnSizeArray[24] = 70;
462 TaskManagerSettings.SortColumn = 1;
463 TaskManagerSettings.SortAscending = TRUE;
465 /* Performance page settings */
466 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
467 TaskManagerSettings.ShowKernelTimes = FALSE;
469 /* Open the key */
470 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
471 if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
472 return;
473 /* Read the settings */
474 dwSize = sizeof(TASKMANAGER_SETTINGS);
475 RegQueryValueEx(hKey, _T("Preferences"), NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
477 /* Close the key */
478 RegCloseKey(hKey);
481 static void SaveSettings(void)
483 HKEY hKey;
484 TCHAR szSubKey3[] = _T("Software\\Wine\\TaskManager");
486 /* Open (or create) the key */
488 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
489 if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
490 return;
491 /* Save the settings */
492 RegSetValueEx(hKey, _T("Preferences"), 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
493 /* Close the key */
494 RegCloseKey(hKey);
497 static void TaskManager_OnRestoreMainWindow(void)
499 HMENU hMenu, hOptionsMenu;
500 BOOL OnTop;
502 hMenu = GetMenu(hMainWnd);
503 hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
504 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
506 OpenIcon(hMainWnd);
507 SetForegroundWindow(hMainWnd);
508 SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
511 static void TaskManager_OnEnterMenuLoop(HWND hWnd)
513 int nParts;
515 /* Update the status bar pane sizes */
516 nParts = -1;
517 SendMessage(hStatusWnd, SB_SETPARTS, 1, (long)&nParts);
518 bInMenuLoop = TRUE;
519 SendMessage(hStatusWnd, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
522 static void TaskManager_OnExitMenuLoop(HWND hWnd)
524 RECT rc;
525 int nParts[3];
526 TCHAR text[260];
528 bInMenuLoop = FALSE;
529 /* Update the status bar pane sizes */
530 GetClientRect(hWnd, &rc);
531 nParts[0] = 100;
532 nParts[1] = 210;
533 nParts[2] = rc.right;
534 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
535 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)_T(""));
536 wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
537 SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
538 wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount());
539 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
542 static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
544 TCHAR str[100];
546 _tcscpy(str, TEXT(""));
547 if (LoadString(hInst, nItemID, str, 100)) {
548 /* load appropriate string */
549 LPTSTR lpsz = str;
550 /* first newline terminates actual string */
551 lpsz = _tcschr(lpsz, '\n');
552 if (lpsz != NULL)
553 *lpsz = '\0';
555 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)str);
558 static void TaskManager_OnViewUpdateSpeedHigh(void)
560 HMENU hMenu;
561 HMENU hViewMenu;
562 HMENU hUpdateSpeedMenu;
564 hMenu = GetMenu(hMainWnd);
565 hViewMenu = GetSubMenu(hMenu, 2);
566 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
568 TaskManagerSettings.UpdateSpeed = 1;
569 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
571 KillTimer(hMainWnd, 1);
572 SetTimer(hMainWnd, 1, 1000, NULL);
575 static void TaskManager_OnViewUpdateSpeedNormal(void)
577 HMENU hMenu;
578 HMENU hViewMenu;
579 HMENU hUpdateSpeedMenu;
581 hMenu = GetMenu(hMainWnd);
582 hViewMenu = GetSubMenu(hMenu, 2);
583 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
585 TaskManagerSettings.UpdateSpeed = 2;
586 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
588 KillTimer(hMainWnd, 1);
589 SetTimer(hMainWnd, 1, 2000, NULL);
592 static void TaskManager_OnViewUpdateSpeedLow(void)
594 HMENU hMenu;
595 HMENU hViewMenu;
596 HMENU hUpdateSpeedMenu;
598 hMenu = GetMenu(hMainWnd);
599 hViewMenu = GetSubMenu(hMenu, 2);
600 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
602 TaskManagerSettings.UpdateSpeed = 4;
603 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
605 KillTimer(hMainWnd, 1);
606 SetTimer(hMainWnd, 1, 4000, NULL);
609 static void TaskManager_OnViewUpdateSpeedPaused(void)
611 HMENU hMenu;
612 HMENU hViewMenu;
613 HMENU hUpdateSpeedMenu;
615 hMenu = GetMenu(hMainWnd);
616 hViewMenu = GetSubMenu(hMenu, 2);
617 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
618 TaskManagerSettings.UpdateSpeed = 0;
619 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
620 KillTimer(hMainWnd, 1);
623 static void TaskManager_OnTabWndSelChange(void)
625 int i;
626 HMENU hMenu;
627 HMENU hOptionsMenu;
628 HMENU hViewMenu;
629 HMENU hSubMenu;
631 hMenu = GetMenu(hMainWnd);
632 hViewMenu = GetSubMenu(hMenu, 2);
633 hOptionsMenu = GetSubMenu(hMenu, 1);
634 TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
635 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
636 hSubMenu = GetSubMenu(hViewMenu, i);
637 if (hSubMenu)
638 DestroyMenu(hSubMenu);
639 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
641 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
642 switch (TaskManagerSettings.ActiveTabPage) {
643 case 0:
644 ShowWindow(hApplicationPage, SW_SHOW);
645 ShowWindow(hProcessPage, SW_HIDE);
646 ShowWindow(hPerformancePage, SW_HIDE);
647 BringWindowToTop(hApplicationPage);
648 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_LARGE, _T("Lar&ge Icons"));
649 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SMALL, _T("S&mall Icons"));
650 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_DETAILS, _T("&Details"));
652 if (GetMenuItemCount(hMenu) <= 4) {
653 hSubMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWSMENU));
654 InsertMenu(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, _T("&Windows"));
655 DrawMenuBar(hMainWnd);
657 if (TaskManagerSettings.View_LargeIcons)
658 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
659 else if (TaskManagerSettings.View_SmallIcons)
660 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
661 else
662 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
664 * Give the application list control focus
666 SetFocus(hApplicationPageListCtrl);
667 break;
669 case 1:
670 ShowWindow(hApplicationPage, SW_HIDE);
671 ShowWindow(hProcessPage, SW_SHOW);
672 ShowWindow(hPerformancePage, SW_HIDE);
673 BringWindowToTop(hProcessPage);
674 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, _T("&Select Columns..."));
675 AppendMenu(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, _T("&Show 16-bit tasks"));
676 if (TaskManagerSettings.Show16BitTasks)
677 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
678 if (GetMenuItemCount(hMenu) > 4)
680 RemoveMenu(hMenu, 3, MF_BYPOSITION);
681 DrawMenuBar(hMainWnd);
684 * Give the process list control focus
686 SetFocus(hProcessPageListCtrl);
687 break;
689 case 2:
690 ShowWindow(hApplicationPage, SW_HIDE);
691 ShowWindow(hProcessPage, SW_HIDE);
692 ShowWindow(hPerformancePage, SW_SHOW);
693 BringWindowToTop(hPerformancePage);
694 if (GetMenuItemCount(hMenu) > 4) {
695 RemoveMenu(hMenu, 3, MF_BYPOSITION);
696 DrawMenuBar(hMainWnd);
698 hSubMenu = CreatePopupMenu();
699 AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, _T("&One Graph, All CPUs"));
700 AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, _T("One Graph &Per CPU"));
701 AppendMenu(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, _T("&CPU History"));
702 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, _T("&Show Kernel Times"));
703 if (TaskManagerSettings.ShowKernelTimes)
704 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
705 else
706 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
707 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
708 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
709 else
710 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
712 * Give the tab control focus
714 SetFocus(hTabWnd);
715 break;
719 LPTSTR GetLastErrorText(LPTSTR lpszBuf, DWORD dwSize)
721 DWORD dwRet;
722 LPTSTR lpszTemp = NULL;
724 dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
725 NULL,
726 GetLastError(),
727 LANG_NEUTRAL,
728 (LPTSTR)&lpszTemp,
730 NULL );
732 /* supplied buffer is not long enough */
733 if (!dwRet || ( (long)dwSize < (long)dwRet+14)) {
734 lpszBuf[0] = TEXT('\0');
735 } else {
736 lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); /* remove cr and newline character */
737 _stprintf(lpszBuf, TEXT("%s (%u)"), lpszTemp, GetLastError());
739 if (lpszTemp) {
740 LocalFree((HLOCAL)lpszTemp);
742 return lpszBuf;
745 /* Message handler for dialog box. */
746 static INT_PTR CALLBACK
747 TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
749 HDC hdc;
750 PAINTSTRUCT ps;
751 LPRECT pRC;
752 RECT rc;
753 int idctrl;
754 LPNMHDR pnmh;
755 WINDOWPLACEMENT wp;
757 switch (message) {
758 case WM_INITDIALOG:
759 hMainWnd = hDlg;
760 return OnCreate(hDlg);
762 case WM_COMMAND:
763 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
764 EndDialog(hDlg, LOWORD(wParam));
765 return TRUE;
767 /* Process menu commands */
768 switch (LOWORD(wParam))
770 case ID_FILE_NEW:
771 TaskManager_OnFileNew();
772 break;
773 case ID_OPTIONS_ALWAYSONTOP:
774 TaskManager_OnOptionsAlwaysOnTop();
775 break;
776 case ID_OPTIONS_MINIMIZEONUSE:
777 TaskManager_OnOptionsMinimizeOnUse();
778 break;
779 case ID_OPTIONS_HIDEWHENMINIMIZED:
780 TaskManager_OnOptionsHideWhenMinimized();
781 break;
782 case ID_OPTIONS_SHOW16BITTASKS:
783 TaskManager_OnOptionsShow16BitTasks();
784 break;
785 case ID_RESTORE:
786 TaskManager_OnRestoreMainWindow();
787 break;
788 case ID_VIEW_LARGE:
789 ApplicationPage_OnViewLargeIcons();
790 break;
791 case ID_VIEW_SMALL:
792 ApplicationPage_OnViewSmallIcons();
793 break;
794 case ID_VIEW_DETAILS:
795 ApplicationPage_OnViewDetails();
796 break;
797 case ID_VIEW_SHOWKERNELTIMES:
798 PerformancePage_OnViewShowKernelTimes();
799 break;
800 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
801 PerformancePage_OnViewCPUHistoryOneGraphAll();
802 break;
803 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
804 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
805 break;
806 case ID_VIEW_UPDATESPEED_HIGH:
807 TaskManager_OnViewUpdateSpeedHigh();
808 break;
809 case ID_VIEW_UPDATESPEED_NORMAL:
810 TaskManager_OnViewUpdateSpeedNormal();
811 break;
812 case ID_VIEW_UPDATESPEED_LOW:
813 TaskManager_OnViewUpdateSpeedLow();
814 break;
815 case ID_VIEW_UPDATESPEED_PAUSED:
816 TaskManager_OnViewUpdateSpeedPaused();
817 break;
818 case ID_VIEW_SELECTCOLUMNS:
819 ProcessPage_OnViewSelectColumns();
820 break;
821 case ID_VIEW_REFRESH:
822 PostMessage(hDlg, WM_TIMER, 0, 0);
823 break;
824 case ID_WINDOWS_TILEHORIZONTALLY:
825 ApplicationPage_OnWindowsTileHorizontally();
826 break;
827 case ID_WINDOWS_TILEVERTICALLY:
828 ApplicationPage_OnWindowsTileVertically();
829 break;
830 case ID_WINDOWS_MINIMIZE:
831 ApplicationPage_OnWindowsMinimize();
832 break;
833 case ID_WINDOWS_MAXIMIZE:
834 ApplicationPage_OnWindowsMaximize();
835 break;
836 case ID_WINDOWS_CASCADE:
837 ApplicationPage_OnWindowsCascade();
838 break;
839 case ID_WINDOWS_BRINGTOFRONT:
840 ApplicationPage_OnWindowsBringToFront();
841 break;
842 case ID_APPLICATION_PAGE_SWITCHTO:
843 ApplicationPage_OnSwitchTo();
844 break;
845 case ID_APPLICATION_PAGE_ENDTASK:
846 ApplicationPage_OnEndTask();
847 break;
848 case ID_APPLICATION_PAGE_GOTOPROCESS:
849 ApplicationPage_OnGotoProcess();
850 break;
851 case ID_PROCESS_PAGE_ENDPROCESS:
852 ProcessPage_OnEndProcess();
853 break;
854 case ID_PROCESS_PAGE_ENDPROCESSTREE:
855 ProcessPage_OnEndProcessTree();
856 break;
857 case ID_PROCESS_PAGE_DEBUG:
858 ProcessPage_OnDebug();
859 break;
860 case ID_PROCESS_PAGE_SETAFFINITY:
861 ProcessPage_OnSetAffinity();
862 break;
863 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
864 ProcessPage_OnSetPriorityRealTime();
865 break;
866 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
867 ProcessPage_OnSetPriorityHigh();
868 break;
869 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
870 ProcessPage_OnSetPriorityAboveNormal();
871 break;
872 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
873 ProcessPage_OnSetPriorityNormal();
874 break;
875 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
876 ProcessPage_OnSetPriorityBelowNormal();
877 break;
878 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
879 ProcessPage_OnSetPriorityLow();
880 break;
881 case ID_PROCESS_PAGE_DEBUGCHANNELS:
882 ProcessPage_OnDebugChannels();
883 break;
884 case ID_HELP_ABOUT:
885 OnAbout();
886 break;
887 case ID_FILE_EXIT:
888 EndDialog(hDlg, IDOK);
889 break;
891 break;
893 case WM_ONTRAYICON:
894 switch(lParam)
896 case WM_RBUTTONDOWN:
898 POINT pt;
899 BOOL OnTop;
900 HMENU hMenu, hPopupMenu;
902 GetCursorPos(&pt);
904 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
906 hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_TRAY_POPUP));
907 hPopupMenu = GetSubMenu(hMenu, 0);
909 if(IsWindowVisible(hMainWnd))
911 DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
913 else
915 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
918 if(OnTop)
920 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
923 SetForegroundWindow(hMainWnd);
924 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
926 DestroyMenu(hMenu);
927 break;
929 case WM_LBUTTONDBLCLK:
930 TaskManager_OnRestoreMainWindow();
931 break;
933 break;
935 case WM_NOTIFY:
936 idctrl = (int)wParam;
937 pnmh = (LPNMHDR)lParam;
938 if ((pnmh->hwndFrom == hTabWnd) &&
939 (pnmh->idFrom == IDC_TAB) &&
940 (pnmh->code == TCN_SELCHANGE))
942 TaskManager_OnTabWndSelChange();
944 break;
946 case WM_NCPAINT:
947 hdc = GetDC(hDlg);
948 GetClientRect(hDlg, &rc);
949 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
950 ReleaseDC(hDlg, hdc);
951 break;
953 case WM_PAINT:
954 hdc = BeginPaint(hDlg, &ps);
955 GetClientRect(hDlg, &rc);
956 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
957 EndPaint(hDlg, &ps);
958 break;
960 case WM_SIZING:
961 /* Make sure the user is sizing the dialog */
962 /* in an acceptable range */
963 pRC = (LPRECT)lParam;
964 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
965 /* If the width is too small enlarge it to the minimum */
966 if (nMinimumWidth > (pRC->right - pRC->left))
967 pRC->left = pRC->right - nMinimumWidth;
968 } else {
969 /* If the width is too small enlarge it to the minimum */
970 if (nMinimumWidth > (pRC->right - pRC->left))
971 pRC->right = pRC->left + nMinimumWidth;
973 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
974 /* If the height is too small enlarge it to the minimum */
975 if (nMinimumHeight > (pRC->bottom - pRC->top))
976 pRC->top = pRC->bottom - nMinimumHeight;
977 } else {
978 /* If the height is too small enlarge it to the minimum */
979 if (nMinimumHeight > (pRC->bottom - pRC->top))
980 pRC->bottom = pRC->top + nMinimumHeight;
982 return TRUE;
983 break;
985 case WM_SIZE:
986 /* Handle the window sizing in it's own function */
987 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
988 break;
990 case WM_MOVE:
991 /* Handle the window moving in it's own function */
992 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
993 break;
995 case WM_DESTROY:
996 ShowWindow(hDlg, SW_HIDE);
997 TrayIcon_ShellRemoveTrayIcon();
998 wp.length = sizeof(WINDOWPLACEMENT);
999 GetWindowPlacement(hDlg, &wp);
1000 TaskManagerSettings.Left = wp.rcNormalPosition.left;
1001 TaskManagerSettings.Top = wp.rcNormalPosition.top;
1002 TaskManagerSettings.Right = wp.rcNormalPosition.right;
1003 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
1004 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
1005 TaskManagerSettings.Maximized = TRUE;
1006 else
1007 TaskManagerSettings.Maximized = FALSE;
1008 return DefWindowProc(hDlg, message, wParam, lParam);
1010 case WM_TIMER:
1011 /* Refresh the performance data */
1012 PerfDataRefresh();
1013 RefreshApplicationPage();
1014 RefreshProcessPage();
1015 RefreshPerformancePage();
1016 TrayIcon_ShellUpdateTrayIcon();
1017 break;
1019 case WM_ENTERMENULOOP:
1020 TaskManager_OnEnterMenuLoop(hDlg);
1021 break;
1022 case WM_EXITMENULOOP:
1023 TaskManager_OnExitMenuLoop(hDlg);
1024 break;
1025 case WM_MENUSELECT:
1026 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
1027 break;
1030 return 0;
1033 int APIENTRY WinMain(HINSTANCE hInstance,
1034 HINSTANCE hPrevInstance,
1035 LPSTR lpCmdLine,
1036 int nCmdShow)
1038 HANDLE hProcess;
1039 HANDLE hToken;
1040 TOKEN_PRIVILEGES tkp;
1042 /* Initialize global variables */
1043 hInst = hInstance;
1045 /* Change our priority class to HIGH */
1046 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
1047 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
1048 CloseHandle(hProcess);
1050 /* Now let's get the SE_DEBUG_NAME privilege
1051 * so that we can debug processes
1054 /* Get a token for this process. */
1055 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
1056 /* Get the LUID for the debug privilege. */
1057 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
1059 tkp.PrivilegeCount = 1; /* one privilege to set */
1060 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1062 /* Get the debug privilege for this process. */
1063 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
1066 /* Load our settings from the registry */
1067 LoadSettings();
1069 /* Initialize perf data */
1070 if (!PerfDataInitialize()) {
1071 return -1;
1074 DialogBox(hInst, (LPCTSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
1076 /* Save our settings to the registry */
1077 SaveSettings();
1078 PerfDataUninitialize();
1079 return 0;