4 * TaskMgr.c : Defines the entry point for the application.
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define STATUS_WINDOW 2001
28 /* Global Variables: */
29 HINSTANCE hInst
; /* current instance */
31 HWND hMainWnd
; /* Main Window */
32 HWND hStatusWnd
; /* Status Bar Window */
33 HWND hTabWnd
; /* Tab Control Window */
35 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
36 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
38 int nOldWidth
; /* Holds the previous client area width */
39 int nOldHeight
; /* Holds the previous client area height */
41 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
43 TASKMANAGER_SETTINGS TaskManagerSettings
;
46 int APIENTRY
wWinMain(HINSTANCE hInstance
,
47 HINSTANCE hPrevInstance
,
56 /* check wether we're already running or not */
57 hMutex
= CreateMutexW(NULL
, TRUE
, L
"taskmgrros");
58 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
61 /* Initialize global variables */
64 /* Change our priority class to HIGH */
65 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
66 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
67 CloseHandle(hProcess
);
69 /* Now lets get the SE_DEBUG_NAME privilege
70 * so that we can debug processes
73 /* Get a token for this process. */
74 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
75 /* Get the LUID for the debug privilege. */
76 LookupPrivilegeValueW(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
78 tkp
.PrivilegeCount
= 1; /* one privilege to set */
79 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
81 /* Get the debug privilege for this process. */
82 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
86 /* Load our settings from the registry */
89 /* Initialize perf data */
90 if (!PerfDataInitialize()) {
94 DialogBoxW(hInst
, (LPCWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
96 /* Save our settings to the registry */
98 PerfDataUninitialize();
102 /* Message handler for dialog box. */
104 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
119 return OnCreate(hDlg
);
122 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
123 EndDialog(hDlg
, LOWORD(wParam
));
126 /* Process menu commands */
127 switch (LOWORD(wParam
))
130 TaskManager_OnFileNew();
132 case ID_OPTIONS_ALWAYSONTOP
:
133 TaskManager_OnOptionsAlwaysOnTop();
135 case ID_OPTIONS_MINIMIZEONUSE
:
136 TaskManager_OnOptionsMinimizeOnUse();
138 case ID_OPTIONS_HIDEWHENMINIMIZED
:
139 TaskManager_OnOptionsHideWhenMinimized();
141 case ID_OPTIONS_SHOW16BITTASKS
:
142 TaskManager_OnOptionsShow16BitTasks();
145 TaskManager_OnRestoreMainWindow();
149 case ID_VIEW_DETAILS
:
150 ApplicationPage_OnView(LOWORD(wParam
));
152 case ID_VIEW_SHOWKERNELTIMES
:
153 PerformancePage_OnViewShowKernelTimes();
155 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
156 PerformancePage_OnViewCPUHistoryOneGraphAll();
158 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
159 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
161 case ID_VIEW_UPDATESPEED_HIGH
:
162 case ID_VIEW_UPDATESPEED_NORMAL
:
163 case ID_VIEW_UPDATESPEED_LOW
:
164 case ID_VIEW_UPDATESPEED_PAUSED
:
165 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
167 case ID_VIEW_SELECTCOLUMNS
:
168 ProcessPage_OnViewSelectColumns();
170 case ID_VIEW_REFRESH
:
171 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
173 case ID_WINDOWS_TILEHORIZONTALLY
:
174 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
176 case ID_WINDOWS_TILEVERTICALLY
:
177 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
179 case ID_WINDOWS_MINIMIZE
:
180 ApplicationPage_OnWindowsMinimize();
182 case ID_WINDOWS_MAXIMIZE
:
183 ApplicationPage_OnWindowsMaximize();
185 case ID_WINDOWS_CASCADE
:
186 ApplicationPage_OnWindowsCascade();
188 case ID_WINDOWS_BRINGTOFRONT
:
189 ApplicationPage_OnWindowsBringToFront();
191 case ID_APPLICATION_PAGE_SWITCHTO
:
192 ApplicationPage_OnSwitchTo();
194 case ID_APPLICATION_PAGE_ENDTASK
:
195 ApplicationPage_OnEndTask();
197 case ID_APPLICATION_PAGE_GOTOPROCESS
:
198 ApplicationPage_OnGotoProcess();
200 case ID_PROCESS_PAGE_ENDPROCESS
:
201 ProcessPage_OnEndProcess();
203 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
204 ProcessPage_OnEndProcessTree();
206 case ID_PROCESS_PAGE_DEBUG
:
207 ProcessPage_OnDebug();
209 case ID_PROCESS_PAGE_SETAFFINITY
:
210 ProcessPage_OnSetAffinity();
212 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
213 DoSetPriority(REALTIME_PRIORITY_CLASS
);
215 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
216 DoSetPriority(HIGH_PRIORITY_CLASS
);
218 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
219 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
221 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
222 DoSetPriority(NORMAL_PRIORITY_CLASS
);
224 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
225 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
227 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
228 DoSetPriority(IDLE_PRIORITY_CLASS
);
230 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
231 ProcessPage_OnDebugChannels();
237 EndDialog(hDlg
, IDOK
);
249 HMENU hMenu
, hPopupMenu
;
253 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
255 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
256 hPopupMenu
= GetSubMenu(hMenu
, 0);
258 if(IsWindowVisible(hMainWnd
))
260 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
264 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
269 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
272 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
275 SetForegroundWindow(hMainWnd
);
276 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
281 case WM_LBUTTONDBLCLK
:
282 TaskManager_OnRestoreMainWindow();
288 idctrl
= (int)wParam
;
289 pnmh
= (LPNMHDR
)lParam
;
290 if ((pnmh
->hwndFrom
== hTabWnd
) &&
291 (pnmh
->idFrom
== IDC_TAB
) &&
292 (pnmh
->code
== TCN_SELCHANGE
))
294 TaskManager_OnTabWndSelChange();
300 GetClientRect(hDlg
, &rc
);
301 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
302 ReleaseDC(hDlg
, hdc
);
306 hdc
= BeginPaint(hDlg
, &ps
);
307 GetClientRect(hDlg
, &rc
);
308 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
313 /* Make sure the user is sizing the dialog */
314 /* in an acceptable range */
315 pRC
= (LPRECT
)lParam
;
316 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
317 /* If the width is too small enlarge it to the minimum */
318 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
319 pRC
->left
= pRC
->right
- nMinimumWidth
;
321 /* If the width is too small enlarge it to the minimum */
322 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
323 pRC
->right
= pRC
->left
+ nMinimumWidth
;
325 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
326 /* If the height is too small enlarge it to the minimum */
327 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
328 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
330 /* If the height is too small enlarge it to the minimum */
331 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
332 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
338 /* Handle the window sizing in it's own function */
339 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
343 /* Handle the window moving in it's own function */
344 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
348 ShowWindow(hDlg
, SW_HIDE
);
349 TrayIcon_ShellRemoveTrayIcon();
350 wp
.length
= sizeof(WINDOWPLACEMENT
);
351 GetWindowPlacement(hDlg
, &wp
);
352 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
353 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
354 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
355 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
356 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
357 TaskManagerSettings
.Maximized
= TRUE
;
359 TaskManagerSettings
.Maximized
= FALSE
;
360 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
363 /* Refresh the performance data */
365 RefreshApplicationPage();
366 RefreshProcessPage();
367 RefreshPerformancePage();
368 TrayIcon_ShellUpdateTrayIcon();
371 case WM_ENTERMENULOOP
:
372 TaskManager_OnEnterMenuLoop(hDlg
);
374 case WM_EXITMENULOOP
:
375 TaskManager_OnExitMenuLoop(hDlg
);
378 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
385 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
387 SetBkColor(hDC
, clr
);
388 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
391 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
395 SetBkColor(hDC
, clr
);
399 rect
.bottom
= y
+ cy
;
400 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
403 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
405 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
406 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
407 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
408 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
411 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
413 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
414 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
417 static void SetUpdateSpeed(HWND hWnd
)
419 /* Setup update speed (pause=fall down) */
420 switch (TaskManagerSettings
.UpdateSpeed
) {
421 case ID_VIEW_UPDATESPEED_HIGH
:
422 SetTimer(hWnd
, 1, 1000, NULL
);
424 case ID_VIEW_UPDATESPEED_NORMAL
:
425 SetTimer(hWnd
, 1, 2000, NULL
);
427 case ID_VIEW_UPDATESPEED_LOW
:
428 SetTimer(hWnd
, 1, 4000, NULL
);
433 BOOL
OnCreate(HWND hWnd
)
438 HMENU hUpdateSpeedMenu
;
439 HMENU hCPUHistoryMenu
;
446 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
448 /* Initialize the Windows Common Controls DLL */
449 InitCommonControls();
451 /* Get the minimum window sizes */
452 GetWindowRect(hWnd
, &rc
);
453 nMinimumWidth
= (rc
.right
- rc
.left
);
454 nMinimumHeight
= (rc
.bottom
- rc
.top
);
456 /* Create the status bar */
457 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
461 /* Create the status bar panes */
465 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
467 /* Create tab pages */
468 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
470 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
471 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
472 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
474 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
475 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
476 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
480 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
481 memset(&item
, 0, sizeof(TCITEM
));
482 item
.mask
= TCIF_TEXT
;
483 item
.pszText
= szTemp
;
484 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
485 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
486 memset(&item
, 0, sizeof(TCITEM
));
487 item
.mask
= TCIF_TEXT
;
488 item
.pszText
= szTemp
;
489 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
490 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
491 memset(&item
, 0, sizeof(TCITEM
));
492 item
.mask
= TCIF_TEXT
;
493 item
.pszText
= szTemp
;
494 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
496 /* Size everything correctly */
497 GetClientRect(hWnd
, &rc
);
498 nOldWidth
= rc
.right
;
499 nOldHeight
= rc
.bottom
;
500 /* nOldStartX = rc.left; */
501 /*nOldStartY = rc.top; */
503 #define PAGE_OFFSET_LEFT 17
504 #define PAGE_OFFSET_TOP 72
505 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
506 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
508 if ((TaskManagerSettings
.Left
!= 0) ||
509 (TaskManagerSettings
.Top
!= 0) ||
510 (TaskManagerSettings
.Right
!= 0) ||
511 (TaskManagerSettings
.Bottom
!= 0))
513 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
514 #ifdef __GNUC__TEST__
515 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
);
516 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
);
517 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
);
520 if (TaskManagerSettings
.Maximized
)
521 ShowWindow(hWnd
, SW_MAXIMIZE
);
523 /* Set the always on top style */
524 hMenu
= GetMenu(hWnd
);
525 hEditMenu
= GetSubMenu(hMenu
, 1);
526 hViewMenu
= GetSubMenu(hMenu
, 2);
527 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
528 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
530 /* Check or uncheck the always on top menu item */
531 if (TaskManagerSettings
.AlwaysOnTop
) {
532 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
533 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
535 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
536 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
539 /* Check or uncheck the minimize on use menu item */
540 if (TaskManagerSettings
.MinimizeOnUse
)
541 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
543 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
545 /* Check or uncheck the hide when minimized menu item */
546 if (TaskManagerSettings
.HideWhenMinimized
)
547 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
549 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
551 /* Check or uncheck the show 16-bit tasks menu item */
552 if (TaskManagerSettings
.Show16BitTasks
)
553 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
555 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
557 /* Set the view mode */
558 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
560 if (TaskManagerSettings
.ShowKernelTimes
)
561 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
563 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
565 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
567 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
568 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
570 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
572 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
573 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
574 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
575 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
576 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
578 /* Setup update speed */
579 SetUpdateSpeed(hWnd
);
582 * Refresh the performance data
583 * Sample it twice so we can establish
584 * the delta values & cpu usage
589 RefreshApplicationPage();
590 RefreshProcessPage();
591 RefreshPerformancePage();
593 TrayIcon_ShellAddTrayIcon();
599 * This function handles all the moving events for the application
600 * It moves every child window that needs moving
602 void OnMove( WPARAM nType
, int cx
, int cy
)
604 #ifdef __GNUC__TEST__
605 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
);
606 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
);
607 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
);
612 * This function handles all the sizing events for the application
613 * It re-sizes every window, and child window that needs re-sizing
615 void OnSize( WPARAM nType
, int cx
, int cy
)
622 if (nType
== SIZE_MINIMIZED
)
624 if(TaskManagerSettings
.HideWhenMinimized
)
626 ShowWindow(hMainWnd
, SW_HIDE
);
631 nXDifference
= cx
- nOldWidth
;
632 nYDifference
= cy
- nOldHeight
;
636 /* Update the status bar size */
637 GetWindowRect(hStatusWnd
, &rc
);
638 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
640 /* Update the status bar pane sizes */
641 nParts
[0] = bInMenuLoop
? -1 : 100;
644 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
646 /* Resize the tab control */
647 GetWindowRect(hTabWnd
, &rc
);
648 cx
= (rc
.right
- rc
.left
) + nXDifference
;
649 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
650 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
652 /* Resize the application page */
653 GetWindowRect(hApplicationPage
, &rc
);
654 cx
= (rc
.right
- rc
.left
) + nXDifference
;
655 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
656 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
658 /* Resize the process page */
659 GetWindowRect(hProcessPage
, &rc
);
660 cx
= (rc
.right
- rc
.left
) + nXDifference
;
661 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
662 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
664 /* Resize the performance page */
665 GetWindowRect(hPerformancePage
, &rc
);
666 cx
= (rc
.right
- rc
.left
) + nXDifference
;
667 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
668 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
671 void LoadSettings(void)
674 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
678 /* Window size & position settings */
679 TaskManagerSettings
.Maximized
= FALSE
;
680 TaskManagerSettings
.Left
= 0;
681 TaskManagerSettings
.Top
= 0;
682 TaskManagerSettings
.Right
= 0;
683 TaskManagerSettings
.Bottom
= 0;
686 TaskManagerSettings
.ActiveTabPage
= 0;
688 /* Options menu settings */
689 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
690 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
691 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
692 TaskManagerSettings
.Show16BitTasks
= TRUE
;
694 /* Update speed settings */
695 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
697 /* Applications page settings */
698 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
700 /* Processes page settings */
701 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
703 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
704 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
705 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
706 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
709 TaskManagerSettings
.SortColumn
= 1;
710 TaskManagerSettings
.SortAscending
= TRUE
;
712 /* Performance page settings */
713 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
714 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
717 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
719 /* Read the settings */
720 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
721 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
724 * ATM, the 'ImageName' column is always visible
725 * (and grayed in configuration dialog)
726 * This will avoid troubles if the registry gets corrupted.
728 TaskManagerSettings
.Column_ImageName
= TRUE
;
734 void SaveSettings(void)
737 WCHAR szSubKey1
[] = L
"Software";
738 WCHAR szSubKey2
[] = L
"Software\\ReactOS";
739 WCHAR szSubKey3
[] = L
"Software\\ReactOS\\TaskManager";
741 /* Open (or create) the key */
743 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey1
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
746 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey2
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
749 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
751 /* Save the settings */
752 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
757 void TaskManager_OnRestoreMainWindow(void)
759 HMENU hMenu
, hOptionsMenu
;
762 hMenu
= GetMenu(hMainWnd
);
763 hOptionsMenu
= GetSubMenu(hMenu
, OPTIONS_MENU_INDEX
);
764 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
767 SetForegroundWindow(hMainWnd
);
768 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
771 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
775 /* Update the status bar pane sizes */
777 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
779 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
782 void TaskManager_OnExitMenuLoop(HWND hWnd
)
787 WCHAR szCpuUsage
[256], szProcesses
[256];
789 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
790 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
793 /* Update the status bar pane sizes */
794 GetClientRect(hWnd
, &rc
);
797 nParts
[2] = rc
.right
;
798 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
799 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
800 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
801 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
802 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
803 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
806 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
811 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
812 /* load appropriate string */
814 /* first newline terminates actual string */
815 lpsz
= wcschr(lpsz
, '\n');
819 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
822 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
826 HMENU hUpdateSpeedMenu
;
828 hMenu
= GetMenu(hMainWnd
);
829 hViewMenu
= GetSubMenu(hMenu
, 2);
830 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
832 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
833 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
835 KillTimer(hMainWnd
, 1);
837 SetUpdateSpeed(hMainWnd
);
840 void TaskManager_OnViewRefresh(void)
842 PostMessageW(hMainWnd
, WM_TIMER
, 0, 0);
845 void TaskManager_OnTabWndSelChange(void)
854 hMenu
= GetMenu(hMainWnd
);
855 hViewMenu
= GetSubMenu(hMenu
, 2);
856 hOptionsMenu
= GetSubMenu(hMenu
, 1);
857 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
858 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
859 hSubMenu
= GetSubMenu(hViewMenu
, i
);
861 DestroyMenu(hSubMenu
);
862 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
864 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
865 switch (TaskManagerSettings
.ActiveTabPage
) {
867 ShowWindow(hApplicationPage
, SW_SHOW
);
868 ShowWindow(hProcessPage
, SW_HIDE
);
869 ShowWindow(hPerformancePage
, SW_HIDE
);
870 BringWindowToTop(hApplicationPage
);
872 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
873 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
875 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
876 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
878 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
879 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
881 if (GetMenuItemCount(hMenu
) <= 4) {
882 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
884 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
885 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
887 DrawMenuBar(hMainWnd
);
889 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
892 * Give the application list control focus
894 SetFocus(hApplicationPageListCtrl
);
898 ShowWindow(hApplicationPage
, SW_HIDE
);
899 ShowWindow(hProcessPage
, SW_SHOW
);
900 ShowWindow(hPerformancePage
, SW_HIDE
);
901 BringWindowToTop(hProcessPage
);
903 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
904 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
906 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
907 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
909 if (TaskManagerSettings
.Show16BitTasks
)
910 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
911 if (GetMenuItemCount(hMenu
) > 4)
913 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
914 DrawMenuBar(hMainWnd
);
917 * Give the process list control focus
919 SetFocus(hProcessPageListCtrl
);
923 ShowWindow(hApplicationPage
, SW_HIDE
);
924 ShowWindow(hProcessPage
, SW_HIDE
);
925 ShowWindow(hPerformancePage
, SW_SHOW
);
926 BringWindowToTop(hPerformancePage
);
927 if (GetMenuItemCount(hMenu
) > 4) {
928 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
929 DrawMenuBar(hMainWnd
);
931 hSubMenu
= CreatePopupMenu();
933 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
934 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
936 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
937 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
939 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
940 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
942 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
943 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
945 if (TaskManagerSettings
.ShowKernelTimes
)
946 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
948 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
949 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
950 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
952 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
954 * Give the tab control focus
961 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
964 LPWSTR lpszTemp
= NULL
;
966 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
974 /* supplied buffer is not long enough */
975 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
978 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
979 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
982 LocalFree((HLOCAL
)lpszTemp
);