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
,
55 /* Initialize global variables */
58 /* Change our priority class to HIGH */
59 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
60 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
61 CloseHandle(hProcess
);
63 /* Now lets get the SE_DEBUG_NAME privilege
64 * so that we can debug processes
67 /* Get a token for this process. */
68 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
69 /* Get the LUID for the debug privilege. */
70 LookupPrivilegeValueW(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
72 tkp
.PrivilegeCount
= 1; /* one privilege to set */
73 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
75 /* Get the debug privilege for this process. */
76 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
80 /* Load our settings from the registry */
83 /* Initialize perf data */
84 if (!PerfDataInitialize()) {
88 DialogBoxW(hInst
, (LPCWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
90 /* Save our settings to the registry */
92 PerfDataUninitialize();
96 /* Message handler for dialog box. */
98 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
111 return OnCreate(hDlg
);
114 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
115 EndDialog(hDlg
, LOWORD(wParam
));
118 /* Process menu commands */
119 switch (LOWORD(wParam
))
122 TaskManager_OnFileNew();
124 case ID_OPTIONS_ALWAYSONTOP
:
125 TaskManager_OnOptionsAlwaysOnTop();
127 case ID_OPTIONS_MINIMIZEONUSE
:
128 TaskManager_OnOptionsMinimizeOnUse();
130 case ID_OPTIONS_HIDEWHENMINIMIZED
:
131 TaskManager_OnOptionsHideWhenMinimized();
133 case ID_OPTIONS_SHOW16BITTASKS
:
134 TaskManager_OnOptionsShow16BitTasks();
137 TaskManager_OnRestoreMainWindow();
141 case ID_VIEW_DETAILS
:
142 ApplicationPage_OnView(LOWORD(wParam
));
144 case ID_VIEW_SHOWKERNELTIMES
:
145 PerformancePage_OnViewShowKernelTimes();
147 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
148 PerformancePage_OnViewCPUHistoryOneGraphAll();
150 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
151 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
153 case ID_VIEW_UPDATESPEED_HIGH
:
154 case ID_VIEW_UPDATESPEED_NORMAL
:
155 case ID_VIEW_UPDATESPEED_LOW
:
156 case ID_VIEW_UPDATESPEED_PAUSED
:
157 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
159 case ID_VIEW_SELECTCOLUMNS
:
160 ProcessPage_OnViewSelectColumns();
162 case ID_VIEW_REFRESH
:
163 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
165 case ID_WINDOWS_TILEHORIZONTALLY
:
166 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
168 case ID_WINDOWS_TILEVERTICALLY
:
169 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
171 case ID_WINDOWS_MINIMIZE
:
172 ApplicationPage_OnWindowsMinimize();
174 case ID_WINDOWS_MAXIMIZE
:
175 ApplicationPage_OnWindowsMaximize();
177 case ID_WINDOWS_CASCADE
:
178 ApplicationPage_OnWindowsCascade();
180 case ID_WINDOWS_BRINGTOFRONT
:
181 ApplicationPage_OnWindowsBringToFront();
183 case ID_APPLICATION_PAGE_SWITCHTO
:
184 ApplicationPage_OnSwitchTo();
186 case ID_APPLICATION_PAGE_ENDTASK
:
187 ApplicationPage_OnEndTask();
189 case ID_APPLICATION_PAGE_GOTOPROCESS
:
190 ApplicationPage_OnGotoProcess();
192 case ID_PROCESS_PAGE_ENDPROCESS
:
193 ProcessPage_OnEndProcess();
195 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
196 ProcessPage_OnEndProcessTree();
198 case ID_PROCESS_PAGE_DEBUG
:
199 ProcessPage_OnDebug();
201 case ID_PROCESS_PAGE_SETAFFINITY
:
202 ProcessPage_OnSetAffinity();
204 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
205 DoSetPriority(REALTIME_PRIORITY_CLASS
);
207 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
208 DoSetPriority(HIGH_PRIORITY_CLASS
);
210 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
211 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
213 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
214 DoSetPriority(NORMAL_PRIORITY_CLASS
);
216 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
217 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
219 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
220 DoSetPriority(IDLE_PRIORITY_CLASS
);
222 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
223 ProcessPage_OnDebugChannels();
229 EndDialog(hDlg
, IDOK
);
241 HMENU hMenu
, hPopupMenu
;
245 OnTop
= ((GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
247 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
248 hPopupMenu
= GetSubMenu(hMenu
, 0);
250 if(IsWindowVisible(hMainWnd
))
252 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
256 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
261 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
264 SetForegroundWindow(hMainWnd
);
265 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
270 case WM_LBUTTONDBLCLK
:
271 TaskManager_OnRestoreMainWindow();
277 idctrl
= (int)wParam
;
278 pnmh
= (LPNMHDR
)lParam
;
279 if ((pnmh
->hwndFrom
== hTabWnd
) &&
280 (pnmh
->idFrom
== IDC_TAB
) &&
281 (pnmh
->code
== TCN_SELCHANGE
))
283 TaskManager_OnTabWndSelChange();
289 GetClientRect(hDlg
, &rc
);
290 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
291 ReleaseDC(hDlg
, hdc
);
295 hdc
= BeginPaint(hDlg
, &ps
);
296 GetClientRect(hDlg
, &rc
);
297 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
302 /* Make sure the user is sizing the dialog */
303 /* in an acceptable range */
304 pRC
= (LPRECT
)lParam
;
305 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
306 /* If the width is too small enlarge it to the minimum */
307 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
308 pRC
->left
= pRC
->right
- nMinimumWidth
;
310 /* If the width is too small enlarge it to the minimum */
311 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
312 pRC
->right
= pRC
->left
+ nMinimumWidth
;
314 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
315 /* If the height is too small enlarge it to the minimum */
316 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
317 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
319 /* If the height is too small enlarge it to the minimum */
320 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
321 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
327 /* Handle the window sizing in it's own function */
328 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
332 /* Handle the window moving in it's own function */
333 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
337 ShowWindow(hDlg
, SW_HIDE
);
338 TrayIcon_ShellRemoveTrayIcon();
339 wp
.length
= sizeof(WINDOWPLACEMENT
);
340 GetWindowPlacement(hDlg
, &wp
);
341 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
342 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
343 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
344 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
345 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
346 TaskManagerSettings
.Maximized
= TRUE
;
348 TaskManagerSettings
.Maximized
= FALSE
;
349 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
352 /* Refresh the performance data */
354 RefreshApplicationPage();
355 RefreshProcessPage();
356 RefreshPerformancePage();
357 TrayIcon_ShellUpdateTrayIcon();
360 case WM_ENTERMENULOOP
:
361 TaskManager_OnEnterMenuLoop(hDlg
);
363 case WM_EXITMENULOOP
:
364 TaskManager_OnExitMenuLoop(hDlg
);
367 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
374 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
376 SetBkColor(hDC
, clr
);
377 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
380 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
384 SetBkColor(hDC
, clr
);
388 rect
.bottom
= y
+ cy
;
389 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
392 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
394 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
395 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
396 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
397 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
400 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
402 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
403 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
406 static void SetUpdateSpeed(HWND hWnd
)
408 /* Setup update speed (pause=fall down) */
409 switch (TaskManagerSettings
.UpdateSpeed
) {
410 case ID_VIEW_UPDATESPEED_HIGH
:
411 SetTimer(hWnd
, 1, 1000, NULL
);
413 case ID_VIEW_UPDATESPEED_NORMAL
:
414 SetTimer(hWnd
, 1, 2000, NULL
);
416 case ID_VIEW_UPDATESPEED_LOW
:
417 SetTimer(hWnd
, 1, 4000, NULL
);
422 BOOL
OnCreate(HWND hWnd
)
427 HMENU hUpdateSpeedMenu
;
428 HMENU hCPUHistoryMenu
;
435 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
437 /* Initialize the Windows Common Controls DLL */
438 InitCommonControls();
440 /* Get the minimum window sizes */
441 GetWindowRect(hWnd
, &rc
);
442 nMinimumWidth
= (rc
.right
- rc
.left
);
443 nMinimumHeight
= (rc
.bottom
- rc
.top
);
445 /* Create the status bar */
446 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
450 /* Create the status bar panes */
454 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
456 /* Create tab pages */
457 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
459 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
460 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
461 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
463 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
464 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
465 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
469 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
470 memset(&item
, 0, sizeof(TCITEM
));
471 item
.mask
= TCIF_TEXT
;
472 item
.pszText
= szTemp
;
473 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
474 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
475 memset(&item
, 0, sizeof(TCITEM
));
476 item
.mask
= TCIF_TEXT
;
477 item
.pszText
= szTemp
;
478 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
479 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
480 memset(&item
, 0, sizeof(TCITEM
));
481 item
.mask
= TCIF_TEXT
;
482 item
.pszText
= szTemp
;
483 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
485 /* Size everything correctly */
486 GetClientRect(hWnd
, &rc
);
487 nOldWidth
= rc
.right
;
488 nOldHeight
= rc
.bottom
;
489 /* nOldStartX = rc.left; */
490 /*nOldStartY = rc.top; */
492 #define PAGE_OFFSET_LEFT 17
493 #define PAGE_OFFSET_TOP 72
494 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
495 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
497 if ((TaskManagerSettings
.Left
!= 0) ||
498 (TaskManagerSettings
.Top
!= 0) ||
499 (TaskManagerSettings
.Right
!= 0) ||
500 (TaskManagerSettings
.Bottom
!= 0))
502 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
503 #ifdef __GNUC__TEST__
504 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
);
505 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
);
506 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
);
509 if (TaskManagerSettings
.Maximized
)
510 ShowWindow(hWnd
, SW_MAXIMIZE
);
512 /* Set the always on top style */
513 hMenu
= GetMenu(hWnd
);
514 hEditMenu
= GetSubMenu(hMenu
, 1);
515 hViewMenu
= GetSubMenu(hMenu
, 2);
516 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
517 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
519 /* Check or uncheck the always on top menu item */
520 if (TaskManagerSettings
.AlwaysOnTop
) {
521 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
522 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
524 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
525 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
528 /* Check or uncheck the minimize on use menu item */
529 if (TaskManagerSettings
.MinimizeOnUse
)
530 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
532 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
534 /* Check or uncheck the hide when minimized menu item */
535 if (TaskManagerSettings
.HideWhenMinimized
)
536 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
538 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
540 /* Check or uncheck the show 16-bit tasks menu item */
541 if (TaskManagerSettings
.Show16BitTasks
)
542 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
544 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
546 /* Set the view mode */
547 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
549 if (TaskManagerSettings
.ShowKernelTimes
)
550 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
552 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
554 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
556 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
557 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
559 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
561 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
562 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
563 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
564 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
565 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
567 /* Setup update speed */
568 SetUpdateSpeed(hWnd
);
571 * Refresh the performance data
572 * Sample it twice so we can establish
573 * the delta values & cpu usage
578 RefreshApplicationPage();
579 RefreshProcessPage();
580 RefreshPerformancePage();
582 TrayIcon_ShellAddTrayIcon();
588 * This function handles all the moving events for the application
589 * It moves every child window that needs moving
591 void OnMove( WPARAM nType
, int cx
, int cy
)
593 #ifdef __GNUC__TEST__
594 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
);
595 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
);
596 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
);
601 * This function handles all the sizing events for the application
602 * It re-sizes every window, and child window that needs re-sizing
604 void OnSize( WPARAM nType
, int cx
, int cy
)
611 if (nType
== SIZE_MINIMIZED
)
613 if(TaskManagerSettings
.HideWhenMinimized
)
615 ShowWindow(hMainWnd
, SW_HIDE
);
620 nXDifference
= cx
- nOldWidth
;
621 nYDifference
= cy
- nOldHeight
;
625 /* Update the status bar size */
626 GetWindowRect(hStatusWnd
, &rc
);
627 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
629 /* Update the status bar pane sizes */
630 nParts
[0] = bInMenuLoop
? -1 : 100;
633 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
635 /* Resize the tab control */
636 GetWindowRect(hTabWnd
, &rc
);
637 cx
= (rc
.right
- rc
.left
) + nXDifference
;
638 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
639 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
641 /* Resize the application page */
642 GetWindowRect(hApplicationPage
, &rc
);
643 cx
= (rc
.right
- rc
.left
) + nXDifference
;
644 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
645 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
647 /* Resize the process page */
648 GetWindowRect(hProcessPage
, &rc
);
649 cx
= (rc
.right
- rc
.left
) + nXDifference
;
650 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
651 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
653 /* Resize the performance page */
654 GetWindowRect(hPerformancePage
, &rc
);
655 cx
= (rc
.right
- rc
.left
) + nXDifference
;
656 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
657 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
660 void LoadSettings(void)
663 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
667 /* Window size & position settings */
668 TaskManagerSettings
.Maximized
= FALSE
;
669 TaskManagerSettings
.Left
= 0;
670 TaskManagerSettings
.Top
= 0;
671 TaskManagerSettings
.Right
= 0;
672 TaskManagerSettings
.Bottom
= 0;
675 TaskManagerSettings
.ActiveTabPage
= 0;
677 /* Options menu settings */
678 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
679 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
680 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
681 TaskManagerSettings
.Show16BitTasks
= TRUE
;
683 /* Update speed settings */
684 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
686 /* Applications page settings */
687 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
689 /* Processes page settings */
690 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
692 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
693 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
694 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
695 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
698 TaskManagerSettings
.SortColumn
= 1;
699 TaskManagerSettings
.SortAscending
= TRUE
;
701 /* Performance page settings */
702 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
703 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
706 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
708 /* Read the settings */
709 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
710 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
713 * ATM, the 'ImageName' column is always visible
714 * (and grayed in configuration dialog)
715 * This will avoid troubles if the registry gets corrupted.
717 TaskManagerSettings
.Column_ImageName
= TRUE
;
723 void SaveSettings(void)
726 WCHAR szSubKey1
[] = L
"Software";
727 WCHAR szSubKey2
[] = L
"Software\\ReactOS";
728 WCHAR szSubKey3
[] = L
"Software\\ReactOS\\TaskManager";
730 /* Open (or create) the key */
732 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey1
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
735 RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey2
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
738 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
740 /* Save the settings */
741 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
746 void TaskManager_OnRestoreMainWindow(void)
748 HMENU hMenu
, hOptionsMenu
;
751 hMenu
= GetMenu(hMainWnd
);
752 hOptionsMenu
= GetSubMenu(hMenu
, OPTIONS_MENU_INDEX
);
753 OnTop
= ((GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
756 SetForegroundWindow(hMainWnd
);
757 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
760 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
764 /* Update the status bar pane sizes */
766 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
768 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
771 void TaskManager_OnExitMenuLoop(HWND hWnd
)
776 WCHAR szCpuUsage
[256], szProcesses
[256];
778 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
779 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
782 /* Update the status bar pane sizes */
783 GetClientRect(hWnd
, &rc
);
786 nParts
[2] = rc
.right
;
787 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
788 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
789 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
790 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
791 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
792 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
795 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
800 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
801 /* load appropriate string */
803 /* first newline terminates actual string */
804 lpsz
= wcschr(lpsz
, '\n');
808 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
811 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
815 HMENU hUpdateSpeedMenu
;
817 hMenu
= GetMenu(hMainWnd
);
818 hViewMenu
= GetSubMenu(hMenu
, 2);
819 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
821 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
822 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
824 KillTimer(hMainWnd
, 1);
826 SetUpdateSpeed(hMainWnd
);
829 void TaskManager_OnViewRefresh(void)
831 PostMessageW(hMainWnd
, WM_TIMER
, 0, 0);
834 void TaskManager_OnTabWndSelChange(void)
843 hMenu
= GetMenu(hMainWnd
);
844 hViewMenu
= GetSubMenu(hMenu
, 2);
845 hOptionsMenu
= GetSubMenu(hMenu
, 1);
846 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
847 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
848 hSubMenu
= GetSubMenu(hViewMenu
, i
);
850 DestroyMenu(hSubMenu
);
851 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
853 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
854 switch (TaskManagerSettings
.ActiveTabPage
) {
856 ShowWindow(hApplicationPage
, SW_SHOW
);
857 ShowWindow(hProcessPage
, SW_HIDE
);
858 ShowWindow(hPerformancePage
, SW_HIDE
);
859 BringWindowToTop(hApplicationPage
);
861 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
862 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
864 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
865 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
867 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
868 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
870 if (GetMenuItemCount(hMenu
) <= 4) {
871 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
873 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
874 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
876 DrawMenuBar(hMainWnd
);
878 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
881 * Give the application list control focus
883 SetFocus(hApplicationPageListCtrl
);
887 ShowWindow(hApplicationPage
, SW_HIDE
);
888 ShowWindow(hProcessPage
, SW_SHOW
);
889 ShowWindow(hPerformancePage
, SW_HIDE
);
890 BringWindowToTop(hProcessPage
);
892 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
893 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
895 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
896 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
898 if (TaskManagerSettings
.Show16BitTasks
)
899 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
900 if (GetMenuItemCount(hMenu
) > 4)
902 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
903 DrawMenuBar(hMainWnd
);
906 * Give the process list control focus
908 SetFocus(hProcessPageListCtrl
);
912 ShowWindow(hApplicationPage
, SW_HIDE
);
913 ShowWindow(hProcessPage
, SW_HIDE
);
914 ShowWindow(hPerformancePage
, SW_SHOW
);
915 BringWindowToTop(hPerformancePage
);
916 if (GetMenuItemCount(hMenu
) > 4) {
917 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
918 DrawMenuBar(hMainWnd
);
920 hSubMenu
= CreatePopupMenu();
922 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
923 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
925 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
926 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
928 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
929 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
931 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
932 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
934 if (TaskManagerSettings
.ShowKernelTimes
)
935 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
937 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
938 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
939 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
941 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
943 * Give the tab control focus
950 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
953 LPWSTR lpszTemp
= NULL
;
955 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
963 /* supplied buffer is not long enough */
964 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
967 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
968 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
971 LocalFree((HLOCAL
)lpszTemp
);