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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
)
60 /* Restore existing taskmanager and bring window to front */
61 /* Relies on the fact that the application title string and window title are the same */
65 LoadString(hInst
, IDS_APP_TITLE
, szTaskmgr
, sizeof(szTaskmgr
)/sizeof(TCHAR
));
66 hTaskMgr
= FindWindow(NULL
, szTaskmgr
);
70 SendMessage(hTaskMgr
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
71 SetForegroundWindow(hTaskMgr
);
80 /* Initialize global variables */
83 /* Change our priority class to HIGH */
84 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
85 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
86 CloseHandle(hProcess
);
88 /* Now lets get the SE_DEBUG_NAME privilege
89 * so that we can debug processes
92 /* Get a token for this process. */
93 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
94 /* Get the LUID for the debug privilege. */
95 LookupPrivilegeValueW(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
97 tkp
.PrivilegeCount
= 1; /* one privilege to set */
98 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
100 /* Get the debug privilege for this process. */
101 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
105 /* Load our settings from the registry */
108 /* Initialize perf data */
109 if (!PerfDataInitialize()) {
113 DialogBoxW(hInst
, (LPCWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
115 /* Save our settings to the registry */
117 PerfDataUninitialize();
121 /* Message handler for dialog box. */
123 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
138 return OnCreate(hDlg
);
141 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
142 EndDialog(hDlg
, LOWORD(wParam
));
145 /* Process menu commands */
146 switch (LOWORD(wParam
))
149 TaskManager_OnFileNew();
151 case ID_OPTIONS_ALWAYSONTOP
:
152 TaskManager_OnOptionsAlwaysOnTop();
154 case ID_OPTIONS_MINIMIZEONUSE
:
155 TaskManager_OnOptionsMinimizeOnUse();
157 case ID_OPTIONS_HIDEWHENMINIMIZED
:
158 TaskManager_OnOptionsHideWhenMinimized();
160 case ID_OPTIONS_SHOW16BITTASKS
:
161 TaskManager_OnOptionsShow16BitTasks();
164 TaskManager_OnRestoreMainWindow();
168 case ID_VIEW_DETAILS
:
169 ApplicationPage_OnView(LOWORD(wParam
));
171 case ID_VIEW_SHOWKERNELTIMES
:
172 PerformancePage_OnViewShowKernelTimes();
174 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
175 PerformancePage_OnViewCPUHistoryOneGraphAll();
177 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
178 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
180 case ID_VIEW_UPDATESPEED_HIGH
:
181 case ID_VIEW_UPDATESPEED_NORMAL
:
182 case ID_VIEW_UPDATESPEED_LOW
:
183 case ID_VIEW_UPDATESPEED_PAUSED
:
184 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
186 case ID_VIEW_SELECTCOLUMNS
:
187 ProcessPage_OnViewSelectColumns();
189 case ID_VIEW_REFRESH
:
190 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
192 case ID_WINDOWS_TILEHORIZONTALLY
:
193 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
195 case ID_WINDOWS_TILEVERTICALLY
:
196 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
198 case ID_WINDOWS_MINIMIZE
:
199 ApplicationPage_OnWindowsMinimize();
201 case ID_WINDOWS_MAXIMIZE
:
202 ApplicationPage_OnWindowsMaximize();
204 case ID_WINDOWS_CASCADE
:
205 ApplicationPage_OnWindowsCascade();
207 case ID_WINDOWS_BRINGTOFRONT
:
208 ApplicationPage_OnWindowsBringToFront();
210 case ID_APPLICATION_PAGE_SWITCHTO
:
211 ApplicationPage_OnSwitchTo();
213 case ID_APPLICATION_PAGE_ENDTASK
:
214 ApplicationPage_OnEndTask();
216 case ID_APPLICATION_PAGE_GOTOPROCESS
:
217 ApplicationPage_OnGotoProcess();
219 case ID_PROCESS_PAGE_ENDPROCESS
:
220 ProcessPage_OnEndProcess();
222 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
223 ProcessPage_OnEndProcessTree();
225 case ID_PROCESS_PAGE_DEBUG
:
226 ProcessPage_OnDebug();
228 case ID_PROCESS_PAGE_SETAFFINITY
:
229 ProcessPage_OnSetAffinity();
231 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
232 DoSetPriority(REALTIME_PRIORITY_CLASS
);
234 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
235 DoSetPriority(HIGH_PRIORITY_CLASS
);
237 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
238 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
240 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
241 DoSetPriority(NORMAL_PRIORITY_CLASS
);
243 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
244 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
246 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
247 DoSetPriority(IDLE_PRIORITY_CLASS
);
249 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
250 ProcessPage_OnDebugChannels();
256 EndDialog(hDlg
, IDOK
);
268 HMENU hMenu
, hPopupMenu
;
272 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
274 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
275 hPopupMenu
= GetSubMenu(hMenu
, 0);
277 if(IsWindowVisible(hMainWnd
))
279 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
283 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
288 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
291 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
294 SetForegroundWindow(hMainWnd
);
295 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
300 case WM_LBUTTONDBLCLK
:
301 TaskManager_OnRestoreMainWindow();
307 idctrl
= (int)wParam
;
308 pnmh
= (LPNMHDR
)lParam
;
309 if ((pnmh
->hwndFrom
== hTabWnd
) &&
310 (pnmh
->idFrom
== IDC_TAB
) &&
311 (pnmh
->code
== TCN_SELCHANGE
))
313 TaskManager_OnTabWndSelChange();
319 GetClientRect(hDlg
, &rc
);
320 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
321 ReleaseDC(hDlg
, hdc
);
325 hdc
= BeginPaint(hDlg
, &ps
);
326 GetClientRect(hDlg
, &rc
);
327 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
332 /* Make sure the user is sizing the dialog */
333 /* in an acceptable range */
334 pRC
= (LPRECT
)lParam
;
335 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
336 /* If the width is too small enlarge it to the minimum */
337 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
338 pRC
->left
= pRC
->right
- nMinimumWidth
;
340 /* If the width is too small enlarge it to the minimum */
341 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
342 pRC
->right
= pRC
->left
+ nMinimumWidth
;
344 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
345 /* If the height is too small enlarge it to the minimum */
346 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
347 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
349 /* If the height is too small enlarge it to the minimum */
350 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
351 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
357 /* Handle the window sizing in it's own function */
358 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
362 /* Handle the window moving in it's own function */
363 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
367 ShowWindow(hDlg
, SW_HIDE
);
368 TrayIcon_ShellRemoveTrayIcon();
369 wp
.length
= sizeof(WINDOWPLACEMENT
);
370 GetWindowPlacement(hDlg
, &wp
);
371 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
372 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
373 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
374 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
375 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
376 TaskManagerSettings
.Maximized
= TRUE
;
378 TaskManagerSettings
.Maximized
= FALSE
;
379 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
382 /* Refresh the performance data */
384 RefreshApplicationPage();
385 RefreshProcessPage();
386 RefreshPerformancePage();
387 TrayIcon_ShellUpdateTrayIcon();
390 case WM_ENTERMENULOOP
:
391 TaskManager_OnEnterMenuLoop(hDlg
);
393 case WM_EXITMENULOOP
:
394 TaskManager_OnExitMenuLoop(hDlg
);
397 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
404 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
406 SetBkColor(hDC
, clr
);
407 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
410 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
414 SetBkColor(hDC
, clr
);
418 rect
.bottom
= y
+ cy
;
419 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
422 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
424 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
425 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
426 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
427 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
430 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
432 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
433 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
436 static void SetUpdateSpeed(HWND hWnd
)
438 /* Setup update speed (pause=fall down) */
439 switch (TaskManagerSettings
.UpdateSpeed
) {
440 case ID_VIEW_UPDATESPEED_HIGH
:
441 SetTimer(hWnd
, 1, 1000, NULL
);
443 case ID_VIEW_UPDATESPEED_NORMAL
:
444 SetTimer(hWnd
, 1, 2000, NULL
);
446 case ID_VIEW_UPDATESPEED_LOW
:
447 SetTimer(hWnd
, 1, 4000, NULL
);
452 BOOL
OnCreate(HWND hWnd
)
457 HMENU hUpdateSpeedMenu
;
458 HMENU hCPUHistoryMenu
;
465 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
467 /* Initialize the Windows Common Controls DLL */
468 InitCommonControls();
470 /* Get the minimum window sizes */
471 GetWindowRect(hWnd
, &rc
);
472 nMinimumWidth
= (rc
.right
- rc
.left
);
473 nMinimumHeight
= (rc
.bottom
- rc
.top
);
475 /* Create the status bar */
476 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
480 /* Create the status bar panes */
481 nParts
[0] = STATUS_SIZE1
;
482 nParts
[1] = STATUS_SIZE2
;
483 nParts
[2] = STATUS_SIZE3
;
484 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
486 /* Create tab pages */
487 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
489 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
490 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
491 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
493 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
494 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
495 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
499 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
500 memset(&item
, 0, sizeof(TCITEM
));
501 item
.mask
= TCIF_TEXT
;
502 item
.pszText
= szTemp
;
503 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
504 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
505 memset(&item
, 0, sizeof(TCITEM
));
506 item
.mask
= TCIF_TEXT
;
507 item
.pszText
= szTemp
;
508 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
509 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
510 memset(&item
, 0, sizeof(TCITEM
));
511 item
.mask
= TCIF_TEXT
;
512 item
.pszText
= szTemp
;
513 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
515 /* Size everything correctly */
516 GetClientRect(hWnd
, &rc
);
517 nOldWidth
= rc
.right
;
518 nOldHeight
= rc
.bottom
;
519 /* nOldStartX = rc.left; */
520 /*nOldStartY = rc.top; */
522 #define PAGE_OFFSET_LEFT 17
523 #define PAGE_OFFSET_TOP 72
524 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
525 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
527 if ((TaskManagerSettings
.Left
!= 0) ||
528 (TaskManagerSettings
.Top
!= 0) ||
529 (TaskManagerSettings
.Right
!= 0) ||
530 (TaskManagerSettings
.Bottom
!= 0))
532 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
533 #ifdef __GNUC__TEST__
534 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
);
535 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
);
536 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
);
539 if (TaskManagerSettings
.Maximized
)
540 ShowWindow(hWnd
, SW_MAXIMIZE
);
542 /* Set the always on top style */
543 hMenu
= GetMenu(hWnd
);
544 hEditMenu
= GetSubMenu(hMenu
, 1);
545 hViewMenu
= GetSubMenu(hMenu
, 2);
546 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
547 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
549 /* Check or uncheck the always on top menu item */
550 if (TaskManagerSettings
.AlwaysOnTop
) {
551 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
552 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
554 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
555 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
558 /* Check or uncheck the minimize on use menu item */
559 if (TaskManagerSettings
.MinimizeOnUse
)
560 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
562 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
564 /* Check or uncheck the hide when minimized menu item */
565 if (TaskManagerSettings
.HideWhenMinimized
)
566 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
568 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
570 /* Check or uncheck the show 16-bit tasks menu item */
571 if (TaskManagerSettings
.Show16BitTasks
)
572 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
574 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
576 /* Set the view mode */
577 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
579 if (TaskManagerSettings
.ShowKernelTimes
)
580 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
582 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
584 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
586 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
587 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
589 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
591 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
592 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
593 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
594 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
595 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
597 /* Setup update speed */
598 SetUpdateSpeed(hWnd
);
601 * Refresh the performance data
602 * Sample it twice so we can establish
603 * the delta values & cpu usage
608 RefreshApplicationPage();
609 RefreshProcessPage();
610 RefreshPerformancePage();
612 TrayIcon_ShellAddTrayIcon();
618 * This function handles all the moving events for the application
619 * It moves every child window that needs moving
621 void OnMove( WPARAM nType
, int cx
, int cy
)
623 #ifdef __GNUC__TEST__
624 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
);
625 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
);
626 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
);
631 * This function handles all the sizing events for the application
632 * It re-sizes every window, and child window that needs re-sizing
634 void OnSize( WPARAM nType
, int cx
, int cy
)
641 if (nType
== SIZE_MINIMIZED
)
643 if(TaskManagerSettings
.HideWhenMinimized
)
645 ShowWindow(hMainWnd
, SW_HIDE
);
650 nXDifference
= cx
- nOldWidth
;
651 nYDifference
= cy
- nOldHeight
;
655 /* Update the status bar size */
656 GetWindowRect(hStatusWnd
, &rc
);
657 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
659 /* Update the status bar pane sizes */
660 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
661 nParts
[1] = STATUS_SIZE2
;
663 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
665 /* Resize the tab control */
666 GetWindowRect(hTabWnd
, &rc
);
667 cx
= (rc
.right
- rc
.left
) + nXDifference
;
668 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
669 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
671 /* Resize the application page */
672 GetWindowRect(hApplicationPage
, &rc
);
673 cx
= (rc
.right
- rc
.left
) + nXDifference
;
674 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
675 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
677 /* Resize the process page */
678 GetWindowRect(hProcessPage
, &rc
);
679 cx
= (rc
.right
- rc
.left
) + nXDifference
;
680 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
681 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
683 /* Resize the performance page */
684 GetWindowRect(hPerformancePage
, &rc
);
685 cx
= (rc
.right
- rc
.left
) + nXDifference
;
686 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
687 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
690 void LoadSettings(void)
693 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
697 /* Window size & position settings */
698 TaskManagerSettings
.Maximized
= FALSE
;
699 TaskManagerSettings
.Left
= 0;
700 TaskManagerSettings
.Top
= 0;
701 TaskManagerSettings
.Right
= 0;
702 TaskManagerSettings
.Bottom
= 0;
705 TaskManagerSettings
.ActiveTabPage
= 0;
707 /* Options menu settings */
708 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
709 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
710 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
711 TaskManagerSettings
.Show16BitTasks
= TRUE
;
713 /* Update speed settings */
714 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
716 /* Applications page settings */
717 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
719 /* Processes page settings */
720 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
722 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
723 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
724 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
725 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
728 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
729 TaskManagerSettings
.SortAscending
= TRUE
;
731 /* Performance page settings */
732 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
733 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
736 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
738 /* Read the settings */
739 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
740 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
743 * ATM, the 'ImageName' column is always visible
744 * (and grayed in configuration dialog)
745 * This will avoid troubles if the registry gets corrupted.
747 TaskManagerSettings
.Column_ImageName
= TRUE
;
753 void SaveSettings(void)
756 WCHAR szSubKey1
[] = L
"Software";
757 WCHAR szSubKey2
[] = L
"Software\\ReactOS";
758 WCHAR szSubKey3
[] = L
"Software\\ReactOS\\TaskManager";
760 /* Open (or create) the key */
762 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey1
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
765 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey2
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
768 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
770 /* Save the settings */
771 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
776 void TaskManager_OnRestoreMainWindow(void)
778 HMENU hMenu
, hOptionsMenu
;
781 hMenu
= GetMenu(hMainWnd
);
782 hOptionsMenu
= GetSubMenu(hMenu
, OPTIONS_MENU_INDEX
);
783 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
786 SetForegroundWindow(hMainWnd
);
787 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
790 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
794 /* Update the status bar pane sizes */
796 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
798 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
801 void TaskManager_OnExitMenuLoop(HWND hWnd
)
806 WCHAR szCpuUsage
[256], szProcesses
[256];
808 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
809 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
812 /* Update the status bar pane sizes */
813 GetClientRect(hWnd
, &rc
);
814 nParts
[0] = STATUS_SIZE1
;
815 nParts
[1] = STATUS_SIZE2
;
816 nParts
[2] = rc
.right
;
817 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
818 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
819 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
820 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
821 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
822 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
825 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
830 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
831 /* load appropriate string */
833 /* first newline terminates actual string */
834 lpsz
= wcschr(lpsz
, '\n');
838 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
841 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
845 HMENU hUpdateSpeedMenu
;
847 hMenu
= GetMenu(hMainWnd
);
848 hViewMenu
= GetSubMenu(hMenu
, 2);
849 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
851 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
852 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
854 KillTimer(hMainWnd
, 1);
856 SetUpdateSpeed(hMainWnd
);
859 void TaskManager_OnViewRefresh(void)
861 PostMessageW(hMainWnd
, WM_TIMER
, 0, 0);
864 void TaskManager_OnTabWndSelChange(void)
874 hMenu
= GetMenu(hMainWnd
);
875 hViewMenu
= GetSubMenu(hMenu
, 2);
876 hOptionsMenu
= GetSubMenu(hMenu
, 1);
877 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
878 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
879 hSubMenu
= GetSubMenu(hViewMenu
, i
);
881 DestroyMenu(hSubMenu
);
882 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
884 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
885 switch (TaskManagerSettings
.ActiveTabPage
) {
887 ShowWindow(hApplicationPage
, SW_SHOW
);
888 ShowWindow(hProcessPage
, SW_HIDE
);
889 ShowWindow(hPerformancePage
, SW_HIDE
);
890 BringWindowToTop(hApplicationPage
);
892 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
893 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
895 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
896 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
898 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
899 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
901 if (GetMenuItemCount(hMenu
) <= 4) {
902 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
904 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
905 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
907 DrawMenuBar(hMainWnd
);
909 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
912 * Give the application list control focus
914 SetFocus(hApplicationPageListCtrl
);
918 ShowWindow(hApplicationPage
, SW_HIDE
);
919 ShowWindow(hProcessPage
, SW_SHOW
);
920 ShowWindow(hPerformancePage
, SW_HIDE
);
921 BringWindowToTop(hProcessPage
);
923 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
924 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
926 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
927 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
929 if (TaskManagerSettings
.Show16BitTasks
)
930 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
931 if (GetMenuItemCount(hMenu
) > 4)
933 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
934 DrawMenuBar(hMainWnd
);
937 * Give the process list control focus
939 SetFocus(hProcessPageListCtrl
);
943 ShowWindow(hApplicationPage
, SW_HIDE
);
944 ShowWindow(hProcessPage
, SW_HIDE
);
945 ShowWindow(hPerformancePage
, SW_SHOW
);
946 BringWindowToTop(hPerformancePage
);
947 if (GetMenuItemCount(hMenu
) > 4) {
948 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
949 DrawMenuBar(hMainWnd
);
952 GetSystemInfo(&sysInfo
);
954 /* Hide CPU graph options on single CPU systems */
955 if (sysInfo
.dwNumberOfProcessors
> 1)
957 hSubMenu
= CreatePopupMenu();
959 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
960 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
962 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
963 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
965 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
966 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
968 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
969 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
971 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
974 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
975 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
977 if (TaskManagerSettings
.ShowKernelTimes
)
978 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
980 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
983 * Give the tab control focus
990 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
993 LPWSTR lpszTemp
= NULL
;
995 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1003 /* supplied buffer is not long enough */
1004 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1007 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
1008 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1011 LocalFree((HLOCAL
)lpszTemp
);