Rudimentiary drivebar support added.
[reactos.git] / rosapps / taskmgr / TASKMGR.cpp
1 // TaskMgr.cpp : Defines the entry point for the application.
2 //
3
4 #ifdef _MSC_VER
5 #include "stdafx.h"
6 #else
7 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
8 #include <windows.h>
9 #include <commctrl.h>
10 #include <stdlib.h>
11 #include <malloc.h>
12 #include <memory.h>
13 #include <tchar.h>
14 #include <process.h>
15 #include <stdio.h>
16 #endif
17
18 #include "resource.h"
19 #include "TaskMgr.h"
20 #include "ApplicationPage.h"
21 #include "ProcessPage.h"
22 #include "PerformancePage.h"
23 #include "run.h"
24 #include "perfdata.h"
25 #include "optnmenu.h"
26 #include "affinity.h"
27 #include "priority.h"
28 #include "debug.h"
29 #include "endproc.h"
30 #include "column.h"
31 #include "about.h"
32 #include "trayicon.h"
33
34 #define STATUS_WINDOW 2001
35
36 // Global Variables:
37 HINSTANCE hInst; // current instance
38
39 HWND hMainWnd; // Main Window
40 HWND hStatusWnd; // Status Bar Window
41 HWND hTabWnd; // Tab Control Window
42
43 int nMinimumWidth; // Minimum width of the dialog (OnSize()'s cx)
44 int nMinimumHeight; // Minimum height of the dialog (OnSize()'s cy)
45
46 int nOldWidth; // Holds the previous client area width
47 int nOldHeight; // Holds the previous client area height
48
49 BOOL bInMenuLoop = FALSE; // Tells us if we are in the menu loop
50
51 TASKMANAGER_SETTINGS TaskManagerSettings;
52
53
54 int APIENTRY WinMain(HINSTANCE hInstance,
55 HINSTANCE hPrevInstance,
56 LPSTR lpCmdLine,
57 int nCmdShow)
58 {
59 // Initialize global variables
60 hInst = hInstance;
61
62 // Change our priority class to HIGH
63 HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
64 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
65 CloseHandle(hProcess);
66
67 // Now lets get the SE_DEBUG_NAME priviledge
68 // so that we can debug processes
69 HANDLE hToken;
70 TOKEN_PRIVILEGES tkp;
71
72 // Get a token for this process.
73 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
74 {
75 // Get the LUID for the debug privilege.
76 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
77
78 tkp.PrivilegeCount = 1; // one privilege to set
79 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
80
81 // Get the debug privilege for this process.
82 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
83 }
84
85 // Load our settings from the registry
86 LoadSettings();
87
88 // Initialize perf data
89 if (!PerfDataInitialize()) {
90 return -1;
91 }
92
93 DialogBox(hInst, (LPCTSTR)IDD_TASKMGR_DIALOG, NULL, (DLGPROC)TaskManagerWndProc);
94
95 // Save our settings to the registry
96 SaveSettings();
97 PerfDataUninitialize();
98 return 0;
99 }
100
101 #define _USE_CMD_MAP
102
103 #ifdef _USE_CMD_MAP
104 #define BEGIN_CMD_MAP(a) switch(##a) {
105 #define CMD_MAP_ENTRY(a, b) case a: b(); break;
106 #define END_CMD_MAP(a) }
107
108 #endif
109
110 // Message handler for dialog box.
111 LRESULT CALLBACK TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
112 {
113 HDC hdc;
114 PAINTSTRUCT ps;
115 LPRECT pRC;
116 RECT rc;
117
118 switch (message)
119 {
120 case WM_INITDIALOG:
121 hMainWnd = hDlg;
122 return OnCreate(hDlg);
123
124 case WM_COMMAND:
125 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
126 EndDialog(hDlg, LOWORD(wParam));
127 return TRUE;
128 }
129 #ifdef _USE_CMD_MAP
130 BEGIN_CMD_MAP(LOWORD(wParam))
131 CMD_MAP_ENTRY(ID_FILE_NEW, TaskManager_OnFileNew)
132 CMD_MAP_ENTRY(ID_OPTIONS_ALWAYSONTOP, TaskManager_OnOptionsAlwaysOnTop)
133 CMD_MAP_ENTRY(ID_OPTIONS_MINIMIZEONUSE, TaskManager_OnOptionsMinimizeOnUse)
134 CMD_MAP_ENTRY(ID_OPTIONS_HIDEWHENMINIMIZED, TaskManager_OnOptionsHideWhenMinimized)
135 CMD_MAP_ENTRY(ID_OPTIONS_SHOW16BITTASKS, TaskManager_OnOptionsShow16BitTasks)
136 CMD_MAP_ENTRY(ID_VIEW_LARGE, ApplicationPage_OnViewLargeIcons)
137 CMD_MAP_ENTRY(ID_VIEW_SMALL, ApplicationPage_OnViewSmallIcons)
138 CMD_MAP_ENTRY(ID_VIEW_DETAILS, ApplicationPage_OnViewDetails)
139 CMD_MAP_ENTRY(ID_VIEW_SHOWKERNELTIMES, PerformancePage_OnViewShowKernelTimes)
140 CMD_MAP_ENTRY(ID_VIEW_CPUHISTORY_ONEGRAPHALL, PerformancePage_OnViewCPUHistoryOneGraphAll)
141 CMD_MAP_ENTRY(ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, PerformancePage_OnViewCPUHistoryOneGraphPerCPU)
142 CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_HIGH, TaskManager_OnViewUpdateSpeedHigh)
143 CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_NORMAL, TaskManager_OnViewUpdateSpeedNormal)
144 CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_LOW, TaskManager_OnViewUpdateSpeedLow)
145 CMD_MAP_ENTRY(ID_VIEW_UPDATESPEED_PAUSED, TaskManager_OnViewUpdateSpeedPaused)
146 CMD_MAP_ENTRY(ID_VIEW_SELECTCOLUMNS, ProcessPage_OnViewSelectColumns)
147 CMD_MAP_ENTRY(ID_VIEW_REFRESH, TaskManager_OnViewRefresh)
148 CMD_MAP_ENTRY(ID_WINDOWS_TILEHORIZONTALLY, ApplicationPage_OnWindowsTileHorizontally)
149 CMD_MAP_ENTRY(ID_WINDOWS_TILEVERTICALLY, ApplicationPage_OnWindowsTileVertically)
150 CMD_MAP_ENTRY(ID_WINDOWS_MINIMIZE, ApplicationPage_OnWindowsMinimize)
151 CMD_MAP_ENTRY(ID_WINDOWS_MAXIMIZE, ApplicationPage_OnWindowsMaximize)
152 CMD_MAP_ENTRY(ID_WINDOWS_CASCADE, ApplicationPage_OnWindowsCascade)
153 CMD_MAP_ENTRY(ID_WINDOWS_BRINGTOFRONT, ApplicationPage_OnWindowsBringToFront)
154 CMD_MAP_ENTRY(ID_APPLICATION_PAGE_SWITCHTO, ApplicationPage_OnSwitchTo)
155 CMD_MAP_ENTRY(ID_APPLICATION_PAGE_ENDTASK, ApplicationPage_OnEndTask)
156 CMD_MAP_ENTRY(ID_APPLICATION_PAGE_GOTOPROCESS, ApplicationPage_OnGotoProcess)
157 CMD_MAP_ENTRY(ID_PROCESS_PAGE_ENDPROCESS, ProcessPage_OnEndProcess)
158 CMD_MAP_ENTRY(ID_PROCESS_PAGE_ENDPROCESSTREE, ProcessPage_OnEndProcessTree)
159 CMD_MAP_ENTRY(ID_PROCESS_PAGE_DEBUG, ProcessPage_OnDebug)
160 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETAFFINITY, ProcessPage_OnSetAffinity)
161 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ProcessPage_OnSetPriorityRealTime)
162 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_HIGH, ProcessPage_OnSetPriorityHigh)
163 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, ProcessPage_OnSetPriorityAboveNormal)
164 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_NORMAL, ProcessPage_OnSetPriorityNormal)
165 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, ProcessPage_OnSetPriorityBelowNormal)
166 CMD_MAP_ENTRY(ID_PROCESS_PAGE_SETPRIORITY_LOW, ProcessPage_OnSetPriorityLow)
167 CMD_MAP_ENTRY(ID_HELP_ABOUT, OnAbout)
168 END_CMD_MAP(0)
169 #else
170 // Process menu commands
171 switch (LOWORD(wParam))
172 {
173 case ID_FILE_NEW:
174 TaskManager_OnFileNew();
175 break;
176 case ID_OPTIONS_ALWAYSONTOP:
177 TaskManager_OnOptionsAlwaysOnTop();
178 break;
179 case ID_OPTIONS_MINIMIZEONUSE:
180 TaskManager_OnOptionsMinimizeOnUse();
181 break;
182 case ID_OPTIONS_HIDEWHENMINIMIZED:
183 TaskManager_OnOptionsHideWhenMinimized();
184 break;
185 case ID_OPTIONS_SHOW16BITTASKS:
186 TaskManager_OnOptionsShow16BitTasks();
187 break;
188 case ID_VIEW_LARGE:
189 ApplicationPage_OnViewLargeIcons();
190 break;
191 case ID_VIEW_SMALL:
192 ApplicationPage_OnViewSmallIcons();
193 break;
194 case ID_VIEW_DETAILS:
195 ApplicationPage_OnViewDetails();
196 break;
197 case ID_VIEW_SHOWKERNELTIMES:
198 PerformancePage_OnViewShowKernelTimes();
199 break;
200 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
201 PerformancePage_OnViewCPUHistoryOneGraphAll();
202 break;
203 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
204 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
205 break;
206 case ID_VIEW_UPDATESPEED_HIGH:
207 TaskManager_OnViewUpdateSpeedHigh();
208 break;
209 case ID_VIEW_UPDATESPEED_NORMAL:
210 TaskManager_OnViewUpdateSpeedNormal();
211 break;
212 case ID_VIEW_UPDATESPEED_LOW:
213 TaskManager_OnViewUpdateSpeedLow();
214 break;
215 case ID_VIEW_UPDATESPEED_PAUSED:
216 TaskManager_OnViewUpdateSpeedPaused();
217 break;
218 case ID_VIEW_SELECTCOLUMNS:
219 ProcessPage_OnViewSelectColumns();
220 break;
221 case ID_VIEW_REFRESH:
222 PostMessage(hDlg, WM_TIMER, 0, 0);
223 break;
224 case ID_WINDOWS_TILEHORIZONTALLY:
225 ApplicationPage_OnWindowsTileHorizontally();
226 break;
227 case ID_WINDOWS_TILEVERTICALLY:
228 ApplicationPage_OnWindowsTileVertically();
229 break;
230 case ID_WINDOWS_MINIMIZE:
231 ApplicationPage_OnWindowsMinimize();
232 break;
233 case ID_WINDOWS_MAXIMIZE:
234 ApplicationPage_OnWindowsMaximize();
235 break;
236 case ID_WINDOWS_CASCADE:
237 ApplicationPage_OnWindowsCascade();
238 break;
239 case ID_WINDOWS_BRINGTOFRONT:
240 ApplicationPage_OnWindowsBringToFront();
241 break;
242 case ID_APPLICATION_PAGE_SWITCHTO:
243 ApplicationPage_OnSwitchTo();
244 break;
245 case ID_APPLICATION_PAGE_ENDTASK:
246 ApplicationPage_OnEndTask();
247 break;
248 case ID_APPLICATION_PAGE_GOTOPROCESS:
249 ApplicationPage_OnGotoProcess();
250 break;
251 case ID_PROCESS_PAGE_ENDPROCESS:
252 ProcessPage_OnEndProcess();
253 break;
254 case ID_PROCESS_PAGE_ENDPROCESSTREE:
255 ProcessPage_OnEndProcessTree();
256 break;
257 case ID_PROCESS_PAGE_DEBUG:
258 ProcessPage_OnDebug();
259 break;
260 case ID_PROCESS_PAGE_SETAFFINITY:
261 ProcessPage_OnSetAffinity();
262 break;
263 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
264 ProcessPage_OnSetPriorityRealTime();
265 break;
266 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
267 ProcessPage_OnSetPriorityHigh();
268 break;
269 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
270 ProcessPage_OnSetPriorityAboveNormal();
271 break;
272 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
273 ProcessPage_OnSetPriorityNormal();
274 break;
275 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
276 ProcessPage_OnSetPriorityBelowNormal();
277 break;
278 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
279 ProcessPage_OnSetPriorityLow();
280 break;
281 case ID_HELP_ABOUT:
282 OnAbout();
283 break;
284 }
285 #endif
286 break;
287
288 case WM_NOTIFY:
289 int idctrl;
290 LPNMHDR pnmh;
291 idctrl = (int)wParam;
292 pnmh = (LPNMHDR)lParam;
293 if ((pnmh->hwndFrom == hTabWnd) &&
294 (pnmh->idFrom == IDC_TAB) &&
295 (pnmh->code == TCN_SELCHANGE))
296 {
297 TaskManager_OnTabWndSelChange();
298 }
299 break;
300
301 case WM_NCPAINT:
302 hdc = GetDC(hDlg);
303 GetClientRect(hDlg, &rc);
304 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
305 ReleaseDC(hDlg, hdc);
306 break;
307
308 case WM_PAINT:
309 hdc = BeginPaint(hDlg, &ps);
310 GetClientRect(hDlg, &rc);
311 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
312 EndPaint(hDlg, &ps);
313 break;
314
315 case WM_SIZING:
316 // Make sure the user is sizing the dialog
317 // in an acceptable range
318 pRC = (LPRECT)lParam;
319 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
320 // If the width is too small enlarge it to the minimum
321 if (nMinimumWidth > (pRC->right - pRC->left))
322 pRC->left = pRC->right - nMinimumWidth;
323 } else {
324 // If the width is too small enlarge it to the minimum
325 if (nMinimumWidth > (pRC->right - pRC->left))
326 pRC->right = pRC->left + nMinimumWidth;
327 }
328 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
329 // If the height is too small enlarge it to the minimum
330 if (nMinimumHeight > (pRC->bottom - pRC->top))
331 pRC->top = pRC->bottom - nMinimumHeight;
332 } else {
333 // If the height is too small enlarge it to the minimum
334 if (nMinimumHeight > (pRC->bottom - pRC->top))
335 pRC->bottom = pRC->top + nMinimumHeight;
336 }
337 return TRUE;
338 break;
339
340 case WM_SIZE:
341 // Handle the window sizing in it's own function
342 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
343 break;
344
345 case WM_MOVE:
346 // Handle the window moving in it's own function
347 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
348 break;
349
350 case WM_DESTROY:
351 WINDOWPLACEMENT wp;
352 ShowWindow(hDlg, SW_HIDE);
353 TrayIcon_ShellRemoveTrayIcon();
354 wp.length = sizeof(WINDOWPLACEMENT);
355 GetWindowPlacement(hDlg, &wp);
356 TaskManagerSettings.Left = wp.rcNormalPosition.left;
357 TaskManagerSettings.Top = wp.rcNormalPosition.top;
358 TaskManagerSettings.Right = wp.rcNormalPosition.right;
359 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
360 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
361 TaskManagerSettings.Maximized = TRUE;
362 else
363 TaskManagerSettings.Maximized = FALSE;
364 return DefWindowProc(hDlg, message, wParam, lParam);
365
366 case WM_TIMER:
367 // Refresh the performance data
368 PerfDataRefresh();
369 RefreshApplicationPage();
370 RefreshProcessPage();
371 RefreshPerformancePage();
372 TrayIcon_ShellUpdateTrayIcon();
373 break;
374
375 case WM_ENTERMENULOOP:
376 TaskManager_OnEnterMenuLoop(hDlg);
377 break;
378 case WM_EXITMENULOOP:
379 TaskManager_OnExitMenuLoop(hDlg);
380 break;
381 case WM_MENUSELECT:
382 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
383 break;
384 }
385
386 return 0;
387 }
388
389 void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
390 {
391 SetBkColor(hDC, clr);
392 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
393 }
394
395 void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
396 {
397
398 SetBkColor(hDC, clr);
399 RECT rect;
400 rect.left = x;
401 rect.top = y;
402 rect.right = x + cx;
403 rect.bottom = y + cy;
404 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
405 }
406
407 void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
408 {
409 FillSolidRect(hDC, x, y, cx - 1, 1, clrTopLeft);
410 FillSolidRect(hDC, x, y, 1, cy - 1, clrTopLeft);
411 FillSolidRect(hDC, x + cx, y, -1, cy, clrBottomRight);
412 FillSolidRect(hDC, x, y + cy, cx, -1, clrBottomRight);
413 }
414
415 void Draw3dRect(HDC hDC, LPRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight)
416 {
417 Draw3dRect(hDC, lpRect->left, lpRect->top, lpRect->right - lpRect->left,
418 lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight);
419 }
420
421 BOOL OnCreate(HWND hWnd)
422 {
423 int nParts[3];
424 RECT rc;
425 char szTemp[256];
426 TCITEM item;
427
428 SendMessage(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER)));
429
430 // Initialize the Windows Common Controls DLL
431 InitCommonControls();
432
433 // Get the minimum window sizes
434 GetWindowRect(hWnd, &rc);
435 nMinimumWidth = (rc.right - rc.left);
436 nMinimumHeight = (rc.bottom - rc.top);
437
438 // Create the status bar
439 hStatusWnd = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, "", hWnd, STATUS_WINDOW);
440 if(!hStatusWnd)
441 return FALSE;
442
443 // Create the status bar panes
444 nParts[0] = 100;
445 nParts[1] = 210;
446 nParts[2] = 400;
447 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
448
449 // Create tab pages
450 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
451 #if 1
452 hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hWnd, (DLGPROC)ApplicationPageWndProc);
453 hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hWnd, (DLGPROC)ProcessPageWndProc);
454 hPerformancePage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE), hWnd, (DLGPROC)PerformancePageWndProc);
455 #else
456 hApplicationPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_APPLICATION_PAGE), hTabWnd, (DLGPROC)ApplicationPageWndProc);
457 hProcessPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROCESS_PAGE), hTabWnd, (DLGPROC)ProcessPageWndProc);
458 hPerformancePage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE), hTabWnd, (DLGPROC)PerformancePageWndProc);
459 #endif
460 // Insert tabs
461 strcpy(szTemp, "Applications");
462 memset(&item, 0, sizeof(TCITEM));
463 item.mask = TCIF_TEXT;
464 item.pszText = szTemp;
465 TabCtrl_InsertItem(hTabWnd, 0, &item);
466 strcpy(szTemp, "Processes");
467 memset(&item, 0, sizeof(TCITEM));
468 item.mask = TCIF_TEXT;
469 item.pszText = szTemp;
470 TabCtrl_InsertItem(hTabWnd, 1, &item);
471 strcpy(szTemp, "Performance");
472 memset(&item, 0, sizeof(TCITEM));
473 item.mask = TCIF_TEXT;
474 item.pszText = szTemp;
475 TabCtrl_InsertItem(hTabWnd, 2, &item);
476
477 // Size everything correctly
478 GetClientRect(hWnd, &rc);
479 nOldWidth = rc.right;
480 nOldHeight = rc.bottom;
481 //nOldStartX = rc.left;
482 //nOldStartY = rc.top;
483
484 #define PAGE_OFFSET_LEFT 17
485 #define PAGE_OFFSET_TOP 72
486 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
487 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
488
489 if ((TaskManagerSettings.Left != 0) ||
490 (TaskManagerSettings.Top != 0) ||
491 (TaskManagerSettings.Right != 0) ||
492 (TaskManagerSettings.Bottom != 0))
493 {
494 MoveWindow(hWnd, TaskManagerSettings.Left, TaskManagerSettings.Top, TaskManagerSettings.Right - TaskManagerSettings.Left, TaskManagerSettings.Bottom - TaskManagerSettings.Top, TRUE);
495 #ifdef GCC
496 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);
497 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);
498 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);
499 #endif
500 }
501 if (TaskManagerSettings.Maximized)
502 ShowWindow(hWnd, SW_MAXIMIZE);
503
504 // Set the always on top style
505 HMENU hMenu;
506 HMENU hEditMenu;
507 HMENU hViewMenu;
508 HMENU hUpdateSpeedMenu;
509 HMENU hCPUHistoryMenu;
510
511 hMenu = GetMenu(hWnd);
512 hEditMenu = GetSubMenu(hMenu, 1);
513 hViewMenu = GetSubMenu(hMenu, 2);
514 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
515 hCPUHistoryMenu = GetSubMenu(hViewMenu, 7);
516
517 // Check or uncheck the always on top menu item
518 if (TaskManagerSettings.AlwaysOnTop) {
519 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_CHECKED);
520 SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
521 } else {
522 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
523 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
524 }
525
526 // Check or uncheck the minimize on use menu item
527 if (TaskManagerSettings.MinimizeOnUse)
528 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
529 else
530 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
531
532 // Check or uncheck the hide when minimized menu item
533 if (TaskManagerSettings.HideWhenMinimized)
534 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
535 else
536 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
537
538 // Check or uncheck the show 16-bit tasks menu item
539 if (TaskManagerSettings.Show16BitTasks)
540 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
541 else
542 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
543
544 if (TaskManagerSettings.View_LargeIcons)
545 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
546 else if (TaskManagerSettings.View_SmallIcons)
547 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
548 else
549 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
550
551 if (TaskManagerSettings.ShowKernelTimes)
552 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
553 else
554 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
555
556 if (TaskManagerSettings.UpdateSpeed == 1)
557 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
558 else if (TaskManagerSettings.UpdateSpeed == 2)
559 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
560 else if (TaskManagerSettings.UpdateSpeed == 4)
561 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
562 else
563 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
564
565 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
566 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
567 else
568 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
569
570 int nActivePage = TaskManagerSettings.ActiveTabPage;
571 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 0);
572 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 1);
573 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, 2);
574 TabCtrl_SetCurFocus/*Sel*/(hTabWnd, nActivePage);
575
576 if (TaskManagerSettings.UpdateSpeed == 0)
577 KillTimer(hWnd, 1);
578 else if (TaskManagerSettings.UpdateSpeed == 1)
579 {
580 KillTimer(hWnd, 1);
581 SetTimer(hWnd, 1, 1000, NULL);
582 }
583 else if (TaskManagerSettings.UpdateSpeed == 2)
584 {
585 KillTimer(hWnd, 1);
586 SetTimer(hWnd, 1, 2000, NULL);
587 }
588 else if (TaskManagerSettings.UpdateSpeed == 4)
589 {
590 KillTimer(hWnd, 1);
591 SetTimer(hWnd, 1, 4000, NULL);
592 }
593
594 //
595 // Refresh the performance data
596 // Sample it twice so we can establish
597 // the delta values & cpu usage
598 //
599 PerfDataRefresh();
600 PerfDataRefresh();
601
602 RefreshApplicationPage();
603 RefreshProcessPage();
604 RefreshPerformancePage();
605
606 TrayIcon_ShellAddTrayIcon();
607
608 return TRUE;
609 }
610
611 // OnMove()
612 // This function handles all the moving events for the application
613 // It moves every child window that needs moving
614 void OnMove( UINT nType, int cx, int cy )
615 {
616 #ifdef GCC
617 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);
618 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);
619 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);
620 #endif
621 }
622
623 // OnSize()
624 // This function handles all the sizing events for the application
625 // It re-sizes every window, and child window that needs re-sizing
626 void OnSize( UINT nType, int cx, int cy )
627 {
628 int nParts[3];
629 int nXDifference;
630 int nYDifference;
631 RECT rc;
632
633 if (nType == SIZE_MINIMIZED)
634 return;
635
636 nXDifference = cx - nOldWidth;
637 nYDifference = cy - nOldHeight;
638 nOldWidth = cx;
639 nOldHeight = cy;
640
641 // Update the status bar size
642 GetWindowRect(hStatusWnd, &rc);
643 SendMessage(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
644
645 // Update the status bar pane sizes
646 nParts[0] = bInMenuLoop ? -1 : 100;
647 nParts[1] = 210;
648 nParts[2] = cx;
649 SendMessage(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (long)nParts);
650
651 // Resize the tab control
652 GetWindowRect(hTabWnd, &rc);
653 cx = (rc.right - rc.left) + nXDifference;
654 cy = (rc.bottom - rc.top) + nYDifference;
655 SetWindowPos(hTabWnd, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
656
657 // Resize the application page
658 GetWindowRect(hApplicationPage, &rc);
659 cx = (rc.right - rc.left) + nXDifference;
660 cy = (rc.bottom - rc.top) + nYDifference;
661 SetWindowPos(hApplicationPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
662
663 // Resize the process page
664 GetWindowRect(hProcessPage, &rc);
665 cx = (rc.right - rc.left) + nXDifference;
666 cy = (rc.bottom - rc.top) + nYDifference;
667 SetWindowPos(hProcessPage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
668
669 // Resize the performance page
670 GetWindowRect(hPerformancePage, &rc);
671 cx = (rc.right - rc.left) + nXDifference;
672 cy = (rc.bottom - rc.top) + nYDifference;
673 SetWindowPos(hPerformancePage, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
674
675 }
676
677 void LoadSettings(void)
678 {
679 HKEY hKey;
680 char szSubKey[] = "Software\\ReactWare\\TaskManager";
681 int i;
682 DWORD dwSize;
683
684 // Window size & position settings
685 TaskManagerSettings.Maximized = FALSE;
686 TaskManagerSettings.Left = 0;
687 TaskManagerSettings.Top = 0;
688 TaskManagerSettings.Right = 0;
689 TaskManagerSettings.Bottom = 0;
690
691 // Tab settings
692 TaskManagerSettings.ActiveTabPage = 0;
693
694 // Options menu settings
695 TaskManagerSettings.AlwaysOnTop = FALSE;
696 TaskManagerSettings.MinimizeOnUse = TRUE;
697 TaskManagerSettings.HideWhenMinimized = TRUE;
698 TaskManagerSettings.Show16BitTasks = TRUE;
699
700 // Update speed settings
701 TaskManagerSettings.UpdateSpeed = 2;
702
703 // Applications page settings
704 TaskManagerSettings.View_LargeIcons = FALSE;
705 TaskManagerSettings.View_SmallIcons = FALSE;
706 TaskManagerSettings.View_Details = TRUE;
707
708 // Processes page settings
709 TaskManagerSettings.ShowProcessesFromAllUsers = FALSE; // Server-only?
710 TaskManagerSettings.Column_ImageName = TRUE;
711 TaskManagerSettings.Column_PID = TRUE;
712 TaskManagerSettings.Column_CPUUsage = TRUE;
713 TaskManagerSettings.Column_CPUTime = TRUE;
714 TaskManagerSettings.Column_MemoryUsage = TRUE;
715 TaskManagerSettings.Column_MemoryUsageDelta = FALSE;
716 TaskManagerSettings.Column_PeakMemoryUsage = FALSE;
717 TaskManagerSettings.Column_PageFaults = FALSE;
718 TaskManagerSettings.Column_USERObjects = FALSE;
719 TaskManagerSettings.Column_IOReads = FALSE;
720 TaskManagerSettings.Column_IOReadBytes = FALSE;
721 TaskManagerSettings.Column_SessionID = FALSE; // Server-only?
722 TaskManagerSettings.Column_UserName = FALSE; // Server-only?
723 TaskManagerSettings.Column_PageFaultsDelta = FALSE;
724 TaskManagerSettings.Column_VirtualMemorySize = FALSE;
725 TaskManagerSettings.Column_PagedPool = FALSE;
726 TaskManagerSettings.Column_NonPagedPool = FALSE;
727 TaskManagerSettings.Column_BasePriority = FALSE;
728 TaskManagerSettings.Column_HandleCount = FALSE;
729 TaskManagerSettings.Column_ThreadCount = FALSE;
730 TaskManagerSettings.Column_GDIObjects = FALSE;
731 TaskManagerSettings.Column_IOWrites = FALSE;
732 TaskManagerSettings.Column_IOWriteBytes = FALSE;
733 TaskManagerSettings.Column_IOOther = FALSE;
734 TaskManagerSettings.Column_IOOtherBytes = FALSE;
735
736 for (i = 0; i < 25; i++) {
737 TaskManagerSettings.ColumnOrderArray[i] = i;
738 }
739 TaskManagerSettings.ColumnSizeArray[0] = 105;
740 TaskManagerSettings.ColumnSizeArray[1] = 50;
741 TaskManagerSettings.ColumnSizeArray[2] = 107;
742 TaskManagerSettings.ColumnSizeArray[3] = 70;
743 TaskManagerSettings.ColumnSizeArray[4] = 35;
744 TaskManagerSettings.ColumnSizeArray[5] = 70;
745 TaskManagerSettings.ColumnSizeArray[6] = 70;
746 TaskManagerSettings.ColumnSizeArray[7] = 100;
747 TaskManagerSettings.ColumnSizeArray[8] = 70;
748 TaskManagerSettings.ColumnSizeArray[9] = 70;
749 TaskManagerSettings.ColumnSizeArray[10] = 70;
750 TaskManagerSettings.ColumnSizeArray[11] = 70;
751 TaskManagerSettings.ColumnSizeArray[12] = 70;
752 TaskManagerSettings.ColumnSizeArray[13] = 70;
753 TaskManagerSettings.ColumnSizeArray[14] = 60;
754 TaskManagerSettings.ColumnSizeArray[15] = 60;
755 TaskManagerSettings.ColumnSizeArray[16] = 60;
756 TaskManagerSettings.ColumnSizeArray[17] = 60;
757 TaskManagerSettings.ColumnSizeArray[18] = 60;
758 TaskManagerSettings.ColumnSizeArray[19] = 70;
759 TaskManagerSettings.ColumnSizeArray[20] = 70;
760 TaskManagerSettings.ColumnSizeArray[21] = 70;
761 TaskManagerSettings.ColumnSizeArray[22] = 70;
762 TaskManagerSettings.ColumnSizeArray[23] = 70;
763 TaskManagerSettings.ColumnSizeArray[24] = 70;
764
765 TaskManagerSettings.SortColumn = 1;
766 TaskManagerSettings.SortAscending = TRUE;
767
768 // Performance page settings
769 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
770 TaskManagerSettings.ShowKernelTimes = FALSE;
771
772 // Open the key
773 if (RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
774 return;
775 // Read the settings
776 dwSize = sizeof(TASKMANAGER_SETTINGS);
777 RegQueryValueEx(hKey, "Preferences", NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
778
779 // Close the key
780 RegCloseKey(hKey);
781 }
782
783 void SaveSettings(void)
784 {
785 HKEY hKey;
786 char szSubKey1[] = "Software";
787 char szSubKey2[] = "Software\\ReactWare";
788 char szSubKey3[] = "Software\\ReactWare\\TaskManager";
789
790 // Open (or create) the key
791 hKey = NULL;
792 RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey1, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
793 RegCloseKey(hKey);
794 hKey = NULL;
795 RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey2, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
796 RegCloseKey(hKey);
797 hKey = NULL;
798 if (RegCreateKeyEx(HKEY_CURRENT_USER, szSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
799 return;
800 // Save the settings
801 RegSetValueEx(hKey, "Preferences", 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
802 // Close the key
803 RegCloseKey(hKey);
804 }
805
806 void TaskManager_OnEnterMenuLoop(HWND hWnd)
807 {
808 int nParts;
809
810 // Update the status bar pane sizes
811 nParts = -1;
812 SendMessage(hStatusWnd, SB_SETPARTS, 1, (long)&nParts);
813 bInMenuLoop = TRUE;
814 SendMessage(hStatusWnd, SB_SETTEXT, (WPARAM)0, (LPARAM)_T(""));
815 }
816
817 void TaskManager_OnExitMenuLoop(HWND hWnd)
818 {
819 RECT rc;
820 int nParts[3];
821 TCHAR text[260];
822
823 bInMenuLoop = FALSE;
824 // Update the status bar pane sizes
825 GetClientRect(hWnd, &rc);
826 nParts[0] = 100;
827 nParts[1] = 210;
828 nParts[2] = rc.right;
829 SendMessage(hStatusWnd, SB_SETPARTS, 3, (long)nParts);
830 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)_T(""));
831 wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
832 SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
833 wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount());
834 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
835 }
836
837 void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
838 {
839 TCHAR str[100];
840
841 strcpy(str, TEXT(""));
842 if (LoadString(hInst, nItemID, str, 100)) {
843 // load appropriate string
844 LPTSTR lpsz = str;
845 // first newline terminates actual string
846 lpsz = _tcschr(lpsz, '\n');
847 if (lpsz != NULL)
848 *lpsz = '\0';
849 }
850 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)str);
851 }
852
853 void TaskManager_OnViewUpdateSpeedHigh(void)
854 {
855 HMENU hMenu;
856 HMENU hViewMenu;
857 HMENU hUpdateSpeedMenu;
858
859 hMenu = GetMenu(hMainWnd);
860 hViewMenu = GetSubMenu(hMenu, 2);
861 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
862
863 TaskManagerSettings.UpdateSpeed = 1;
864 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
865
866 KillTimer(hMainWnd, 1);
867 SetTimer(hMainWnd, 1, 1000, NULL);
868 }
869
870 void TaskManager_OnViewUpdateSpeedNormal(void)
871 {
872 HMENU hMenu;
873 HMENU hViewMenu;
874 HMENU hUpdateSpeedMenu;
875
876 hMenu = GetMenu(hMainWnd);
877 hViewMenu = GetSubMenu(hMenu, 2);
878 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
879
880 TaskManagerSettings.UpdateSpeed = 2;
881 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
882
883 KillTimer(hMainWnd, 1);
884 SetTimer(hMainWnd, 1, 2000, NULL);
885 }
886
887 void TaskManager_OnViewUpdateSpeedLow(void)
888 {
889 HMENU hMenu;
890 HMENU hViewMenu;
891 HMENU hUpdateSpeedMenu;
892
893 hMenu = GetMenu(hMainWnd);
894 hViewMenu = GetSubMenu(hMenu, 2);
895 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
896
897 TaskManagerSettings.UpdateSpeed = 4;
898 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
899
900 KillTimer(hMainWnd, 1);
901 SetTimer(hMainWnd, 1, 4000, NULL);
902 }
903
904 void TaskManager_OnViewRefresh(void)
905 {
906 PostMessage(hMainWnd, WM_TIMER, 0, 0);
907 }
908
909 void TaskManager_OnViewUpdateSpeedPaused(void)
910 {
911 HMENU hMenu;
912 HMENU hViewMenu;
913 HMENU hUpdateSpeedMenu;
914
915 hMenu = GetMenu(hMainWnd);
916 hViewMenu = GetSubMenu(hMenu, 2);
917 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
918 TaskManagerSettings.UpdateSpeed = 0;
919 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
920 KillTimer(hMainWnd, 1);
921 }
922
923 void TaskManager_OnTabWndSelChange(void)
924 {
925 int i;
926 HMENU hMenu;
927 HMENU hOptionsMenu;
928 HMENU hViewMenu;
929 HMENU hSubMenu;
930
931 hMenu = GetMenu(hMainWnd);
932 hViewMenu = GetSubMenu(hMenu, 2);
933 hOptionsMenu = GetSubMenu(hMenu, 1);
934 TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
935 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
936 hSubMenu = GetSubMenu(hViewMenu, i);
937 if (hSubMenu)
938 DestroyMenu(hSubMenu);
939 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
940 }
941 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
942 switch (TaskManagerSettings.ActiveTabPage) {
943 case 0:
944 ShowWindow(hApplicationPage, SW_SHOW);
945 ShowWindow(hProcessPage, SW_HIDE);
946 ShowWindow(hPerformancePage, SW_HIDE);
947 BringWindowToTop(hApplicationPage);
948 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_LARGE, "Lar&ge Icons");
949 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SMALL, "S&mall Icons");
950 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_DETAILS, "&Details");
951
952 if (GetMenuItemCount(hMenu) <= 4) {
953 hSubMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWSMENU));
954 InsertMenu(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT)hSubMenu, "&Windows");
955 DrawMenuBar(hMainWnd);
956 }
957 if (TaskManagerSettings.View_LargeIcons)
958 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
959 else if (TaskManagerSettings.View_SmallIcons)
960 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
961 else
962 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
963 //
964 // Give the application list control focus
965 //
966 SetFocus(hApplicationPageListCtrl);
967 break;
968
969 case 1:
970 ShowWindow(hApplicationPage, SW_HIDE);
971 ShowWindow(hProcessPage, SW_SHOW);
972 ShowWindow(hPerformancePage, SW_HIDE);
973 BringWindowToTop(hProcessPage);
974 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, "&Select Columns...");
975 AppendMenu(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, "&Show 16-bit tasks");
976 if (TaskManagerSettings.Show16BitTasks)
977 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
978 if (GetMenuItemCount(hMenu) > 4)
979 {
980 RemoveMenu(hMenu, 3, MF_BYPOSITION);
981 DrawMenuBar(hMainWnd);
982 }
983 //
984 // Give the process list control focus
985 //
986 SetFocus(hProcessPageListCtrl);
987 break;
988
989 case 2:
990 ShowWindow(hApplicationPage, SW_HIDE);
991 ShowWindow(hProcessPage, SW_HIDE);
992 ShowWindow(hPerformancePage, SW_SHOW);
993 BringWindowToTop(hPerformancePage);
994 if (GetMenuItemCount(hMenu) > 4) {
995 RemoveMenu(hMenu, 3, MF_BYPOSITION);
996 DrawMenuBar(hMainWnd);
997 }
998 hSubMenu = CreatePopupMenu();
999 AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, "&One Graph, All CPUs");
1000 AppendMenu(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, "One Graph &Per CPU");
1001 AppendMenu(hViewMenu, MF_STRING|MF_POPUP, (UINT)hSubMenu, "&CPU History");
1002 AppendMenu(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, "&Show Kernel Times");
1003 if (TaskManagerSettings.ShowKernelTimes)
1004 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
1005 else
1006 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
1007 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
1008 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
1009 else
1010 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
1011 //
1012 // Give the tab control focus
1013 //
1014 SetFocus(hTabWnd);
1015 break;
1016 }
1017 }
1018
1019 LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize )
1020 {
1021 DWORD dwRet;
1022 LPTSTR lpszTemp = NULL;
1023
1024 dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
1025 NULL,
1026 GetLastError(),
1027 LANG_NEUTRAL,
1028 (LPTSTR)&lpszTemp,
1029 0,
1030 NULL );
1031
1032 // supplied buffer is not long enough
1033 if (!dwRet || ( (long)dwSize < (long)dwRet+14 )) {
1034 lpszBuf[0] = TEXT('\0');
1035 } else {
1036 lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character
1037 _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() );
1038 }
1039 if (lpszTemp) {
1040 LocalFree((HLOCAL)lpszTemp);
1041 }
1042 return lpszBuf;
1043 }