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
)
213 // For now, the Help dialog menu item is disabled because of lacking of HTML Help support
214 EnableMenuItem(GetMenu(hDlg
), ID_HELP_TOPICS
, MF_BYCOMMAND
| MF_GRAYED
);
216 return OnCreate(hDlg
);
219 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
220 EndDialog(hDlg
, LOWORD(wParam
));
223 /* Process menu commands */
224 switch (LOWORD(wParam
))
227 TaskManager_OnFileNew();
229 case ID_OPTIONS_ALWAYSONTOP
:
230 TaskManager_OnOptionsAlwaysOnTop();
232 case ID_OPTIONS_MINIMIZEONUSE
:
233 TaskManager_OnOptionsMinimizeOnUse();
235 case ID_OPTIONS_HIDEWHENMINIMIZED
:
236 TaskManager_OnOptionsHideWhenMinimized();
238 case ID_OPTIONS_SHOW16BITTASKS
:
239 TaskManager_OnOptionsShow16BitTasks();
242 TaskManager_OnRestoreMainWindow();
246 case ID_VIEW_DETAILS
:
247 ApplicationPage_OnView(LOWORD(wParam
));
249 case ID_VIEW_SHOWKERNELTIMES
:
250 PerformancePage_OnViewShowKernelTimes();
252 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
253 PerformancePage_OnViewCPUHistoryOneGraphAll();
255 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
256 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
258 case ID_VIEW_UPDATESPEED_HIGH
:
259 case ID_VIEW_UPDATESPEED_NORMAL
:
260 case ID_VIEW_UPDATESPEED_LOW
:
261 case ID_VIEW_UPDATESPEED_PAUSED
:
262 TaskManager_OnViewUpdateSpeed(LOWORD(wParam
));
264 case ID_VIEW_SELECTCOLUMNS
:
265 ProcessPage_OnViewSelectColumns();
267 case ID_VIEW_REFRESH
:
268 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
270 case ID_WINDOWS_TILEHORIZONTALLY
:
271 ApplicationPage_OnWindowsTile(MDITILE_HORIZONTAL
);
273 case ID_WINDOWS_TILEVERTICALLY
:
274 ApplicationPage_OnWindowsTile(MDITILE_VERTICAL
);
276 case ID_WINDOWS_MINIMIZE
:
277 ApplicationPage_OnWindowsMinimize();
279 case ID_WINDOWS_MAXIMIZE
:
280 ApplicationPage_OnWindowsMaximize();
282 case ID_WINDOWS_CASCADE
:
283 ApplicationPage_OnWindowsCascade();
285 case ID_WINDOWS_BRINGTOFRONT
:
286 ApplicationPage_OnWindowsBringToFront();
288 case ID_APPLICATION_PAGE_SWITCHTO
:
289 ApplicationPage_OnSwitchTo();
291 case ID_APPLICATION_PAGE_ENDTASK
:
292 ApplicationPage_OnEndTask();
294 case ID_APPLICATION_PAGE_GOTOPROCESS
:
295 ApplicationPage_OnGotoProcess();
297 case ID_PROCESS_PAGE_ENDPROCESS
:
298 ProcessPage_OnEndProcess();
300 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
301 ProcessPage_OnEndProcessTree();
303 case ID_PROCESS_PAGE_DEBUG
:
304 ProcessPage_OnDebug();
306 case ID_PROCESS_PAGE_SETAFFINITY
:
307 ProcessPage_OnSetAffinity();
309 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
310 DoSetPriority(REALTIME_PRIORITY_CLASS
);
312 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
313 DoSetPriority(HIGH_PRIORITY_CLASS
);
315 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
316 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS
);
318 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
319 DoSetPriority(NORMAL_PRIORITY_CLASS
);
321 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
322 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS
);
324 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
325 DoSetPriority(IDLE_PRIORITY_CLASS
);
327 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
328 ProcessPage_OnDebugChannels();
332 case ID_SHUTDOWN_STANDBY
:
335 case ID_SHUTDOWN_HIBERNATE
:
336 ShutDown_Hibernate();
338 case ID_SHUTDOWN_POWEROFF
:
341 case ID_SHUTDOWN_REBOOT
:
344 case ID_SHUTDOWN_LOGOFF
:
345 ShutDown_LogOffUser();
347 case ID_SHUTDOWN_SWITCHUSER
:
348 ShutDown_SwitchUser();
350 case ID_SHUTDOWN_LOCKCOMPUTER
:
351 ShutDown_LockComputer();
353 case ID_SHUTDOWN_DISCONNECT
:
354 ShutDown_Disconnect();
356 case ID_SHUTDOWN_EJECT_COMPUTER
:
357 ShutDown_EjectComputer();
364 EndDialog(hDlg
, IDOK
);
376 HMENU hMenu
, hPopupMenu
;
380 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
382 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
383 hPopupMenu
= GetSubMenu(hMenu
, 0);
385 if(IsWindowVisible(hMainWnd
))
387 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
391 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
396 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
399 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_UNCHECKED
);
402 SetForegroundWindow(hMainWnd
);
403 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
408 case WM_LBUTTONDBLCLK
:
409 TaskManager_OnRestoreMainWindow();
415 pnmh
= (LPNMHDR
)lParam
;
416 if ((pnmh
->hwndFrom
== hTabWnd
) &&
417 (pnmh
->idFrom
== IDC_TAB
))
422 TaskManager_OnTabWndSelChange();
425 bWasKeyboardInput
= TRUE
;
428 bWasKeyboardInput
= FALSE
;
436 GetClientRect(hDlg
, &rc
);
437 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
438 ReleaseDC(hDlg
, hdc
);
442 hdc
= BeginPaint(hDlg
, &ps
);
443 GetClientRect(hDlg
, &rc
);
444 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
449 /* Make sure the user is sizing the dialog */
450 /* in an acceptable range */
451 pRC
= (LPRECT
)lParam
;
452 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
453 /* If the width is too small enlarge it to the minimum */
454 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
455 pRC
->left
= pRC
->right
- nMinimumWidth
;
457 /* If the width is too small enlarge it to the minimum */
458 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
459 pRC
->right
= pRC
->left
+ nMinimumWidth
;
461 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
462 /* If the height is too small enlarge it to the minimum */
463 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
464 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
466 /* If the height is too small enlarge it to the minimum */
467 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
468 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
474 /* Handle the window sizing in it's own function */
475 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
479 /* Handle the window moving in it's own function */
480 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
484 ShowWindow(hDlg
, SW_HIDE
);
485 TrayIcon_ShellRemoveTrayIcon();
486 wp
.length
= sizeof(WINDOWPLACEMENT
);
487 GetWindowPlacement(hDlg
, &wp
);
488 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
489 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
490 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
491 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
492 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
493 TaskManagerSettings
.Maximized
= TRUE
;
495 TaskManagerSettings
.Maximized
= FALSE
;
496 /* Get rid of the allocated command line cache, if any */
497 PerfDataDeallocCommandLineCache();
499 DestroyMenu(hWindowMenu
);
500 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
503 /* Refresh the performance data */
505 RefreshApplicationPage();
506 RefreshProcessPage();
507 RefreshPerformancePage();
508 TrayIcon_ShellUpdateTrayIcon();
511 case WM_ENTERMENULOOP
:
512 TaskManager_OnEnterMenuLoop(hDlg
);
514 case WM_EXITMENULOOP
:
515 TaskManager_OnExitMenuLoop(hDlg
);
518 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
520 case WM_SYSCOLORCHANGE
:
521 /* Forward WM_SYSCOLORCHANGE to common controls */
522 SendMessage(hApplicationPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
523 SendMessage(hProcessPageListCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
524 SendMessage(hProcessPageHeaderCtrl
, WM_SYSCOLORCHANGE
, 0, 0);
531 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
533 SetBkColor(hDC
, clr
);
534 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
537 void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
541 SetBkColor(hDC
, clr
);
545 rect
.bottom
= y
+ cy
;
546 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
549 void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
551 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
552 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
553 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
554 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
557 void Draw3dRect2(HDC hDC
, LPRECT lpRect
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
559 Draw3dRect(hDC
, lpRect
->left
, lpRect
->top
, lpRect
->right
- lpRect
->left
,
560 lpRect
->bottom
- lpRect
->top
, clrTopLeft
, clrBottomRight
);
563 static void SetUpdateSpeed(HWND hWnd
)
565 /* Setup update speed (pause=fall down) */
566 switch (TaskManagerSettings
.UpdateSpeed
) {
567 case ID_VIEW_UPDATESPEED_HIGH
:
568 SetTimer(hWnd
, 1, 1000, NULL
);
570 case ID_VIEW_UPDATESPEED_NORMAL
:
571 SetTimer(hWnd
, 1, 2000, NULL
);
573 case ID_VIEW_UPDATESPEED_LOW
:
574 SetTimer(hWnd
, 1, 4000, NULL
);
579 BOOL
OnCreate(HWND hWnd
)
585 HMENU hUpdateSpeedMenu
;
586 HMENU hCPUHistoryMenu
;
591 WCHAR szLogOffItem
[MAX_PATH
];
596 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
598 /* Initialize the Windows Common Controls DLL */
599 InitCommonControls();
601 /* Get the minimum window sizes */
602 GetWindowRect(hWnd
, &rc
);
603 nMinimumWidth
= (rc
.right
- rc
.left
);
604 nMinimumHeight
= (rc
.bottom
- rc
.top
);
606 /* Create the status bar */
607 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
611 /* Create the status bar panes */
612 nParts
[0] = STATUS_SIZE1
;
613 nParts
[1] = STATUS_SIZE2
;
614 nParts
[2] = STATUS_SIZE3
;
615 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
617 /* Create tab pages */
618 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
620 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
621 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
622 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
624 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
625 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
626 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
630 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
631 memset(&item
, 0, sizeof(TCITEM
));
632 item
.mask
= TCIF_TEXT
;
633 item
.pszText
= szTemp
;
634 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
635 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
636 memset(&item
, 0, sizeof(TCITEM
));
637 item
.mask
= TCIF_TEXT
;
638 item
.pszText
= szTemp
;
639 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
640 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
641 memset(&item
, 0, sizeof(TCITEM
));
642 item
.mask
= TCIF_TEXT
;
643 item
.pszText
= szTemp
;
644 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
646 /* Size everything correctly */
647 GetClientRect(hWnd
, &rc
);
648 nOldWidth
= rc
.right
;
649 nOldHeight
= rc
.bottom
;
650 /* nOldStartX = rc.left; */
651 /*nOldStartY = rc.top; */
653 #define PAGE_OFFSET_LEFT 17
654 #define PAGE_OFFSET_TOP 72
655 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
656 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
658 if ((TaskManagerSettings
.Left
!= 0) ||
659 (TaskManagerSettings
.Top
!= 0) ||
660 (TaskManagerSettings
.Right
!= 0) ||
661 (TaskManagerSettings
.Bottom
!= 0))
663 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
664 #ifdef __GNUC__TEST__
665 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
);
666 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
);
667 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
);
670 if (TaskManagerSettings
.Maximized
)
671 ShowWindow(hWnd
, SW_MAXIMIZE
);
673 /* Set the always on top style */
674 hMenu
= GetMenu(hWnd
);
675 hEditMenu
= GetSubMenu(hMenu
, 1);
676 hViewMenu
= GetSubMenu(hMenu
, 2);
677 hShutMenu
= GetSubMenu(hMenu
, 4);
678 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
679 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
681 /* Check or uncheck the always on top menu item */
682 if (TaskManagerSettings
.AlwaysOnTop
) {
683 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
684 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
686 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
687 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
690 /* Check or uncheck the minimize on use menu item */
691 if (TaskManagerSettings
.MinimizeOnUse
)
692 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
694 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
696 /* Check or uncheck the hide when minimized menu item */
697 if (TaskManagerSettings
.HideWhenMinimized
)
698 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
700 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
702 /* Check or uncheck the show 16-bit tasks menu item */
703 if (TaskManagerSettings
.Show16BitTasks
)
704 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
706 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
708 /* Set the view mode */
709 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
711 if (TaskManagerSettings
.ShowKernelTimes
)
712 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
714 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
716 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
718 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
719 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
721 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
723 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
724 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
725 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
726 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
727 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
729 /* Set the username in the "Log Off %s" item of the Shutdown menu */
731 /* 1- Get the menu item text and store it temporarily */
732 GetMenuStringW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, szTemp
, 256, MF_BYCOMMAND
);
734 /* 2- Retrieve the username length first, then allocate a buffer for it and call it again */
735 if (!GetUserNameW(NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
737 lpUserName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
* sizeof(WCHAR
));
738 if (lpUserName
&& GetUserNameW(lpUserName
, &len
))
740 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, lpUserName
);
741 szLogOffItem
[sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]) - 1] = UNICODE_NULL
;
745 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
748 if (lpUserName
) HeapFree(GetProcessHeap(), 0, lpUserName
);
752 _snwprintf(szLogOffItem
, sizeof(szLogOffItem
)/sizeof(szLogOffItem
[0]), szTemp
, L
"n/a");
755 /* 3- Set the menu item text to its formatted counterpart */
756 ModifyMenuW(hShutMenu
, ID_SHUTDOWN_LOGOFF
, MF_BYCOMMAND
| MF_STRING
, ID_SHUTDOWN_LOGOFF
, szLogOffItem
);
758 /* Setup update speed */
759 SetUpdateSpeed(hWnd
);
762 * Refresh the performance data
763 * Sample it twice so we can establish
764 * the delta values & cpu usage
769 RefreshApplicationPage();
770 RefreshProcessPage();
771 RefreshPerformancePage();
773 TrayIcon_ShellAddTrayIcon();
779 * This function handles all the moving events for the application
780 * It moves every child window that needs moving
782 void OnMove( WPARAM nType
, int cx
, int cy
)
784 #ifdef __GNUC__TEST__
785 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
);
786 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
);
787 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
);
792 * This function handles all the sizing events for the application
793 * It re-sizes every window, and child window that needs re-sizing
795 void OnSize( WPARAM nType
, int cx
, int cy
)
802 if (nType
== SIZE_MINIMIZED
)
804 if(TaskManagerSettings
.HideWhenMinimized
)
806 ShowWindow(hMainWnd
, SW_HIDE
);
811 nXDifference
= cx
- nOldWidth
;
812 nYDifference
= cy
- nOldHeight
;
816 /* Update the status bar size */
817 GetWindowRect(hStatusWnd
, &rc
);
818 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
820 /* Update the status bar pane sizes */
821 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
822 nParts
[1] = STATUS_SIZE2
;
824 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
826 /* Resize the tab control */
827 GetWindowRect(hTabWnd
, &rc
);
828 cx
= (rc
.right
- rc
.left
) + nXDifference
;
829 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
830 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
832 /* Resize the application page */
833 GetWindowRect(hApplicationPage
, &rc
);
834 cx
= (rc
.right
- rc
.left
) + nXDifference
;
835 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
836 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
838 /* Resize the process page */
839 GetWindowRect(hProcessPage
, &rc
);
840 cx
= (rc
.right
- rc
.left
) + nXDifference
;
841 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
842 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
844 /* Resize the performance page */
845 GetWindowRect(hPerformancePage
, &rc
);
846 cx
= (rc
.right
- rc
.left
) + nXDifference
;
847 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
848 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
851 void LoadSettings(void)
854 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
858 /* Window size & position settings */
859 TaskManagerSettings
.Maximized
= FALSE
;
860 TaskManagerSettings
.Left
= 0;
861 TaskManagerSettings
.Top
= 0;
862 TaskManagerSettings
.Right
= 0;
863 TaskManagerSettings
.Bottom
= 0;
866 TaskManagerSettings
.ActiveTabPage
= 0;
868 /* Options menu settings */
869 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
870 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
871 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
872 TaskManagerSettings
.Show16BitTasks
= TRUE
;
874 /* Update speed settings */
875 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
877 /* Applications page settings */
878 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
880 /* Processes page settings */
881 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
883 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
884 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
885 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
886 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
889 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
890 TaskManagerSettings
.SortAscending
= TRUE
;
892 /* Performance page settings */
893 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
894 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
897 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
899 /* Read the settings */
900 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
901 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
904 * ATM, the 'ImageName' column is always visible
905 * (and grayed in configuration dialog)
906 * This will avoid troubles if the registry gets corrupted.
908 TaskManagerSettings
.Column_ImageName
= TRUE
;
914 void SaveSettings(void)
917 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
919 /* Open (or create) the key */
920 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
922 /* Save the settings */
923 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
928 void TaskManager_OnRestoreMainWindow(void)
930 //HMENU hMenu, hOptionsMenu;
933 //hMenu = GetMenu(hMainWnd);
934 //hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
935 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
938 SetForegroundWindow(hMainWnd
);
939 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
942 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
946 /* Update the status bar pane sizes */
948 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
950 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
953 void TaskManager_OnExitMenuLoop(HWND hWnd
)
960 /* Update the status bar pane sizes */
961 GetClientRect(hWnd
, &rc
);
962 nParts
[0] = STATUS_SIZE1
;
963 nParts
[1] = STATUS_SIZE2
;
964 nParts
[2] = rc
.right
;
965 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
967 /* trigger update of status bar columns and performance page asynchronously */
968 RefreshPerformancePage();
971 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
976 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
977 /* load appropriate string */
979 /* first newline terminates actual string */
980 lpsz
= wcschr(lpsz
, '\n');
984 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
987 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
991 HMENU hUpdateSpeedMenu
;
993 hMenu
= GetMenu(hMainWnd
);
994 hViewMenu
= GetSubMenu(hMenu
, 2);
995 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
997 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
998 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
1000 KillTimer(hMainWnd
, 1);
1002 SetUpdateSpeed(hMainWnd
);
1005 void TaskManager_OnTabWndSelChange(void)
1013 SYSTEM_INFO sysInfo
;
1015 hMenu
= GetMenu(hMainWnd
);
1016 hViewMenu
= GetSubMenu(hMenu
, 2);
1017 hOptionsMenu
= GetSubMenu(hMenu
, 1);
1018 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
1019 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
1020 hSubMenu
= GetSubMenu(hViewMenu
, i
);
1022 DestroyMenu(hSubMenu
);
1023 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
1025 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
1027 DestroyMenu(hWindowMenu
);
1028 switch (TaskManagerSettings
.ActiveTabPage
) {
1030 ShowWindow(hApplicationPage
, SW_SHOW
);
1031 ShowWindow(hProcessPage
, SW_HIDE
);
1032 ShowWindow(hPerformancePage
, SW_HIDE
);
1033 BringWindowToTop(hApplicationPage
);
1035 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
1036 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
1038 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
1039 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
1041 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
1042 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
1044 if (GetMenuItemCount(hMenu
) <= 5) {
1045 hWindowMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
1047 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
1048 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hWindowMenu
, szTemp
);
1050 DrawMenuBar(hMainWnd
);
1052 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
1055 * Give the application list control focus
1057 if (!bWasKeyboardInput
)
1058 SetFocus(hApplicationPageListCtrl
);
1062 ShowWindow(hApplicationPage
, SW_HIDE
);
1063 ShowWindow(hProcessPage
, SW_SHOW
);
1064 ShowWindow(hPerformancePage
, SW_HIDE
);
1065 BringWindowToTop(hProcessPage
);
1067 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
1068 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
1070 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
1071 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
1073 if (TaskManagerSettings
.Show16BitTasks
)
1074 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
1075 if (GetMenuItemCount(hMenu
) > 5)
1077 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1078 DrawMenuBar(hMainWnd
);
1081 * Give the process list control focus
1083 if (!bWasKeyboardInput
)
1084 SetFocus(hProcessPageListCtrl
);
1088 ShowWindow(hApplicationPage
, SW_HIDE
);
1089 ShowWindow(hProcessPage
, SW_HIDE
);
1090 ShowWindow(hPerformancePage
, SW_SHOW
);
1091 BringWindowToTop(hPerformancePage
);
1092 if (GetMenuItemCount(hMenu
) > 5) {
1093 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1094 DrawMenuBar(hMainWnd
);
1097 GetSystemInfo(&sysInfo
);
1099 /* Hide CPU graph options on single CPU systems */
1100 if (sysInfo
.dwNumberOfProcessors
> 1)
1102 hSubMenu
= CreatePopupMenu();
1104 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
1105 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
1107 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
1108 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
1110 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
1111 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
1113 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
1114 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
1116 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
1119 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
1120 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
1122 if (TaskManagerSettings
.ShowKernelTimes
)
1123 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
1125 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
1128 * Give the tab control focus
1130 if (!bWasKeyboardInput
)
1136 VOID
ShowWin32Error(DWORD dwError
)
1138 LPWSTR lpMessageBuffer
;
1140 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1143 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1144 (LPWSTR
)&lpMessageBuffer
,
1147 MessageBoxW(hMainWnd
, lpMessageBuffer
, NULL
, MB_OK
| MB_ICONERROR
);
1148 if (lpMessageBuffer
) LocalFree(lpMessageBuffer
);
1152 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
1155 LPWSTR lpszTemp
= NULL
;
1157 dwRet
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1165 /* supplied buffer is not long enough */
1166 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1169 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
1170 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1173 LocalFree((HLOCAL
)lpszTemp
);
1178 DWORD
EndLocalThread(HANDLE
*hThread
, DWORD dwThread
)
1180 DWORD dwExitCodeThread
= 0;
1182 if (*hThread
!= NULL
) {
1183 PostThreadMessage(dwThread
,WM_QUIT
,0,0);
1187 if (WAIT_OBJECT_0
== WaitForSingleObject(*hThread
, 500))
1189 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1190 TranslateMessage(&msg
);
1191 DispatchMessage(&msg
);
1194 GetExitCodeThread(*hThread
, &dwExitCodeThread
);
1195 CloseHandle(*hThread
);
1198 return dwExitCodeThread
;