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
32 #define STATUS_WINDOW 2001
34 /* Global Variables: */
35 HINSTANCE hInst
; /* current instance */
37 HWND hMainWnd
; /* Main Window */
38 HWND hStatusWnd
; /* Status Bar Window */
39 HWND hTabWnd
; /* Tab Control Window */
41 HMENU hWindowMenu
= NULL
;
43 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
44 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
46 int nOldWidth
; /* Holds the previous client area width */
47 int nOldHeight
; /* Holds the previous client area height */
49 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
50 BOOL bWasKeyboardInput
= FALSE
; /* TabChange by Keyboard or Mouse ? */
52 TASKMANAGER_SETTINGS TaskManagerSettings
;
54 ////////////////////////////////////////////////////////////////////////////////
55 // Taken from WinSpy++ 1.7
56 // http://www.catch22.net/software/winspy
57 // Copyright (c) 2002 by J Brown
61 // Copied from uxtheme.h
62 // If you have this new header, then delete these and
63 // #include <uxtheme.h> instead!
65 #define ETDT_DISABLE 0x00000001
66 #define ETDT_ENABLE 0x00000002
67 #define ETDT_USETABTEXTURE 0x00000004
68 #define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE)
71 typedef HRESULT (WINAPI
* ETDTProc
) (HWND
, DWORD
);
74 // Try to call EnableThemeDialogTexture, if uxtheme.dll is present
76 BOOL
EnableDialogTheme(HWND hwnd
)
79 ETDTProc fnEnableThemeDialogTexture
;
81 hUXTheme
= LoadLibraryA("uxtheme.dll");
85 fnEnableThemeDialogTexture
=
86 (ETDTProc
)GetProcAddress(hUXTheme
, "EnableThemeDialogTexture");
88 if(fnEnableThemeDialogTexture
)
90 fnEnableThemeDialogTexture(hwnd
, ETDT_ENABLETAB
);
92 FreeLibrary(hUXTheme
);
97 // Failed to locate API!
98 FreeLibrary(hUXTheme
);
104 // Not running under XP? Just fail gracefully
109 int APIENTRY
wWinMain(HINSTANCE hInstance
,
110 HINSTANCE hPrevInstance
,
116 TOKEN_PRIVILEGES tkp
;
119 /* check wether we're already running or not */
120 hMutex
= CreateMutexW(NULL
, TRUE
, L
"taskmgrros");
121 if (hMutex
&& GetLastError() == ERROR_ALREADY_EXISTS
)
123 /* Restore existing taskmanager and bring window to front */
124 /* Relies on the fact that the application title string and window title are the same */
126 TCHAR szTaskmgr
[128];
128 LoadString(hInst
, IDS_APP_TITLE
, szTaskmgr
, sizeof(szTaskmgr
)/sizeof(TCHAR
));
129 hTaskMgr
= FindWindow(NULL
, szTaskmgr
);
131 if (hTaskMgr
!= NULL
)
133 SendMessage(hTaskMgr
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
134 SetForegroundWindow(hTaskMgr
);
145 /* Initialize global variables */
148 /* Change our priority class to HIGH */
149 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
150 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
151 CloseHandle(hProcess
);
153 /* Now lets get the SE_DEBUG_NAME privilege
154 * so that we can debug processes
157 /* Get a token for this process. */
158 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
))
160 /* Get the LUID for the debug privilege. */
161 if (LookupPrivilegeValueW(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
))
163 tkp
.PrivilegeCount
= 1; /* one privilege to set */
164 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
166 /* Get the debug privilege for this process. */
167 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
172 /* Load our settings from the registry */
175 /* Initialize perf data */
176 if (!PerfDataInitialize())
182 * Set our shutdown parameters: we want to shutdown the very last,
183 * without displaying any end task dialog if needed.
185 SetProcessShutdownParameters(1, SHUTDOWN_NORETRY
);
187 DialogBoxW(hInst
, (LPCWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
189 /* Save our settings to the registry */
191 PerfDataUninitialize();
194 DestroyMenu(hWindowMenu
);
198 /* Message handler for dialog box. */
200 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
214 return OnCreate(hDlg
);
217 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
218 EndDialog(hDlg
, LOWORD(wParam
));
221 /* Process menu commands */
222 switch (LOWORD(wParam
))
225 TaskManager_OnFileNew();
227 case ID_OPTIONS_ALWAYSONTOP
:
228 TaskManager_OnOptionsAlwaysOnTop();
230 case ID_OPTIONS_MINIMIZEONUSE
:
231 TaskManager_OnOptionsMinimizeOnUse();
233 case ID_OPTIONS_HIDEWHENMINIMIZED
:
234 TaskManager_OnOptionsHideWhenMinimized();
236 case ID_OPTIONS_SHOW16BITTASKS
:
237 TaskManager_OnOptionsShow16BitTasks();
240 TaskManager_OnRestoreMainWindow();
244 case ID_VIEW_DETAILS
:
245 ApplicationPage_OnView(LOWORD(wParam
));
247 case ID_VIEW_SHOWKERNELTIMES
:
248 PerformancePage_OnViewShowKernelTimes();
250 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
251 PerformancePage_OnViewCPUHistoryOneGraphAll();
253 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
254 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
256 case ID_VIEW_UPDATESPEED_HIGH
:
257 case ID_VIEW_UPDATESPEED_NORMAL
:
258 case ID_VIEW_UPDATESPEED_LOW
:
259 case ID_VIEW_UPDATESPEED_PAUSED
:
260 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
262 case ID_VIEW_SELECTCOLUMNS
:
263 ProcessPage_OnViewSelectColumns();
265 case ID_VIEW_REFRESH
:
266 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
268 case ID_WINDOWS_TILEHORIZONTALLY
:
269 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
271 case ID_WINDOWS_TILEVERTICALLY
:
272 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
274 case ID_WINDOWS_MINIMIZE
:
275 ApplicationPage_OnWindowsMinimize();
277 case ID_WINDOWS_MAXIMIZE
:
278 ApplicationPage_OnWindowsMaximize();
280 case ID_WINDOWS_CASCADE
:
281 ApplicationPage_OnWindowsCascade();
283 case ID_WINDOWS_BRINGTOFRONT
:
284 ApplicationPage_OnWindowsBringToFront();
286 case ID_APPLICATION_PAGE_SWITCHTO
:
287 ApplicationPage_OnSwitchTo();
289 case ID_APPLICATION_PAGE_ENDTASK
:
290 ApplicationPage_OnEndTask();
292 case ID_APPLICATION_PAGE_GOTOPROCESS
:
293 ApplicationPage_OnGotoProcess();
295 case ID_PROCESS_PAGE_ENDPROCESS
:
296 ProcessPage_OnEndProcess();
298 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
299 ProcessPage_OnEndProcessTree();
301 case ID_PROCESS_PAGE_DEBUG
:
302 ProcessPage_OnDebug();
304 case ID_PROCESS_PAGE_SETAFFINITY
:
305 ProcessPage_OnSetAffinity();
307 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
308 DoSetPriority(REALTIME_PRIORITY_CLASS
);
310 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
311 DoSetPriority(HIGH_PRIORITY_CLASS
);
313 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
314 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
316 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
317 DoSetPriority(NORMAL_PRIORITY_CLASS
);
319 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
320 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
322 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
323 DoSetPriority(IDLE_PRIORITY_CLASS
);
325 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
326 ProcessPage_OnDebugChannels();
330 case ID_SHUTDOWN_STANDBY
:
333 case ID_SHUTDOWN_HIBERNATE
:
334 ShutDown_Hibernate();
336 case ID_SHUTDOWN_POWEROFF
:
339 case ID_SHUTDOWN_REBOOT
:
342 case ID_SHUTDOWN_LOGOFF
:
343 ShutDown_LogOffUser();
345 case ID_SHUTDOWN_SWITCHUSER
:
346 ShutDown_SwitchUser();
348 case ID_SHUTDOWN_LOCKCOMPUTER
:
349 ShutDown_LockComputer();
351 case ID_SHUTDOWN_DISCONNECT
:
352 ShutDown_Disconnect();
354 case ID_SHUTDOWN_EJECT_COMPUTER
:
355 ShutDown_EjectComputer();
362 EndDialog(hDlg
, IDOK
);
374 HMENU hMenu
, hPopupMenu
;
378 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
380 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
381 hPopupMenu
= GetSubMenu(hMenu
, 0);
383 if(IsWindowVisible(hMainWnd
))
385 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
389 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
394 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
397 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
400 SetForegroundWindow(hMainWnd
);
401 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
406 case WM_LBUTTONDBLCLK
:
407 TaskManager_OnRestoreMainWindow();
413 pnmh
= (LPNMHDR
)lParam
;
414 if ((pnmh
->hwndFrom
== hTabWnd
) &&
415 (pnmh
->idFrom
== IDC_TAB
))
420 TaskManager_OnTabWndSelChange();
423 bWasKeyboardInput
= TRUE
;
426 bWasKeyboardInput
= FALSE
;
434 GetClientRect(hDlg
, &rc
);
435 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
436 ReleaseDC(hDlg
, hdc
);
440 hdc
= BeginPaint(hDlg
, &ps
);
441 GetClientRect(hDlg
, &rc
);
442 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
447 /* Make sure the user is sizing the dialog */
448 /* in an acceptable range */
449 pRC
= (LPRECT
)lParam
;
450 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
451 /* If the width is too small enlarge it to the minimum */
452 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
453 pRC
->left
= pRC
->right
- nMinimumWidth
;
455 /* If the width is too small enlarge it to the minimum */
456 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
457 pRC
->right
= pRC
->left
+ nMinimumWidth
;
459 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
460 /* If the height is too small enlarge it to the minimum */
461 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
462 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
464 /* If the height is too small enlarge it to the minimum */
465 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
466 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
472 /* Handle the window sizing in it's own function */
473 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
477 /* Handle the window moving in it's own function */
478 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
482 ShowWindow(hDlg
, SW_HIDE
);
483 TrayIcon_ShellRemoveTrayIcon();
484 wp
.length
= sizeof(WINDOWPLACEMENT
);
485 GetWindowPlacement(hDlg
, &wp
);
486 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
487 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
488 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
489 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
490 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
491 TaskManagerSettings
.Maximized
= TRUE
;
493 TaskManagerSettings
.Maximized
= FALSE
;
494 /* Get rid of the allocated command line cache, if any */
495 PerfDataDeallocCommandLineCache();
497 DestroyMenu(hWindowMenu
);
498 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
501 /* Refresh the performance data */
503 RefreshApplicationPage();
504 RefreshProcessPage();
505 RefreshPerformancePage();
506 TrayIcon_ShellUpdateTrayIcon();
509 case WM_ENTERMENULOOP
:
510 TaskManager_OnEnterMenuLoop(hDlg
);
512 case WM_EXITMENULOOP
:
513 TaskManager_OnExitMenuLoop(hDlg
);
516 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
518 case WM_SYSCOLORCHANGE
:
519 /* Forward WM_SYSCOLORCHANGE to common controls */
520 SendMessage(hApplicationPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
521 SendMessage(hProcessPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
522 SendMessage(hProcessPageHeaderCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
529 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
531 SetBkColor(hDC
, clr
);
532 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
535 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
539 SetBkColor(hDC
, clr
);
543 rect
.bottom
= y
+ cy
;
544 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
547 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
549 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
550 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
551 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
552 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
555 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
557 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
558 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
561 static void SetUpdateSpeed(HWND hWnd
)
563 /* Setup update speed (pause=fall down) */
564 switch (TaskManagerSettings
.UpdateSpeed
) {
565 case ID_VIEW_UPDATESPEED_HIGH
:
566 SetTimer(hWnd
, 1, 1000, NULL
);
568 case ID_VIEW_UPDATESPEED_NORMAL
:
569 SetTimer(hWnd
, 1, 2000, NULL
);
571 case ID_VIEW_UPDATESPEED_LOW
:
572 SetTimer(hWnd
, 1, 4000, NULL
);
577 BOOL
OnCreate(HWND hWnd
)
583 HMENU hUpdateSpeedMenu
;
584 HMENU hCPUHistoryMenu
;
589 WCHAR szLogOffItem
[MAX_PATH
];
594 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
596 /* Initialize the Windows Common Controls DLL */
597 InitCommonControls();
599 /* Get the minimum window sizes */
600 GetWindowRect(hWnd
, &rc
);
601 nMinimumWidth
= (rc
.right
- rc
.left
);
602 nMinimumHeight
= (rc
.bottom
- rc
.top
);
604 /* Create the status bar */
605 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
609 /* Create the status bar panes */
610 nParts
[0] = STATUS_SIZE1
;
611 nParts
[1] = STATUS_SIZE2
;
612 nParts
[2] = STATUS_SIZE3
;
613 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
615 /* Create tab pages */
616 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
618 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
619 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
620 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
622 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
623 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
624 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
628 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
629 memset(&item
, 0, sizeof(TCITEM
));
630 item
.mask
= TCIF_TEXT
;
631 item
.pszText
= szTemp
;
632 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
633 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
634 memset(&item
, 0, sizeof(TCITEM
));
635 item
.mask
= TCIF_TEXT
;
636 item
.pszText
= szTemp
;
637 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
638 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
639 memset(&item
, 0, sizeof(TCITEM
));
640 item
.mask
= TCIF_TEXT
;
641 item
.pszText
= szTemp
;
642 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
644 /* Size everything correctly */
645 GetClientRect(hWnd
, &rc
);
646 nOldWidth
= rc
.right
;
647 nOldHeight
= rc
.bottom
;
648 /* nOldStartX = rc.left; */
649 /*nOldStartY = rc.top; */
651 #define PAGE_OFFSET_LEFT 17
652 #define PAGE_OFFSET_TOP 72
653 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
654 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
656 if ((TaskManagerSettings
.Left
!= 0) ||
657 (TaskManagerSettings
.Top
!= 0) ||
658 (TaskManagerSettings
.Right
!= 0) ||
659 (TaskManagerSettings
.Bottom
!= 0))
661 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
662 #ifdef __GNUC__TEST__
663 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
);
664 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
);
665 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
);
668 if (TaskManagerSettings
.Maximized
)
669 ShowWindow(hWnd
, SW_MAXIMIZE
);
671 /* Set the always on top style */
672 hMenu
= GetMenu(hWnd
);
673 hEditMenu
= GetSubMenu(hMenu
, 1);
674 hViewMenu
= GetSubMenu(hMenu
, 2);
675 hShutMenu
= GetSubMenu(hMenu
, 4);
676 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
677 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
679 /* Check or uncheck the always on top menu item */
680 if (TaskManagerSettings
.AlwaysOnTop
) {
681 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
682 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
684 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
685 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
688 /* Check or uncheck the minimize on use menu item */
689 if (TaskManagerSettings
.MinimizeOnUse
)
690 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
692 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
694 /* Check or uncheck the hide when minimized menu item */
695 if (TaskManagerSettings
.HideWhenMinimized
)
696 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
698 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
700 /* Check or uncheck the show 16-bit tasks menu item */
701 if (TaskManagerSettings
.Show16BitTasks
)
702 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
704 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
706 /* Set the view mode */
707 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
709 if (TaskManagerSettings
.ShowKernelTimes
)
710 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
712 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
714 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
716 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
717 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
719 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
721 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
722 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
723 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
724 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
725 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
727 /* Set the username in the "Log Off %s" item of the Shutdown menu */
729 /* 1- Get the menu item text and store it temporarily */
730 GetMenuStringW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, szTemp
, 256, MF_BYCOMMAND
);
732 /* 2- Retrieve the username length first, then allocate a buffer for it and call it again */
733 if (!GetUserNameW(NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
735 lpUserName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
* sizeof(WCHAR
));
736 if (lpUserName
&& GetUserNameW(lpUserName
, &len
))
738 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, lpUserName
);
739 szLogOffItem
[sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]) - 1] = UNICODE_NULL
;
743 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
746 if (lpUserName
) HeapFree(GetProcessHeap(), 0, lpUserName
);
750 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
753 /* 3- Set the menu item text to its formatted counterpart */
754 ModifyMenuW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, MF_BYCOMMAND
| MF_STRING
, ID_SHUTDOWN_LOGOFF
, szLogOffItem
);
756 /* Setup update speed */
757 SetUpdateSpeed(hWnd
);
760 * Refresh the performance data
761 * Sample it twice so we can establish
762 * the delta values & cpu usage
767 RefreshApplicationPage();
768 RefreshProcessPage();
769 RefreshPerformancePage();
771 TrayIcon_ShellAddTrayIcon();
777 * This function handles all the moving events for the application
778 * It moves every child window that needs moving
780 void OnMove( WPARAM nType
, int cx
, int cy
)
782 #ifdef __GNUC__TEST__
783 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
);
784 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
);
785 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
);
790 * This function handles all the sizing events for the application
791 * It re-sizes every window, and child window that needs re-sizing
793 void OnSize( WPARAM nType
, int cx
, int cy
)
800 if (nType
== SIZE_MINIMIZED
)
802 if(TaskManagerSettings
.HideWhenMinimized
)
804 ShowWindow(hMainWnd
, SW_HIDE
);
809 nXDifference
= cx
- nOldWidth
;
810 nYDifference
= cy
- nOldHeight
;
814 /* Update the status bar size */
815 GetWindowRect(hStatusWnd
, &rc
);
816 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
818 /* Update the status bar pane sizes */
819 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
820 nParts
[1] = STATUS_SIZE2
;
822 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
824 /* Resize the tab control */
825 GetWindowRect(hTabWnd
, &rc
);
826 cx
= (rc
.right
- rc
.left
) + nXDifference
;
827 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
828 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
830 /* Resize the application page */
831 GetWindowRect(hApplicationPage
, &rc
);
832 cx
= (rc
.right
- rc
.left
) + nXDifference
;
833 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
834 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
836 /* Resize the process page */
837 GetWindowRect(hProcessPage
, &rc
);
838 cx
= (rc
.right
- rc
.left
) + nXDifference
;
839 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
840 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
842 /* Resize the performance page */
843 GetWindowRect(hPerformancePage
, &rc
);
844 cx
= (rc
.right
- rc
.left
) + nXDifference
;
845 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
846 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
849 void LoadSettings(void)
852 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
856 /* Window size & position settings */
857 TaskManagerSettings
.Maximized
= FALSE
;
858 TaskManagerSettings
.Left
= 0;
859 TaskManagerSettings
.Top
= 0;
860 TaskManagerSettings
.Right
= 0;
861 TaskManagerSettings
.Bottom
= 0;
864 TaskManagerSettings
.ActiveTabPage
= 0;
866 /* Options menu settings */
867 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
868 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
869 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
870 TaskManagerSettings
.Show16BitTasks
= TRUE
;
872 /* Update speed settings */
873 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
875 /* Applications page settings */
876 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
878 /* Processes page settings */
879 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
881 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
882 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
883 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
884 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
887 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
888 TaskManagerSettings
.SortAscending
= TRUE
;
890 /* Performance page settings */
891 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
892 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
895 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
897 /* Read the settings */
898 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
899 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
902 * ATM, the 'ImageName' column is always visible
903 * (and grayed in configuration dialog)
904 * This will avoid troubles if the registry gets corrupted.
906 TaskManagerSettings
.Column_ImageName
= TRUE
;
912 void SaveSettings(void)
915 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
917 /* Open (or create) the key */
918 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
920 /* Save the settings */
921 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
926 void TaskManager_OnRestoreMainWindow(void)
928 //HMENU hMenu, hOptionsMenu;
931 //hMenu = GetMenu(hMainWnd);
932 //hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
933 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
936 SetForegroundWindow(hMainWnd
);
937 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
940 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
944 /* Update the status bar pane sizes */
946 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
948 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
951 void TaskManager_OnExitMenuLoop(HWND hWnd
)
956 WCHAR szCpuUsage
[256], szProcesses
[256];
958 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
959 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
962 /* Update the status bar pane sizes */
963 GetClientRect(hWnd
, &rc
);
964 nParts
[0] = STATUS_SIZE1
;
965 nParts
[1] = STATUS_SIZE2
;
966 nParts
[2] = rc
.right
;
967 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
968 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
969 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
970 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
971 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
972 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
975 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
980 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
981 /* load appropriate string */
983 /* first newline terminates actual string */
984 lpsz
= wcschr(lpsz
, '\n');
988 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
991 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
995 HMENU hUpdateSpeedMenu
;
997 hMenu
= GetMenu(hMainWnd
);
998 hViewMenu
= GetSubMenu(hMenu
, 2);
999 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
1001 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
1002 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
1004 KillTimer(hMainWnd
, 1);
1006 SetUpdateSpeed(hMainWnd
);
1009 void TaskManager_OnTabWndSelChange(void)
1017 SYSTEM_INFO sysInfo
;
1019 hMenu
= GetMenu(hMainWnd
);
1020 hViewMenu
= GetSubMenu(hMenu
, 2);
1021 hOptionsMenu
= GetSubMenu(hMenu
, 1);
1022 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
1023 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
1024 hSubMenu
= GetSubMenu(hViewMenu
, i
);
1026 DestroyMenu(hSubMenu
);
1027 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
1029 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
1031 DestroyMenu(hWindowMenu
);
1032 switch (TaskManagerSettings
.ActiveTabPage
) {
1034 ShowWindow(hApplicationPage
, SW_SHOW
);
1035 ShowWindow(hProcessPage
, SW_HIDE
);
1036 ShowWindow(hPerformancePage
, SW_HIDE
);
1037 BringWindowToTop(hApplicationPage
);
1039 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
1040 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
1042 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
1043 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
1045 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
1046 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
1048 if (GetMenuItemCount(hMenu
) <= 5) {
1049 hWindowMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
1051 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
1052 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hWindowMenu
, szTemp
);
1054 DrawMenuBar(hMainWnd
);
1056 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
1059 * Give the application list control focus
1061 if (!bWasKeyboardInput
)
1062 SetFocus(hApplicationPageListCtrl
);
1066 ShowWindow(hApplicationPage
, SW_HIDE
);
1067 ShowWindow(hProcessPage
, SW_SHOW
);
1068 ShowWindow(hPerformancePage
, SW_HIDE
);
1069 BringWindowToTop(hProcessPage
);
1071 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
1072 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
1074 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
1075 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
1077 if (TaskManagerSettings
.Show16BitTasks
)
1078 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
1079 if (GetMenuItemCount(hMenu
) > 5)
1081 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1082 DrawMenuBar(hMainWnd
);
1085 * Give the process list control focus
1087 if (!bWasKeyboardInput
)
1088 SetFocus(hProcessPageListCtrl
);
1092 ShowWindow(hApplicationPage
, SW_HIDE
);
1093 ShowWindow(hProcessPage
, SW_HIDE
);
1094 ShowWindow(hPerformancePage
, SW_SHOW
);
1095 BringWindowToTop(hPerformancePage
);
1096 if (GetMenuItemCount(hMenu
) > 5) {
1097 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1098 DrawMenuBar(hMainWnd
);
1101 GetSystemInfo(&sysInfo
);
1103 /* Hide CPU graph options on single CPU systems */
1104 if (sysInfo
.dwNumberOfProcessors
> 1)
1106 hSubMenu
= CreatePopupMenu();
1108 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
1109 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
1111 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
1112 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
1114 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
1115 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
1117 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
1118 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
1120 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
1123 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
1124 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
1126 if (TaskManagerSettings
.ShowKernelTimes
)
1127 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
1129 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
1132 * Give the tab control focus
1134 if (!bWasKeyboardInput
)
1140 VOID
ShowWin32Error(DWORD dwError
)
1142 LPWSTR lpMessageBuffer
;
1144 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1147 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1148 (LPWSTR
)&lpMessageBuffer
,
1151 MessageBoxW(hMainWnd
, lpMessageBuffer
, NULL
, MB_OK
| MB_ICONERROR
);
1152 if (lpMessageBuffer
) LocalFree(lpMessageBuffer
);
1156 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
1159 LPWSTR lpszTemp
= NULL
;
1161 dwRet
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1169 /* supplied buffer is not long enough */
1170 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1173 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
1174 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1177 LocalFree((HLOCAL
)lpszTemp
);
1182 DWORD
EndLocalThread(HANDLE
*hThread
, DWORD dwThread
)
1184 DWORD dwExitCodeThread
= 0;
1186 if (*hThread
!= NULL
) {
1187 PostThreadMessage(dwThread
,WM_QUIT
,0,0);
1191 if (WAIT_OBJECT_0
== WaitForSingleObject(*hThread
, 500))
1193 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1194 TranslateMessage(&msg
);
1195 DispatchMessage(&msg
);
1198 GetExitCodeThread(*hThread
, &dwExitCodeThread
);
1199 CloseHandle(*hThread
);
1202 return dwExitCodeThread
;