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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
49 #define STATUS_WINDOW 2001
51 /* Global Variables: */
52 HINSTANCE hInst
; /* current instance */
54 HWND hMainWnd
; /* Main Window */
55 HWND hStatusWnd
; /* Status Bar Window */
56 HWND hTabWnd
; /* Tab Control Window */
58 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
59 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
61 int nOldWidth
; /* Holds the previous client area width */
62 int nOldHeight
; /* Holds the previous client area height */
64 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
66 TASKMANAGER_SETTINGS TaskManagerSettings
;
69 int APIENTRY
WinMain(HINSTANCE hInstance
,
70 HINSTANCE hPrevInstance
,
78 /* Initialize global variables */
81 /* Change our priority class to HIGH */
82 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
83 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
84 CloseHandle(hProcess
);
86 /* Now lets get the SE_DEBUG_NAME priviledge
87 * so that we can debug processes
90 /* Get a token for this process. */
91 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
92 /* Get the LUID for the debug privilege. */
93 LookupPrivilegeValue(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
95 tkp
.PrivilegeCount
= 1; /* one privilege to set */
96 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
98 /* Get the debug privilege for this process. */
99 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
102 /* Load our settings from the registry */
105 /* Initialize perf data */
106 if (!PerfDataInitialize()) {
110 DialogBox(hInst
, (LPCTSTR
)IDD_TASKMGR_DIALOG
, NULL
, (DLGPROC
)TaskManagerWndProc
);
112 /* Save our settings to the registry */
114 PerfDataUninitialize();
118 /* Message handler for dialog box. */
119 LRESULT CALLBACK
TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
132 return OnCreate(hDlg
);
135 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
136 EndDialog(hDlg
, LOWORD(wParam
));
139 /* Process menu commands */
140 switch (LOWORD(wParam
))
143 TaskManager_OnFileNew();
145 case ID_OPTIONS_ALWAYSONTOP
:
146 TaskManager_OnOptionsAlwaysOnTop();
148 case ID_OPTIONS_MINIMIZEONUSE
:
149 TaskManager_OnOptionsMinimizeOnUse();
151 case ID_OPTIONS_HIDEWHENMINIMIZED
:
152 TaskManager_OnOptionsHideWhenMinimized();
154 case ID_OPTIONS_SHOW16BITTASKS
:
155 TaskManager_OnOptionsShow16BitTasks();
158 ApplicationPage_OnViewLargeIcons();
161 ApplicationPage_OnViewSmallIcons();
163 case ID_VIEW_DETAILS
:
164 ApplicationPage_OnViewDetails();
166 case ID_VIEW_SHOWKERNELTIMES
:
167 PerformancePage_OnViewShowKernelTimes();
169 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
170 PerformancePage_OnViewCPUHistoryOneGraphAll();
172 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
173 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
175 case ID_VIEW_UPDATESPEED_HIGH
:
176 TaskManager_OnViewUpdateSpeedHigh();
178 case ID_VIEW_UPDATESPEED_NORMAL
:
179 TaskManager_OnViewUpdateSpeedNormal();
181 case ID_VIEW_UPDATESPEED_LOW
:
182 TaskManager_OnViewUpdateSpeedLow();
184 case ID_VIEW_UPDATESPEED_PAUSED
:
185 TaskManager_OnViewUpdateSpeedPaused();
187 case ID_VIEW_SELECTCOLUMNS
:
188 ProcessPage_OnViewSelectColumns();
190 case ID_VIEW_REFRESH
:
191 PostMessage(hDlg
, WM_TIMER
, 0, 0);
193 case ID_WINDOWS_TILEHORIZONTALLY
:
194 ApplicationPage_OnWindowsTileHorizontally();
196 case ID_WINDOWS_TILEVERTICALLY
:
197 ApplicationPage_OnWindowsTileVertically();
199 case ID_WINDOWS_MINIMIZE
:
200 ApplicationPage_OnWindowsMinimize();
202 case ID_WINDOWS_MAXIMIZE
:
203 ApplicationPage_OnWindowsMaximize();
205 case ID_WINDOWS_CASCADE
:
206 ApplicationPage_OnWindowsCascade();
208 case ID_WINDOWS_BRINGTOFRONT
:
209 ApplicationPage_OnWindowsBringToFront();
211 case ID_APPLICATION_PAGE_SWITCHTO
:
212 ApplicationPage_OnSwitchTo();
214 case ID_APPLICATION_PAGE_ENDTASK
:
215 ApplicationPage_OnEndTask();
217 case ID_APPLICATION_PAGE_GOTOPROCESS
:
218 ApplicationPage_OnGotoProcess();
220 case ID_PROCESS_PAGE_ENDPROCESS
:
221 ProcessPage_OnEndProcess();
223 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
224 ProcessPage_OnEndProcessTree();
226 case ID_PROCESS_PAGE_DEBUG
:
227 ProcessPage_OnDebug();
229 case ID_PROCESS_PAGE_SETAFFINITY
:
230 ProcessPage_OnSetAffinity();
232 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
233 ProcessPage_OnSetPriorityRealTime();
235 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
236 ProcessPage_OnSetPriorityHigh();
238 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
239 ProcessPage_OnSetPriorityAboveNormal();
241 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
242 ProcessPage_OnSetPriorityNormal();
244 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
245 ProcessPage_OnSetPriorityBelowNormal();
247 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
248 ProcessPage_OnSetPriorityLow();
260 idctrl
= (int)wParam
;
261 pnmh
= (LPNMHDR
)lParam
;
262 if ((pnmh
->hwndFrom
== hTabWnd
) &&
263 (pnmh
->idFrom
== IDC_TAB
) &&
264 (pnmh
->code
== TCN_SELCHANGE
))
266 TaskManager_OnTabWndSelChange();
272 GetClientRect(hDlg
, &rc
);
273 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
274 ReleaseDC(hDlg
, hdc
);
278 hdc
= BeginPaint(hDlg
, &ps
);
279 GetClientRect(hDlg
, &rc
);
280 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
285 /* Make sure the user is sizing the dialog */
286 /* in an acceptable range */
287 pRC
= (LPRECT
)lParam
;
288 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
289 /* If the width is too small enlarge it to the minimum */
290 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
291 pRC
->left
= pRC
->right
- nMinimumWidth
;
293 /* If the width is too small enlarge it to the minimum */
294 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
295 pRC
->right
= pRC
->left
+ nMinimumWidth
;
297 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
298 /* If the height is too small enlarge it to the minimum */
299 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
300 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
302 /* If the height is too small enlarge it to the minimum */
303 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
304 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
310 /* Handle the window sizing in it's own function */
311 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
315 /* Handle the window moving in it's own function */
316 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
320 ShowWindow(hDlg
, SW_HIDE
);
321 TrayIcon_ShellRemoveTrayIcon();
322 wp
.length
= sizeof(WINDOWPLACEMENT
);
323 GetWindowPlacement(hDlg
, &wp
);
324 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
325 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
326 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
327 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
328 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
329 TaskManagerSettings
.Maximized
= TRUE
;
331 TaskManagerSettings
.Maximized
= FALSE
;
332 return DefWindowProc(hDlg
, message
, wParam
, lParam
);
335 /* Refresh the performance data */
337 RefreshApplicationPage();
338 RefreshProcessPage();
339 RefreshPerformancePage();
340 TrayIcon_ShellUpdateTrayIcon();
343 case WM_ENTERMENULOOP
:
344 TaskManager_OnEnterMenuLoop(hDlg
);
346 case WM_EXITMENULOOP
:
347 TaskManager_OnExitMenuLoop(hDlg
);
350 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
357 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
359 SetBkColor(hDC
, clr
);
360 ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
363 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
367 SetBkColor(hDC
, clr
);
371 rect
.bottom
= y
+ cy
;
372 ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
375 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
377 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
378 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
379 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
380 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
383 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
385 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
386 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
389 BOOL
OnCreate(HWND hWnd
)
394 HMENU hUpdateSpeedMenu
;
395 HMENU hCPUHistoryMenu
;
402 SendMessage(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIcon(hInst
, MAKEINTRESOURCE(IDI_TASKMANAGER
)));
404 /* Initialize the Windows Common Controls DLL */
405 InitCommonControls();
407 /* Get the minimum window sizes */
408 GetWindowRect(hWnd
, &rc
);
409 nMinimumWidth
= (rc
.right
- rc
.left
);
410 nMinimumHeight
= (rc
.bottom
- rc
.top
);
412 /* Create the status bar */
413 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, _T(""), hWnd
, STATUS_WINDOW
);
417 /* Create the status bar panes */
421 SendMessage(hStatusWnd
, SB_SETPARTS
, 3, (long)nParts
);
423 /* Create tab pages */
424 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
426 hApplicationPage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_APPLICATION_PAGE
), hWnd
, (DLGPROC
)ApplicationPageWndProc
);
427 hProcessPage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_PROCESS_PAGE
), hWnd
, (DLGPROC
)ProcessPageWndProc
);
428 hPerformancePage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE
), hWnd
, (DLGPROC
)PerformancePageWndProc
);
430 hApplicationPage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_APPLICATION_PAGE
), hTabWnd
, (DLGPROC
)ApplicationPageWndProc
);
431 hProcessPage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_PROCESS_PAGE
), hTabWnd
, (DLGPROC
)ProcessPageWndProc
);
432 hPerformancePage
= CreateDialog(hInst
, MAKEINTRESOURCE(IDD_PERFORMANCE_PAGE
), hTabWnd
, (DLGPROC
)PerformancePageWndProc
);
435 _tcscpy(szTemp
, _T("Applications"));
436 memset(&item
, 0, sizeof(TCITEM
));
437 item
.mask
= TCIF_TEXT
;
438 item
.pszText
= szTemp
;
439 TabCtrl_InsertItem(hTabWnd
, 0, &item
);
440 _tcscpy(szTemp
, _T("Processes"));
441 memset(&item
, 0, sizeof(TCITEM
));
442 item
.mask
= TCIF_TEXT
;
443 item
.pszText
= szTemp
;
444 TabCtrl_InsertItem(hTabWnd
, 1, &item
);
445 _tcscpy(szTemp
, _T("Performance"));
446 memset(&item
, 0, sizeof(TCITEM
));
447 item
.mask
= TCIF_TEXT
;
448 item
.pszText
= szTemp
;
449 TabCtrl_InsertItem(hTabWnd
, 2, &item
);
451 /* Size everything correctly */
452 GetClientRect(hWnd
, &rc
);
453 nOldWidth
= rc
.right
;
454 nOldHeight
= rc
.bottom
;
455 /* nOldStartX = rc.left; */
456 /*nOldStartY = rc.top; */
458 #define PAGE_OFFSET_LEFT 17
459 #define PAGE_OFFSET_TOP 72
460 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
461 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
463 if ((TaskManagerSettings
.Left
!= 0) ||
464 (TaskManagerSettings
.Top
!= 0) ||
465 (TaskManagerSettings
.Right
!= 0) ||
466 (TaskManagerSettings
.Bottom
!= 0))
468 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
469 #ifdef __GNUC__TEST__
470 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
);
471 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
);
472 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
);
475 if (TaskManagerSettings
.Maximized
)
476 ShowWindow(hWnd
, SW_MAXIMIZE
);
478 /* Set the always on top style */
479 hMenu
= GetMenu(hWnd
);
480 hEditMenu
= GetSubMenu(hMenu
, 1);
481 hViewMenu
= GetSubMenu(hMenu
, 2);
482 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
483 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
485 /* Check or uncheck the always on top menu item */
486 if (TaskManagerSettings
.AlwaysOnTop
) {
487 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
488 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
490 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
491 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
494 /* Check or uncheck the minimize on use menu item */
495 if (TaskManagerSettings
.MinimizeOnUse
)
496 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
498 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
500 /* Check or uncheck the hide when minimized menu item */
501 if (TaskManagerSettings
.HideWhenMinimized
)
502 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
504 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
506 /* Check or uncheck the show 16-bit tasks menu item */
507 if (TaskManagerSettings
.Show16BitTasks
)
508 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
510 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
512 if (TaskManagerSettings
.View_LargeIcons
)
513 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
514 else if (TaskManagerSettings
.View_SmallIcons
)
515 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
517 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
519 if (TaskManagerSettings
.ShowKernelTimes
)
520 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
522 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
524 if (TaskManagerSettings
.UpdateSpeed
== 1)
525 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
526 else if (TaskManagerSettings
.UpdateSpeed
== 2)
527 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
528 else if (TaskManagerSettings
.UpdateSpeed
== 4)
529 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
531 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
533 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
534 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
536 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
538 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
539 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
540 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
541 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
542 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
544 if (TaskManagerSettings
.UpdateSpeed
== 0)
546 else if (TaskManagerSettings
.UpdateSpeed
== 1)
549 SetTimer(hWnd
, 1, 1000, NULL
);
551 else if (TaskManagerSettings
.UpdateSpeed
== 2)
554 SetTimer(hWnd
, 1, 2000, NULL
);
556 else if (TaskManagerSettings
.UpdateSpeed
== 4)
559 SetTimer(hWnd
, 1, 4000, NULL
);
563 * Refresh the performance data
564 * Sample it twice so we can establish
565 * the delta values & cpu usage
570 RefreshApplicationPage();
571 RefreshProcessPage();
572 RefreshPerformancePage();
574 TrayIcon_ShellAddTrayIcon();
580 * This function handles all the moving events for the application
581 * It moves every child window that needs moving
583 void OnMove( UINT nType
, int cx
, int cy
)
585 #ifdef __GNUC__TEST__
586 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
);
587 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
);
588 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
);
593 * This function handles all the sizing events for the application
594 * It re-sizes every window, and child window that needs re-sizing
596 void OnSize( UINT nType
, int cx
, int cy
)
603 if (nType
== SIZE_MINIMIZED
)
606 nXDifference
= cx
- nOldWidth
;
607 nYDifference
= cy
- nOldHeight
;
611 /* Update the status bar size */
612 GetWindowRect(hStatusWnd
, &rc
);
613 SendMessage(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
615 /* Update the status bar pane sizes */
616 nParts
[0] = bInMenuLoop
? -1 : 100;
619 SendMessage(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (long)nParts
);
621 /* Resize the tab control */
622 GetWindowRect(hTabWnd
, &rc
);
623 cx
= (rc
.right
- rc
.left
) + nXDifference
;
624 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
625 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
627 /* Resize the application page */
628 GetWindowRect(hApplicationPage
, &rc
);
629 cx
= (rc
.right
- rc
.left
) + nXDifference
;
630 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
631 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
633 /* Resize the process page */
634 GetWindowRect(hProcessPage
, &rc
);
635 cx
= (rc
.right
- rc
.left
) + nXDifference
;
636 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
637 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
639 /* Resize the performance page */
640 GetWindowRect(hPerformancePage
, &rc
);
641 cx
= (rc
.right
- rc
.left
) + nXDifference
;
642 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
643 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
647 void LoadSettings(void)
650 TCHAR szSubKey
[] = _T("Software\\ReactWare\\TaskManager");
654 /* Window size & position settings */
655 TaskManagerSettings
.Maximized
= FALSE
;
656 TaskManagerSettings
.Left
= 0;
657 TaskManagerSettings
.Top
= 0;
658 TaskManagerSettings
.Right
= 0;
659 TaskManagerSettings
.Bottom
= 0;
662 TaskManagerSettings
.ActiveTabPage
= 0;
664 /* Options menu settings */
665 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
666 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
667 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
668 TaskManagerSettings
.Show16BitTasks
= TRUE
;
670 /* Update speed settings */
671 TaskManagerSettings
.UpdateSpeed
= 2;
673 /* Applications page settings */
674 TaskManagerSettings
.View_LargeIcons
= FALSE
;
675 TaskManagerSettings
.View_SmallIcons
= FALSE
;
676 TaskManagerSettings
.View_Details
= TRUE
;
678 /* Processes page settings */
679 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
680 TaskManagerSettings
.Column_ImageName
= TRUE
;
681 TaskManagerSettings
.Column_PID
= TRUE
;
682 TaskManagerSettings
.Column_CPUUsage
= TRUE
;
683 TaskManagerSettings
.Column_CPUTime
= TRUE
;
684 TaskManagerSettings
.Column_MemoryUsage
= TRUE
;
685 TaskManagerSettings
.Column_MemoryUsageDelta
= FALSE
;
686 TaskManagerSettings
.Column_PeakMemoryUsage
= FALSE
;
687 TaskManagerSettings
.Column_PageFaults
= FALSE
;
688 TaskManagerSettings
.Column_USERObjects
= FALSE
;
689 TaskManagerSettings
.Column_IOReads
= FALSE
;
690 TaskManagerSettings
.Column_IOReadBytes
= FALSE
;
691 TaskManagerSettings
.Column_SessionID
= FALSE
; /* Server-only? */
692 TaskManagerSettings
.Column_UserName
= FALSE
; /* Server-only? */
693 TaskManagerSettings
.Column_PageFaultsDelta
= FALSE
;
694 TaskManagerSettings
.Column_VirtualMemorySize
= FALSE
;
695 TaskManagerSettings
.Column_PagedPool
= FALSE
;
696 TaskManagerSettings
.Column_NonPagedPool
= FALSE
;
697 TaskManagerSettings
.Column_BasePriority
= FALSE
;
698 TaskManagerSettings
.Column_HandleCount
= FALSE
;
699 TaskManagerSettings
.Column_ThreadCount
= FALSE
;
700 TaskManagerSettings
.Column_GDIObjects
= FALSE
;
701 TaskManagerSettings
.Column_IOWrites
= FALSE
;
702 TaskManagerSettings
.Column_IOWriteBytes
= FALSE
;
703 TaskManagerSettings
.Column_IOOther
= FALSE
;
704 TaskManagerSettings
.Column_IOOtherBytes
= FALSE
;
706 for (i
= 0; i
< 25; i
++) {
707 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
709 TaskManagerSettings
.ColumnSizeArray
[0] = 105;
710 TaskManagerSettings
.ColumnSizeArray
[1] = 50;
711 TaskManagerSettings
.ColumnSizeArray
[2] = 107;
712 TaskManagerSettings
.ColumnSizeArray
[3] = 70;
713 TaskManagerSettings
.ColumnSizeArray
[4] = 35;
714 TaskManagerSettings
.ColumnSizeArray
[5] = 70;
715 TaskManagerSettings
.ColumnSizeArray
[6] = 70;
716 TaskManagerSettings
.ColumnSizeArray
[7] = 100;
717 TaskManagerSettings
.ColumnSizeArray
[8] = 70;
718 TaskManagerSettings
.ColumnSizeArray
[9] = 70;
719 TaskManagerSettings
.ColumnSizeArray
[10] = 70;
720 TaskManagerSettings
.ColumnSizeArray
[11] = 70;
721 TaskManagerSettings
.ColumnSizeArray
[12] = 70;
722 TaskManagerSettings
.ColumnSizeArray
[13] = 70;
723 TaskManagerSettings
.ColumnSizeArray
[14] = 60;
724 TaskManagerSettings
.ColumnSizeArray
[15] = 60;
725 TaskManagerSettings
.ColumnSizeArray
[16] = 60;
726 TaskManagerSettings
.ColumnSizeArray
[17] = 60;
727 TaskManagerSettings
.ColumnSizeArray
[18] = 60;
728 TaskManagerSettings
.ColumnSizeArray
[19] = 70;
729 TaskManagerSettings
.ColumnSizeArray
[20] = 70;
730 TaskManagerSettings
.ColumnSizeArray
[21] = 70;
731 TaskManagerSettings
.ColumnSizeArray
[22] = 70;
732 TaskManagerSettings
.ColumnSizeArray
[23] = 70;
733 TaskManagerSettings
.ColumnSizeArray
[24] = 70;
735 TaskManagerSettings
.SortColumn
= 1;
736 TaskManagerSettings
.SortAscending
= TRUE
;
738 /* Performance page settings */
739 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
740 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
743 if (RegOpenKeyEx(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
745 /* Read the settings */
746 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
747 RegQueryValueEx(hKey
, _T("Preferences"), NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
753 void SaveSettings(void)
756 TCHAR szSubKey1
[] = _T("Software");
757 TCHAR szSubKey2
[] = _T("Software\\ReactWare");
758 TCHAR szSubKey3
[] = _T("Software\\ReactWare\\TaskManager");
760 /* Open (or create) the key */
762 RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey1
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
765 RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey2
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
768 if (RegCreateKeyEx(HKEY_CURRENT_USER
, szSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
770 /* Save the settings */
771 RegSetValueEx(hKey
, _T("Preferences"), 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
776 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
780 /* Update the status bar pane sizes */
782 SendMessage(hStatusWnd
, SB_SETPARTS
, 1, (long)&nParts
);
784 SendMessage(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
787 void TaskManager_OnExitMenuLoop(HWND hWnd
)
794 /* Update the status bar pane sizes */
795 GetClientRect(hWnd
, &rc
);
798 nParts
[2] = rc
.right
;
799 SendMessage(hStatusWnd
, SB_SETPARTS
, 3, (long)nParts
);
800 SendMessage(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)_T(""));
801 wsprintf(text
, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
802 SendMessage(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
803 wsprintf(text
, _T("Processes: %d"), PerfDataGetProcessCount());
804 SendMessage(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
807 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
811 _tcscpy(str
, TEXT(""));
812 if (LoadString(hInst
, nItemID
, str
, 100)) {
813 /* load appropriate string */
815 /* first newline terminates actual string */
816 lpsz
= _tcschr(lpsz
, '\n');
820 SendMessage(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
823 void TaskManager_OnViewUpdateSpeedHigh(void)
827 HMENU hUpdateSpeedMenu
;
829 hMenu
= GetMenu(hMainWnd
);
830 hViewMenu
= GetSubMenu(hMenu
, 2);
831 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
833 TaskManagerSettings
.UpdateSpeed
= 1;
834 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
836 KillTimer(hMainWnd
, 1);
837 SetTimer(hMainWnd
, 1, 1000, NULL
);
840 void TaskManager_OnViewUpdateSpeedNormal(void)
844 HMENU hUpdateSpeedMenu
;
846 hMenu
= GetMenu(hMainWnd
);
847 hViewMenu
= GetSubMenu(hMenu
, 2);
848 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
850 TaskManagerSettings
.UpdateSpeed
= 2;
851 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
853 KillTimer(hMainWnd
, 1);
854 SetTimer(hMainWnd
, 1, 2000, NULL
);
857 void TaskManager_OnViewUpdateSpeedLow(void)
861 HMENU hUpdateSpeedMenu
;
863 hMenu
= GetMenu(hMainWnd
);
864 hViewMenu
= GetSubMenu(hMenu
, 2);
865 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
867 TaskManagerSettings
.UpdateSpeed
= 4;
868 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
870 KillTimer(hMainWnd
, 1);
871 SetTimer(hMainWnd
, 1, 4000, NULL
);
874 void TaskManager_OnViewRefresh(void)
876 PostMessage(hMainWnd
, WM_TIMER
, 0, 0);
879 void TaskManager_OnViewUpdateSpeedPaused(void)
883 HMENU hUpdateSpeedMenu
;
885 hMenu
= GetMenu(hMainWnd
);
886 hViewMenu
= GetSubMenu(hMenu
, 2);
887 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
888 TaskManagerSettings
.UpdateSpeed
= 0;
889 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
890 KillTimer(hMainWnd
, 1);
893 void TaskManager_OnTabWndSelChange(void)
901 hMenu
= GetMenu(hMainWnd
);
902 hViewMenu
= GetSubMenu(hMenu
, 2);
903 hOptionsMenu
= GetSubMenu(hMenu
, 1);
904 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
905 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
906 hSubMenu
= GetSubMenu(hViewMenu
, i
);
908 DestroyMenu(hSubMenu
);
909 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
911 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
912 switch (TaskManagerSettings
.ActiveTabPage
) {
914 ShowWindow(hApplicationPage
, SW_SHOW
);
915 ShowWindow(hProcessPage
, SW_HIDE
);
916 ShowWindow(hPerformancePage
, SW_HIDE
);
917 BringWindowToTop(hApplicationPage
);
918 AppendMenu(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, _T("Lar&ge Icons"));
919 AppendMenu(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, _T("S&mall Icons"));
920 AppendMenu(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, _T("&Details"));
922 if (GetMenuItemCount(hMenu
) <= 4) {
923 hSubMenu
= LoadMenu(hInst
, MAKEINTRESOURCE(IDR_WINDOWSMENU
));
924 InsertMenu(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT
)hSubMenu
, _T("&Windows"));
925 DrawMenuBar(hMainWnd
);
927 if (TaskManagerSettings
.View_LargeIcons
)
928 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
929 else if (TaskManagerSettings
.View_SmallIcons
)
930 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
932 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
934 * Give the application list control focus
936 SetFocus(hApplicationPageListCtrl
);
940 ShowWindow(hApplicationPage
, SW_HIDE
);
941 ShowWindow(hProcessPage
, SW_SHOW
);
942 ShowWindow(hPerformancePage
, SW_HIDE
);
943 BringWindowToTop(hProcessPage
);
944 AppendMenu(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, _T("&Select Columns..."));
945 AppendMenu(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, _T("&Show 16-bit tasks"));
946 if (TaskManagerSettings
.Show16BitTasks
)
947 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
948 if (GetMenuItemCount(hMenu
) > 4)
950 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
951 DrawMenuBar(hMainWnd
);
954 * Give the process list control focus
956 SetFocus(hProcessPageListCtrl
);
960 ShowWindow(hApplicationPage
, SW_HIDE
);
961 ShowWindow(hProcessPage
, SW_HIDE
);
962 ShowWindow(hPerformancePage
, SW_SHOW
);
963 BringWindowToTop(hPerformancePage
);
964 if (GetMenuItemCount(hMenu
) > 4) {
965 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
966 DrawMenuBar(hMainWnd
);
968 hSubMenu
= CreatePopupMenu();
969 AppendMenu(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, _T("&One Graph, All CPUs"));
970 AppendMenu(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, _T("One Graph &Per CPU"));
971 AppendMenu(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT
)hSubMenu
, _T("&CPU History"));
972 AppendMenu(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, _T("&Show Kernel Times"));
973 if (TaskManagerSettings
.ShowKernelTimes
)
974 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
976 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
977 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
978 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
980 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
982 * Give the tab control focus
989 LPTSTR
GetLastErrorText(LPTSTR lpszBuf
, DWORD dwSize
)
992 LPTSTR lpszTemp
= NULL
;
994 dwRet
= FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1002 /* supplied buffer is not long enough */
1003 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1004 lpszBuf
[0] = TEXT('\0');
1006 lpszTemp
[lstrlen(lpszTemp
)-2] = TEXT('\0'); /*remove cr and newline character */
1007 _stprintf(lpszBuf
, TEXT("%s (0x%x)"), lpszTemp
, (int)GetLastError());
1010 LocalFree((HLOCAL
)lpszTemp
);