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
)
137 return OnCreate(hDlg
);
140 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
141 EndDialog(hDlg
, LOWORD(wParam
));
144 /* Process menu commands */
145 switch (LOWORD(wParam
))
148 TaskManager_OnFileNew();
150 case ID_OPTIONS_ALWAYSONTOP
:
151 TaskManager_OnOptionsAlwaysOnTop();
153 case ID_OPTIONS_MINIMIZEONUSE
:
154 TaskManager_OnOptionsMinimizeOnUse();
156 case ID_OPTIONS_HIDEWHENMINIMIZED
:
157 TaskManager_OnOptionsHideWhenMinimized();
159 case ID_OPTIONS_SHOW16BITTASKS
:
160 TaskManager_OnOptionsShow16BitTasks();
163 TaskManager_OnRestoreMainWindow();
167 case ID_VIEW_DETAILS
:
168 ApplicationPage_OnView(LOWORD(wParam
));
170 case ID_VIEW_SHOWKERNELTIMES
:
171 PerformancePage_OnViewShowKernelTimes();
173 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
174 PerformancePage_OnViewCPUHistoryOneGraphAll();
176 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
177 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
179 case ID_VIEW_UPDATESPEED_HIGH
:
180 case ID_VIEW_UPDATESPEED_NORMAL
:
181 case ID_VIEW_UPDATESPEED_LOW
:
182 case ID_VIEW_UPDATESPEED_PAUSED
:
183 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
185 case ID_VIEW_SELECTCOLUMNS
:
186 ProcessPage_OnViewSelectColumns();
188 case ID_VIEW_REFRESH
:
189 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
191 case ID_WINDOWS_TILEHORIZONTALLY
:
192 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
194 case ID_WINDOWS_TILEVERTICALLY
:
195 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
197 case ID_WINDOWS_MINIMIZE
:
198 ApplicationPage_OnWindowsMinimize();
200 case ID_WINDOWS_MAXIMIZE
:
201 ApplicationPage_OnWindowsMaximize();
203 case ID_WINDOWS_CASCADE
:
204 ApplicationPage_OnWindowsCascade();
206 case ID_WINDOWS_BRINGTOFRONT
:
207 ApplicationPage_OnWindowsBringToFront();
209 case ID_APPLICATION_PAGE_SWITCHTO
:
210 ApplicationPage_OnSwitchTo();
212 case ID_APPLICATION_PAGE_ENDTASK
:
213 ApplicationPage_OnEndTask();
215 case ID_APPLICATION_PAGE_GOTOPROCESS
:
216 ApplicationPage_OnGotoProcess();
218 case ID_PROCESS_PAGE_ENDPROCESS
:
219 ProcessPage_OnEndProcess();
221 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
222 ProcessPage_OnEndProcessTree();
224 case ID_PROCESS_PAGE_DEBUG
:
225 ProcessPage_OnDebug();
227 case ID_PROCESS_PAGE_SETAFFINITY
:
228 ProcessPage_OnSetAffinity();
230 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
231 DoSetPriority(REALTIME_PRIORITY_CLASS
);
233 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
234 DoSetPriority(HIGH_PRIORITY_CLASS
);
236 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
237 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
239 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
240 DoSetPriority(NORMAL_PRIORITY_CLASS
);
242 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
243 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
245 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
246 DoSetPriority(IDLE_PRIORITY_CLASS
);
248 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
249 ProcessPage_OnDebugChannels();
255 EndDialog(hDlg
, IDOK
);
267 HMENU hMenu
, hPopupMenu
;
271 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
273 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
274 hPopupMenu
= GetSubMenu(hMenu
, 0);
276 if(IsWindowVisible(hMainWnd
))
278 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
282 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
287 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
290 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
293 SetForegroundWindow(hMainWnd
);
294 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
299 case WM_LBUTTONDBLCLK
:
300 TaskManager_OnRestoreMainWindow();
306 pnmh
= (LPNMHDR
)lParam
;
307 if ((pnmh
->hwndFrom
== hTabWnd
) &&
308 (pnmh
->idFrom
== IDC_TAB
) &&
309 (pnmh
->code
== TCN_SELCHANGE
))
311 TaskManager_OnTabWndSelChange();
317 GetClientRect(hDlg
, &rc
);
318 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
319 ReleaseDC(hDlg
, hdc
);
323 hdc
= BeginPaint(hDlg
, &ps
);
324 GetClientRect(hDlg
, &rc
);
325 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
330 /* Make sure the user is sizing the dialog */
331 /* in an acceptable range */
332 pRC
= (LPRECT
)lParam
;
333 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
334 /* If the width is too small enlarge it to the minimum */
335 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
336 pRC
->left
= pRC
->right
- nMinimumWidth
;
338 /* If the width is too small enlarge it to the minimum */
339 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
340 pRC
->right
= pRC
->left
+ nMinimumWidth
;
342 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
343 /* If the height is too small enlarge it to the minimum */
344 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
345 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
347 /* If the height is too small enlarge it to the minimum */
348 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
349 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
355 /* Handle the window sizing in it's own function */
356 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
360 /* Handle the window moving in it's own function */
361 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
365 ShowWindow(hDlg
, SW_HIDE
);
366 TrayIcon_ShellRemoveTrayIcon();
367 wp
.length
= sizeof(WINDOWPLACEMENT
);
368 GetWindowPlacement(hDlg
, &wp
);
369 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
370 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
371 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
372 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
373 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
374 TaskManagerSettings
.Maximized
= TRUE
;
376 TaskManagerSettings
.Maximized
= FALSE
;
377 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
380 /* Refresh the performance data */
382 RefreshApplicationPage();
383 RefreshProcessPage();
384 RefreshPerformancePage();
385 TrayIcon_ShellUpdateTrayIcon();
388 case WM_ENTERMENULOOP
:
389 TaskManager_OnEnterMenuLoop(hDlg
);
391 case WM_EXITMENULOOP
:
392 TaskManager_OnExitMenuLoop(hDlg
);
395 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
397 case WM_SYSCOLORCHANGE
:
398 /* Forward WM_SYSCOLORCHANGE to common controls */
399 SendMessage(hApplicationPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
400 SendMessage(hProcessPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
401 SendMessage(hProcessPageHeaderCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
408 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
410 SetBkColor(hDC
, clr
);
411 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
414 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
418 SetBkColor(hDC
, clr
);
422 rect
.bottom
= y
+ cy
;
423 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
426 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
428 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
429 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
430 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
431 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
434 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
436 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
437 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
440 static void SetUpdateSpeed(HWND hWnd
)
442 /* Setup update speed (pause=fall down) */
443 switch (TaskManagerSettings
.UpdateSpeed
) {
444 case ID_VIEW_UPDATESPEED_HIGH
:
445 SetTimer(hWnd
, 1, 1000, NULL
);
447 case ID_VIEW_UPDATESPEED_NORMAL
:
448 SetTimer(hWnd
, 1, 2000, NULL
);
450 case ID_VIEW_UPDATESPEED_LOW
:
451 SetTimer(hWnd
, 1, 4000, NULL
);
456 BOOL
OnCreate(HWND hWnd
)
461 HMENU hUpdateSpeedMenu
;
462 HMENU hCPUHistoryMenu
;
469 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
471 /* Initialize the Windows Common Controls DLL */
472 InitCommonControls();
474 /* Get the minimum window sizes */
475 GetWindowRect(hWnd
, &rc
);
476 nMinimumWidth
= (rc
.right
- rc
.left
);
477 nMinimumHeight
= (rc
.bottom
- rc
.top
);
479 /* Create the status bar */
480 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
484 /* Create the status bar panes */
485 nParts
[0] = STATUS_SIZE1
;
486 nParts
[1] = STATUS_SIZE2
;
487 nParts
[2] = STATUS_SIZE3
;
488 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
490 /* Create tab pages */
491 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
493 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
494 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
495 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
497 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
498 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
499 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
503 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
504 memset(&item
, 0, sizeof(TCITEM
));
505 item
.mask
= TCIF_TEXT
;
506 item
.pszText
= szTemp
;
507 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
508 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
509 memset(&item
, 0, sizeof(TCITEM
));
510 item
.mask
= TCIF_TEXT
;
511 item
.pszText
= szTemp
;
512 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
513 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
514 memset(&item
, 0, sizeof(TCITEM
));
515 item
.mask
= TCIF_TEXT
;
516 item
.pszText
= szTemp
;
517 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
519 /* Size everything correctly */
520 GetClientRect(hWnd
, &rc
);
521 nOldWidth
= rc
.right
;
522 nOldHeight
= rc
.bottom
;
523 /* nOldStartX = rc.left; */
524 /*nOldStartY = rc.top; */
526 #define PAGE_OFFSET_LEFT 17
527 #define PAGE_OFFSET_TOP 72
528 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
529 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
531 if ((TaskManagerSettings
.Left
!= 0) ||
532 (TaskManagerSettings
.Top
!= 0) ||
533 (TaskManagerSettings
.Right
!= 0) ||
534 (TaskManagerSettings
.Bottom
!= 0))
536 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
537 #ifdef __GNUC__TEST__
538 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
);
539 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
);
540 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
);
543 if (TaskManagerSettings
.Maximized
)
544 ShowWindow(hWnd
, SW_MAXIMIZE
);
546 /* Set the always on top style */
547 hMenu
= GetMenu(hWnd
);
548 hEditMenu
= GetSubMenu(hMenu
, 1);
549 hViewMenu
= GetSubMenu(hMenu
, 2);
550 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
551 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
553 /* Check or uncheck the always on top menu item */
554 if (TaskManagerSettings
.AlwaysOnTop
) {
555 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
556 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
558 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
559 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
562 /* Check or uncheck the minimize on use menu item */
563 if (TaskManagerSettings
.MinimizeOnUse
)
564 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
566 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
568 /* Check or uncheck the hide when minimized menu item */
569 if (TaskManagerSettings
.HideWhenMinimized
)
570 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
572 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
574 /* Check or uncheck the show 16-bit tasks menu item */
575 if (TaskManagerSettings
.Show16BitTasks
)
576 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
578 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
580 /* Set the view mode */
581 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
583 if (TaskManagerSettings
.ShowKernelTimes
)
584 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
586 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
588 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
590 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
591 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
593 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
595 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
596 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
597 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
598 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
599 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
601 /* Setup update speed */
602 SetUpdateSpeed(hWnd
);
605 * Refresh the performance data
606 * Sample it twice so we can establish
607 * the delta values & cpu usage
612 RefreshApplicationPage();
613 RefreshProcessPage();
614 RefreshPerformancePage();
616 TrayIcon_ShellAddTrayIcon();
622 * This function handles all the moving events for the application
623 * It moves every child window that needs moving
625 void OnMove( WPARAM nType
, int cx
, int cy
)
627 #ifdef __GNUC__TEST__
628 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
);
629 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
);
630 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
);
635 * This function handles all the sizing events for the application
636 * It re-sizes every window, and child window that needs re-sizing
638 void OnSize( WPARAM nType
, int cx
, int cy
)
645 if (nType
== SIZE_MINIMIZED
)
647 if(TaskManagerSettings
.HideWhenMinimized
)
649 ShowWindow(hMainWnd
, SW_HIDE
);
654 nXDifference
= cx
- nOldWidth
;
655 nYDifference
= cy
- nOldHeight
;
659 /* Update the status bar size */
660 GetWindowRect(hStatusWnd
, &rc
);
661 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
663 /* Update the status bar pane sizes */
664 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
665 nParts
[1] = STATUS_SIZE2
;
667 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
669 /* Resize the tab control */
670 GetWindowRect(hTabWnd
, &rc
);
671 cx
= (rc
.right
- rc
.left
) + nXDifference
;
672 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
673 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
675 /* Resize the application page */
676 GetWindowRect(hApplicationPage
, &rc
);
677 cx
= (rc
.right
- rc
.left
) + nXDifference
;
678 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
679 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
681 /* Resize the process page */
682 GetWindowRect(hProcessPage
, &rc
);
683 cx
= (rc
.right
- rc
.left
) + nXDifference
;
684 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
685 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
687 /* Resize the performance page */
688 GetWindowRect(hPerformancePage
, &rc
);
689 cx
= (rc
.right
- rc
.left
) + nXDifference
;
690 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
691 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
694 void LoadSettings(void)
697 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
701 /* Window size & position settings */
702 TaskManagerSettings
.Maximized
= FALSE
;
703 TaskManagerSettings
.Left
= 0;
704 TaskManagerSettings
.Top
= 0;
705 TaskManagerSettings
.Right
= 0;
706 TaskManagerSettings
.Bottom
= 0;
709 TaskManagerSettings
.ActiveTabPage
= 0;
711 /* Options menu settings */
712 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
713 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
714 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
715 TaskManagerSettings
.Show16BitTasks
= TRUE
;
717 /* Update speed settings */
718 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
720 /* Applications page settings */
721 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
723 /* Processes page settings */
724 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
726 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
727 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
728 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
729 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
732 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
733 TaskManagerSettings
.SortAscending
= TRUE
;
735 /* Performance page settings */
736 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
737 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
740 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
742 /* Read the settings */
743 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
744 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
747 * ATM, the 'ImageName' column is always visible
748 * (and grayed in configuration dialog)
749 * This will avoid troubles if the registry gets corrupted.
751 TaskManagerSettings
.Column_ImageName
= TRUE
;
757 void SaveSettings(void)
760 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
762 /* Open (or create) the key */
763 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
765 /* Save the settings */
766 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
771 void TaskManager_OnRestoreMainWindow(void)
773 //HMENU hMenu, hOptionsMenu;
776 //hMenu = GetMenu(hMainWnd);
777 //hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
778 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
781 SetForegroundWindow(hMainWnd
);
782 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
785 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
789 /* Update the status bar pane sizes */
791 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
793 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
796 void TaskManager_OnExitMenuLoop(HWND hWnd
)
801 WCHAR szCpuUsage
[256], szProcesses
[256];
803 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
804 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
807 /* Update the status bar pane sizes */
808 GetClientRect(hWnd
, &rc
);
809 nParts
[0] = STATUS_SIZE1
;
810 nParts
[1] = STATUS_SIZE2
;
811 nParts
[2] = rc
.right
;
812 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
813 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
814 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
815 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
816 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
817 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
820 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
825 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
826 /* load appropriate string */
828 /* first newline terminates actual string */
829 lpsz
= wcschr(lpsz
, '\n');
833 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
836 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
840 HMENU hUpdateSpeedMenu
;
842 hMenu
= GetMenu(hMainWnd
);
843 hViewMenu
= GetSubMenu(hMenu
, 2);
844 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
846 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
847 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
849 KillTimer(hMainWnd
, 1);
851 SetUpdateSpeed(hMainWnd
);
854 void TaskManager_OnTabWndSelChange(void)
864 hMenu
= GetMenu(hMainWnd
);
865 hViewMenu
= GetSubMenu(hMenu
, 2);
866 hOptionsMenu
= GetSubMenu(hMenu
, 1);
867 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
868 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
869 hSubMenu
= GetSubMenu(hViewMenu
, i
);
871 DestroyMenu(hSubMenu
);
872 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
874 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
875 switch (TaskManagerSettings
.ActiveTabPage
) {
877 ShowWindow(hApplicationPage
, SW_SHOW
);
878 ShowWindow(hProcessPage
, SW_HIDE
);
879 ShowWindow(hPerformancePage
, SW_HIDE
);
880 BringWindowToTop(hApplicationPage
);
882 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
883 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
885 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
886 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
888 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
889 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
891 if (GetMenuItemCount(hMenu
) <= 4) {
892 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
894 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
895 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
897 DrawMenuBar(hMainWnd
);
899 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
902 * Give the application list control focus
904 SetFocus(hApplicationPageListCtrl
);
908 ShowWindow(hApplicationPage
, SW_HIDE
);
909 ShowWindow(hProcessPage
, SW_SHOW
);
910 ShowWindow(hPerformancePage
, SW_HIDE
);
911 BringWindowToTop(hProcessPage
);
913 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
914 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
916 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
917 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
919 if (TaskManagerSettings
.Show16BitTasks
)
920 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
921 if (GetMenuItemCount(hMenu
) > 4)
923 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
924 DrawMenuBar(hMainWnd
);
927 * Give the process list control focus
929 SetFocus(hProcessPageListCtrl
);
933 ShowWindow(hApplicationPage
, SW_HIDE
);
934 ShowWindow(hProcessPage
, SW_HIDE
);
935 ShowWindow(hPerformancePage
, SW_SHOW
);
936 BringWindowToTop(hPerformancePage
);
937 if (GetMenuItemCount(hMenu
) > 4) {
938 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
939 DrawMenuBar(hMainWnd
);
942 GetSystemInfo(&sysInfo
);
944 /* Hide CPU graph options on single CPU systems */
945 if (sysInfo
.dwNumberOfProcessors
> 1)
947 hSubMenu
= CreatePopupMenu();
949 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
950 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
952 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
953 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
955 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
956 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
958 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
959 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
961 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
964 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
965 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
967 if (TaskManagerSettings
.ShowKernelTimes
)
968 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
970 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
973 * Give the tab control focus
980 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
983 LPWSTR lpszTemp
= NULL
;
985 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
993 /* supplied buffer is not long enough */
994 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
997 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
998 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1001 LocalFree((HLOCAL
)lpszTemp
);
1006 DWORD
EndLocalThread(HANDLE
*hThread
, DWORD dwThread
)
1008 DWORD dwExitCodeThread
= 0;
1010 if (*hThread
!= NULL
) {
1011 PostThreadMessage(dwThread
,WM_QUIT
,0,0);
1015 if (WAIT_OBJECT_0
== WaitForSingleObject(*hThread
, 500))
1017 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1018 TranslateMessage(&msg
);
1019 DispatchMessage(&msg
);
1022 GetExitCodeThread(*hThread
, &dwExitCodeThread
);
1023 CloseHandle(*hThread
);
1026 return dwExitCodeThread
;