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 */
51 TASKMANAGER_SETTINGS TaskManagerSettings
;
53 ////////////////////////////////////////////////////////////////////////////////
54 // Taken from WinSpy++ 1.7
55 // http://www.catch22.net/software/winspy
56 // Copyright (c) 2002 by J Brown
60 // Copied from uxtheme.h
61 // If you have this new header, then delete these and
62 // #include <uxtheme.h> instead!
64 #define ETDT_DISABLE 0x00000001
65 #define ETDT_ENABLE 0x00000002
66 #define ETDT_USETABTEXTURE 0x00000004
67 #define ETDT_ENABLETAB (ETDT_ENABLE | ETDT_USETABTEXTURE)
70 typedef HRESULT (WINAPI
* ETDTProc
) (HWND
, DWORD
);
73 // Try to call EnableThemeDialogTexture, if uxtheme.dll is present
75 BOOL
EnableDialogTheme(HWND hwnd
)
78 ETDTProc fnEnableThemeDialogTexture
;
80 hUXTheme
= LoadLibraryA("uxtheme.dll");
84 fnEnableThemeDialogTexture
=
85 (ETDTProc
)GetProcAddress(hUXTheme
, "EnableThemeDialogTexture");
87 if(fnEnableThemeDialogTexture
)
89 fnEnableThemeDialogTexture(hwnd
, ETDT_ENABLETAB
);
91 FreeLibrary(hUXTheme
);
96 // Failed to locate API!
97 FreeLibrary(hUXTheme
);
103 // Not running under XP? Just fail gracefully
108 int APIENTRY
wWinMain(HINSTANCE hInstance
,
109 HINSTANCE hPrevInstance
,
115 TOKEN_PRIVILEGES tkp
;
118 /* check wether we're already running or not */
119 hMutex
= CreateMutexW(NULL
, TRUE
, L
"taskmgrros");
120 if (hMutex
&& GetLastError() == ERROR_ALREADY_EXISTS
)
122 /* Restore existing taskmanager and bring window to front */
123 /* Relies on the fact that the application title string and window title are the same */
125 TCHAR szTaskmgr
[128];
127 LoadString(hInst
, IDS_APP_TITLE
, szTaskmgr
, sizeof(szTaskmgr
)/sizeof(TCHAR
));
128 hTaskMgr
= FindWindow(NULL
, szTaskmgr
);
130 if (hTaskMgr
!= NULL
)
132 SendMessage(hTaskMgr
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
133 SetForegroundWindow(hTaskMgr
);
144 /* Initialize global variables */
147 /* Change our priority class to HIGH */
148 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
149 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
150 CloseHandle(hProcess
);
152 /* Now lets get the SE_DEBUG_NAME privilege
153 * so that we can debug processes
156 /* Get a token for this process. */
157 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
))
159 /* Get the LUID for the debug privilege. */
160 if (LookupPrivilegeValueW(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
))
162 tkp
.PrivilegeCount
= 1; /* one privilege to set */
163 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
165 /* Get the debug privilege for this process. */
166 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, (PTOKEN_PRIVILEGES
)NULL
, 0);
171 /* Load our settings from the registry */
174 /* Initialize perf data */
175 if (!PerfDataInitialize())
181 * Set our shutdown parameters: we want to shutdown the very last,
182 * without displaying any end task dialog if needed.
184 SetProcessShutdownParameters(1, SHUTDOWN_NORETRY
);
186 DialogBoxW(hInst
, (LPCWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
188 /* Save our settings to the registry */
190 PerfDataUninitialize();
193 DestroyMenu(hWindowMenu
);
197 /* Message handler for dialog box. */
199 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
213 return OnCreate(hDlg
);
216 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
217 EndDialog(hDlg
, LOWORD(wParam
));
220 /* Process menu commands */
221 switch (LOWORD(wParam
))
224 TaskManager_OnFileNew();
226 case ID_OPTIONS_ALWAYSONTOP
:
227 TaskManager_OnOptionsAlwaysOnTop();
229 case ID_OPTIONS_MINIMIZEONUSE
:
230 TaskManager_OnOptionsMinimizeOnUse();
232 case ID_OPTIONS_HIDEWHENMINIMIZED
:
233 TaskManager_OnOptionsHideWhenMinimized();
235 case ID_OPTIONS_SHOW16BITTASKS
:
236 TaskManager_OnOptionsShow16BitTasks();
239 TaskManager_OnRestoreMainWindow();
243 case ID_VIEW_DETAILS
:
244 ApplicationPage_OnView(LOWORD(wParam
));
246 case ID_VIEW_SHOWKERNELTIMES
:
247 PerformancePage_OnViewShowKernelTimes();
249 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
250 PerformancePage_OnViewCPUHistoryOneGraphAll();
252 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
253 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
255 case ID_VIEW_UPDATESPEED_HIGH
:
256 case ID_VIEW_UPDATESPEED_NORMAL
:
257 case ID_VIEW_UPDATESPEED_LOW
:
258 case ID_VIEW_UPDATESPEED_PAUSED
:
259 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
261 case ID_VIEW_SELECTCOLUMNS
:
262 ProcessPage_OnViewSelectColumns();
264 case ID_VIEW_REFRESH
:
265 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
267 case ID_WINDOWS_TILEHORIZONTALLY
:
268 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
270 case ID_WINDOWS_TILEVERTICALLY
:
271 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
273 case ID_WINDOWS_MINIMIZE
:
274 ApplicationPage_OnWindowsMinimize();
276 case ID_WINDOWS_MAXIMIZE
:
277 ApplicationPage_OnWindowsMaximize();
279 case ID_WINDOWS_CASCADE
:
280 ApplicationPage_OnWindowsCascade();
282 case ID_WINDOWS_BRINGTOFRONT
:
283 ApplicationPage_OnWindowsBringToFront();
285 case ID_APPLICATION_PAGE_SWITCHTO
:
286 ApplicationPage_OnSwitchTo();
288 case ID_APPLICATION_PAGE_ENDTASK
:
289 ApplicationPage_OnEndTask();
291 case ID_APPLICATION_PAGE_GOTOPROCESS
:
292 ApplicationPage_OnGotoProcess();
294 case ID_PROCESS_PAGE_ENDPROCESS
:
295 ProcessPage_OnEndProcess();
297 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
298 ProcessPage_OnEndProcessTree();
300 case ID_PROCESS_PAGE_DEBUG
:
301 ProcessPage_OnDebug();
303 case ID_PROCESS_PAGE_SETAFFINITY
:
304 ProcessPage_OnSetAffinity();
306 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
307 DoSetPriority(REALTIME_PRIORITY_CLASS
);
309 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
310 DoSetPriority(HIGH_PRIORITY_CLASS
);
312 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
313 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
315 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
316 DoSetPriority(NORMAL_PRIORITY_CLASS
);
318 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
319 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
321 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
322 DoSetPriority(IDLE_PRIORITY_CLASS
);
324 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
325 ProcessPage_OnDebugChannels();
329 case ID_SHUTDOWN_STANDBY
:
332 case ID_SHUTDOWN_HIBERNATE
:
333 ShutDown_Hibernate();
335 case ID_SHUTDOWN_POWEROFF
:
338 case ID_SHUTDOWN_REBOOT
:
341 case ID_SHUTDOWN_LOGOFF
:
342 ShutDown_LogOffUser();
344 case ID_SHUTDOWN_SWITCHUSER
:
345 ShutDown_SwitchUser();
347 case ID_SHUTDOWN_LOCKCOMPUTER
:
348 ShutDown_LockComputer();
350 case ID_SHUTDOWN_DISCONNECT
:
351 ShutDown_Disconnect();
353 case ID_SHUTDOWN_EJECT_COMPUTER
:
354 ShutDown_EjectComputer();
361 EndDialog(hDlg
, IDOK
);
373 HMENU hMenu
, hPopupMenu
;
377 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
379 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
380 hPopupMenu
= GetSubMenu(hMenu
, 0);
382 if(IsWindowVisible(hMainWnd
))
384 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
388 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
393 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
396 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
399 SetForegroundWindow(hMainWnd
);
400 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
405 case WM_LBUTTONDBLCLK
:
406 TaskManager_OnRestoreMainWindow();
412 pnmh
= (LPNMHDR
)lParam
;
413 if ((pnmh
->hwndFrom
== hTabWnd
) &&
414 (pnmh
->idFrom
== IDC_TAB
) &&
415 (pnmh
->code
== TCN_SELCHANGE
))
417 TaskManager_OnTabWndSelChange();
423 GetClientRect(hDlg
, &rc
);
424 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
425 ReleaseDC(hDlg
, hdc
);
429 hdc
= BeginPaint(hDlg
, &ps
);
430 GetClientRect(hDlg
, &rc
);
431 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
436 /* Make sure the user is sizing the dialog */
437 /* in an acceptable range */
438 pRC
= (LPRECT
)lParam
;
439 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
440 /* If the width is too small enlarge it to the minimum */
441 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
442 pRC
->left
= pRC
->right
- nMinimumWidth
;
444 /* If the width is too small enlarge it to the minimum */
445 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
446 pRC
->right
= pRC
->left
+ nMinimumWidth
;
448 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
449 /* If the height is too small enlarge it to the minimum */
450 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
451 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
453 /* If the height is too small enlarge it to the minimum */
454 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
455 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
461 /* Handle the window sizing in it's own function */
462 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
466 /* Handle the window moving in it's own function */
467 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
471 ShowWindow(hDlg
, SW_HIDE
);
472 TrayIcon_ShellRemoveTrayIcon();
473 wp
.length
= sizeof(WINDOWPLACEMENT
);
474 GetWindowPlacement(hDlg
, &wp
);
475 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
476 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
477 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
478 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
479 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
480 TaskManagerSettings
.Maximized
= TRUE
;
482 TaskManagerSettings
.Maximized
= FALSE
;
483 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
486 /* Refresh the performance data */
488 RefreshApplicationPage();
489 RefreshProcessPage();
490 RefreshPerformancePage();
491 TrayIcon_ShellUpdateTrayIcon();
494 case WM_ENTERMENULOOP
:
495 TaskManager_OnEnterMenuLoop(hDlg
);
497 case WM_EXITMENULOOP
:
498 TaskManager_OnExitMenuLoop(hDlg
);
501 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
503 case WM_SYSCOLORCHANGE
:
504 /* Forward WM_SYSCOLORCHANGE to common controls */
505 SendMessage(hApplicationPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
506 SendMessage(hProcessPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
507 SendMessage(hProcessPageHeaderCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
514 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
516 SetBkColor(hDC
, clr
);
517 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
520 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
524 SetBkColor(hDC
, clr
);
528 rect
.bottom
= y
+ cy
;
529 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
532 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
534 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
535 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
536 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
537 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
540 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
542 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
543 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
546 static void SetUpdateSpeed(HWND hWnd
)
548 /* Setup update speed (pause=fall down) */
549 switch (TaskManagerSettings
.UpdateSpeed
) {
550 case ID_VIEW_UPDATESPEED_HIGH
:
551 SetTimer(hWnd
, 1, 1000, NULL
);
553 case ID_VIEW_UPDATESPEED_NORMAL
:
554 SetTimer(hWnd
, 1, 2000, NULL
);
556 case ID_VIEW_UPDATESPEED_LOW
:
557 SetTimer(hWnd
, 1, 4000, NULL
);
562 BOOL
OnCreate(HWND hWnd
)
568 HMENU hUpdateSpeedMenu
;
569 HMENU hCPUHistoryMenu
;
574 WCHAR szLogOffItem
[MAX_PATH
];
579 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
581 /* Initialize the Windows Common Controls DLL */
582 InitCommonControls();
584 /* Get the minimum window sizes */
585 GetWindowRect(hWnd
, &rc
);
586 nMinimumWidth
= (rc
.right
- rc
.left
);
587 nMinimumHeight
= (rc
.bottom
- rc
.top
);
589 /* Create the status bar */
590 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
594 /* Create the status bar panes */
595 nParts
[0] = STATUS_SIZE1
;
596 nParts
[1] = STATUS_SIZE2
;
597 nParts
[2] = STATUS_SIZE3
;
598 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
600 /* Create tab pages */
601 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
603 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
604 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
605 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
607 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
608 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
609 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
613 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
614 memset(&item
, 0, sizeof(TCITEM
));
615 item
.mask
= TCIF_TEXT
;
616 item
.pszText
= szTemp
;
617 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
618 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
619 memset(&item
, 0, sizeof(TCITEM
));
620 item
.mask
= TCIF_TEXT
;
621 item
.pszText
= szTemp
;
622 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
623 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
624 memset(&item
, 0, sizeof(TCITEM
));
625 item
.mask
= TCIF_TEXT
;
626 item
.pszText
= szTemp
;
627 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
629 /* Size everything correctly */
630 GetClientRect(hWnd
, &rc
);
631 nOldWidth
= rc
.right
;
632 nOldHeight
= rc
.bottom
;
633 /* nOldStartX = rc.left; */
634 /*nOldStartY = rc.top; */
636 #define PAGE_OFFSET_LEFT 17
637 #define PAGE_OFFSET_TOP 72
638 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
639 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
641 if ((TaskManagerSettings
.Left
!= 0) ||
642 (TaskManagerSettings
.Top
!= 0) ||
643 (TaskManagerSettings
.Right
!= 0) ||
644 (TaskManagerSettings
.Bottom
!= 0))
646 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
647 #ifdef __GNUC__TEST__
648 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
);
649 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
);
650 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
);
653 if (TaskManagerSettings
.Maximized
)
654 ShowWindow(hWnd
, SW_MAXIMIZE
);
656 /* Set the always on top style */
657 hMenu
= GetMenu(hWnd
);
658 hEditMenu
= GetSubMenu(hMenu
, 1);
659 hViewMenu
= GetSubMenu(hMenu
, 2);
660 hShutMenu
= GetSubMenu(hMenu
, 4);
661 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
662 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
664 /* Check or uncheck the always on top menu item */
665 if (TaskManagerSettings
.AlwaysOnTop
) {
666 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
667 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
669 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
670 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
673 /* Check or uncheck the minimize on use menu item */
674 if (TaskManagerSettings
.MinimizeOnUse
)
675 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
677 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
679 /* Check or uncheck the hide when minimized menu item */
680 if (TaskManagerSettings
.HideWhenMinimized
)
681 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
683 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
685 /* Check or uncheck the show 16-bit tasks menu item */
686 if (TaskManagerSettings
.Show16BitTasks
)
687 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
689 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
691 /* Set the view mode */
692 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
694 if (TaskManagerSettings
.ShowKernelTimes
)
695 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
697 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
699 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
701 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
702 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
704 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
706 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
707 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
708 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
709 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
710 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
712 /* Set the username in the "Log Off %s" item of the Shutdown menu */
714 /* 1- Get the menu item text and store it temporarily */
715 GetMenuStringW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, szTemp
, 256, MF_BYCOMMAND
);
717 /* 2- Retrieve the username length first, then allocate a buffer for it and call it again */
718 if (!GetUserNameW(NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
720 lpUserName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
* sizeof(WCHAR
));
721 if (lpUserName
&& GetUserNameW(lpUserName
, &len
))
723 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, lpUserName
);
724 szLogOffItem
[sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]) - 1] = UNICODE_NULL
;
728 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
731 if (lpUserName
) HeapFree(GetProcessHeap(), 0, lpUserName
);
735 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
738 /* 3- Set the menu item text to its formatted counterpart */
739 ModifyMenuW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, MF_BYCOMMAND
| MF_STRING
, ID_SHUTDOWN_LOGOFF
, szLogOffItem
);
741 /* Setup update speed */
742 SetUpdateSpeed(hWnd
);
745 * Refresh the performance data
746 * Sample it twice so we can establish
747 * the delta values & cpu usage
752 RefreshApplicationPage();
753 RefreshProcessPage();
754 RefreshPerformancePage();
756 TrayIcon_ShellAddTrayIcon();
762 * This function handles all the moving events for the application
763 * It moves every child window that needs moving
765 void OnMove( WPARAM nType
, int cx
, int cy
)
767 #ifdef __GNUC__TEST__
768 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
);
769 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
);
770 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
);
775 * This function handles all the sizing events for the application
776 * It re-sizes every window, and child window that needs re-sizing
778 void OnSize( WPARAM nType
, int cx
, int cy
)
785 if (nType
== SIZE_MINIMIZED
)
787 if(TaskManagerSettings
.HideWhenMinimized
)
789 ShowWindow(hMainWnd
, SW_HIDE
);
794 nXDifference
= cx
- nOldWidth
;
795 nYDifference
= cy
- nOldHeight
;
799 /* Update the status bar size */
800 GetWindowRect(hStatusWnd
, &rc
);
801 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
803 /* Update the status bar pane sizes */
804 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
805 nParts
[1] = STATUS_SIZE2
;
807 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
809 /* Resize the tab control */
810 GetWindowRect(hTabWnd
, &rc
);
811 cx
= (rc
.right
- rc
.left
) + nXDifference
;
812 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
813 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
815 /* Resize the application page */
816 GetWindowRect(hApplicationPage
, &rc
);
817 cx
= (rc
.right
- rc
.left
) + nXDifference
;
818 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
819 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
821 /* Resize the process page */
822 GetWindowRect(hProcessPage
, &rc
);
823 cx
= (rc
.right
- rc
.left
) + nXDifference
;
824 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
825 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
827 /* Resize the performance page */
828 GetWindowRect(hPerformancePage
, &rc
);
829 cx
= (rc
.right
- rc
.left
) + nXDifference
;
830 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
831 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
834 void LoadSettings(void)
837 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
841 /* Window size & position settings */
842 TaskManagerSettings
.Maximized
= FALSE
;
843 TaskManagerSettings
.Left
= 0;
844 TaskManagerSettings
.Top
= 0;
845 TaskManagerSettings
.Right
= 0;
846 TaskManagerSettings
.Bottom
= 0;
849 TaskManagerSettings
.ActiveTabPage
= 0;
851 /* Options menu settings */
852 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
853 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
854 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
855 TaskManagerSettings
.Show16BitTasks
= TRUE
;
857 /* Update speed settings */
858 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
860 /* Applications page settings */
861 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
863 /* Processes page settings */
864 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
866 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
867 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
868 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
869 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
872 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
873 TaskManagerSettings
.SortAscending
= TRUE
;
875 /* Performance page settings */
876 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
877 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
880 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
882 /* Read the settings */
883 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
884 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
887 * ATM, the 'ImageName' column is always visible
888 * (and grayed in configuration dialog)
889 * This will avoid troubles if the registry gets corrupted.
891 TaskManagerSettings
.Column_ImageName
= TRUE
;
897 void SaveSettings(void)
900 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
902 /* Open (or create) the key */
903 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
905 /* Save the settings */
906 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
911 void TaskManager_OnRestoreMainWindow(void)
913 //HMENU hMenu, hOptionsMenu;
916 //hMenu = GetMenu(hMainWnd);
917 //hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
918 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
921 SetForegroundWindow(hMainWnd
);
922 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
925 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
929 /* Update the status bar pane sizes */
931 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
933 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
936 void TaskManager_OnExitMenuLoop(HWND hWnd
)
941 WCHAR szCpuUsage
[256], szProcesses
[256];
943 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
944 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
947 /* Update the status bar pane sizes */
948 GetClientRect(hWnd
, &rc
);
949 nParts
[0] = STATUS_SIZE1
;
950 nParts
[1] = STATUS_SIZE2
;
951 nParts
[2] = rc
.right
;
952 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
953 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
954 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
955 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
956 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
957 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
960 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
965 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
966 /* load appropriate string */
968 /* first newline terminates actual string */
969 lpsz
= wcschr(lpsz
, '\n');
973 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
976 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
980 HMENU hUpdateSpeedMenu
;
982 hMenu
= GetMenu(hMainWnd
);
983 hViewMenu
= GetSubMenu(hMenu
, 2);
984 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
986 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
987 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
989 KillTimer(hMainWnd
, 1);
991 SetUpdateSpeed(hMainWnd
);
994 void TaskManager_OnTabWndSelChange(void)
1002 SYSTEM_INFO sysInfo
;
1004 hMenu
= GetMenu(hMainWnd
);
1005 hViewMenu
= GetSubMenu(hMenu
, 2);
1006 hOptionsMenu
= GetSubMenu(hMenu
, 1);
1007 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
1008 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
1009 hSubMenu
= GetSubMenu(hViewMenu
, i
);
1011 DestroyMenu(hSubMenu
);
1012 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
1014 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
1016 DestroyMenu(hWindowMenu
);
1017 switch (TaskManagerSettings
.ActiveTabPage
) {
1019 ShowWindow(hApplicationPage
, SW_SHOW
);
1020 ShowWindow(hProcessPage
, SW_HIDE
);
1021 ShowWindow(hPerformancePage
, SW_HIDE
);
1022 BringWindowToTop(hApplicationPage
);
1024 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
1025 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
1027 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
1028 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
1030 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
1031 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
1033 if (GetMenuItemCount(hMenu
) <= 5) {
1034 hWindowMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
1036 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
1037 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hWindowMenu
, szTemp
);
1039 DrawMenuBar(hMainWnd
);
1041 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
1044 * Give the application list control focus
1046 SetFocus(hApplicationPageListCtrl
);
1050 ShowWindow(hApplicationPage
, SW_HIDE
);
1051 ShowWindow(hProcessPage
, SW_SHOW
);
1052 ShowWindow(hPerformancePage
, SW_HIDE
);
1053 BringWindowToTop(hProcessPage
);
1055 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
1056 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
1058 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
1059 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
1061 if (TaskManagerSettings
.Show16BitTasks
)
1062 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
1063 if (GetMenuItemCount(hMenu
) > 5)
1065 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1066 DrawMenuBar(hMainWnd
);
1069 * Give the process list control focus
1071 SetFocus(hProcessPageListCtrl
);
1075 ShowWindow(hApplicationPage
, SW_HIDE
);
1076 ShowWindow(hProcessPage
, SW_HIDE
);
1077 ShowWindow(hPerformancePage
, SW_SHOW
);
1078 BringWindowToTop(hPerformancePage
);
1079 if (GetMenuItemCount(hMenu
) > 5) {
1080 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1081 DrawMenuBar(hMainWnd
);
1084 GetSystemInfo(&sysInfo
);
1086 /* Hide CPU graph options on single CPU systems */
1087 if (sysInfo
.dwNumberOfProcessors
> 1)
1089 hSubMenu
= CreatePopupMenu();
1091 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
1092 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
1094 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
1095 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
1097 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
1098 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
1100 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
1101 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
1103 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
1106 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
1107 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
1109 if (TaskManagerSettings
.ShowKernelTimes
)
1110 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
1112 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
1115 * Give the tab control focus
1122 VOID
ShowWin32Error(DWORD dwError
)
1124 LPWSTR lpMessageBuffer
;
1126 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1129 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1130 (LPWSTR
)&lpMessageBuffer
,
1133 MessageBoxW(hMainWnd
, lpMessageBuffer
, NULL
, MB_OK
| MB_ICONERROR
);
1134 if (lpMessageBuffer
) LocalFree(lpMessageBuffer
);
1138 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
1141 LPWSTR lpszTemp
= NULL
;
1143 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1151 /* supplied buffer is not long enough */
1152 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1155 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
1156 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1159 LocalFree((HLOCAL
)lpszTemp
);
1164 DWORD
EndLocalThread(HANDLE
*hThread
, DWORD dwThread
)
1166 DWORD dwExitCodeThread
= 0;
1168 if (*hThread
!= NULL
) {
1169 PostThreadMessage(dwThread
,WM_QUIT
,0,0);
1173 if (WAIT_OBJECT_0
== WaitForSingleObject(*hThread
, 500))
1175 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1176 TranslateMessage(&msg
);
1177 DispatchMessage(&msg
);
1180 GetExitCodeThread(*hThread
, &dwExitCodeThread
);
1181 CloseHandle(*hThread
);
1184 return dwExitCodeThread
;