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
)
567 HMENU hUpdateSpeedMenu
;
568 HMENU hCPUHistoryMenu
;
575 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
577 /* Initialize the Windows Common Controls DLL */
578 InitCommonControls();
580 /* Get the minimum window sizes */
581 GetWindowRect(hWnd
, &rc
);
582 nMinimumWidth
= (rc
.right
- rc
.left
);
583 nMinimumHeight
= (rc
.bottom
- rc
.top
);
585 /* Create the status bar */
586 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, L
"", hWnd
, STATUS_WINDOW
);
590 /* Create the status bar panes */
591 nParts
[0] = STATUS_SIZE1
;
592 nParts
[1] = STATUS_SIZE2
;
593 nParts
[2] = STATUS_SIZE3
;
594 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
596 /* Create tab pages */
597 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
599 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
600 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
601 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
603 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
); EnableDialogTheme(hApplicationPage
);
604 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
); EnableDialogTheme(hProcessPage
);
605 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
); EnableDialogTheme(hPerformancePage
);
609 LoadStringW(hInst
, IDS_TAB_APPS
, szTemp
, 256);
610 memset(&item
, 0, sizeof(TCITEM
));
611 item
.mask
= TCIF_TEXT
;
612 item
.pszText
= szTemp
;
613 (void)TabCtrl_InsertItem(hTabWnd
, 0, &item
);
614 LoadStringW(hInst
, IDS_TAB_PROCESSES
, szTemp
, 256);
615 memset(&item
, 0, sizeof(TCITEM
));
616 item
.mask
= TCIF_TEXT
;
617 item
.pszText
= szTemp
;
618 (void)TabCtrl_InsertItem(hTabWnd
, 1, &item
);
619 LoadStringW(hInst
, IDS_TAB_PERFORMANCE
, szTemp
, 256);
620 memset(&item
, 0, sizeof(TCITEM
));
621 item
.mask
= TCIF_TEXT
;
622 item
.pszText
= szTemp
;
623 (void)TabCtrl_InsertItem(hTabWnd
, 2, &item
);
625 /* Size everything correctly */
626 GetClientRect(hWnd
, &rc
);
627 nOldWidth
= rc
.right
;
628 nOldHeight
= rc
.bottom
;
629 /* nOldStartX = rc.left; */
630 /*nOldStartY = rc.top; */
632 #define PAGE_OFFSET_LEFT 17
633 #define PAGE_OFFSET_TOP 72
634 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
635 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
637 if ((TaskManagerSettings
.Left
!= 0) ||
638 (TaskManagerSettings
.Top
!= 0) ||
639 (TaskManagerSettings
.Right
!= 0) ||
640 (TaskManagerSettings
.Bottom
!= 0))
642 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
643 #ifdef __GNUC__TEST__
644 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
);
645 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
);
646 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
);
649 if (TaskManagerSettings
.Maximized
)
650 ShowWindow(hWnd
, SW_MAXIMIZE
);
652 /* Set the always on top style */
653 hMenu
= GetMenu(hWnd
);
654 hEditMenu
= GetSubMenu(hMenu
, 1);
655 hViewMenu
= GetSubMenu(hMenu
, 2);
656 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
657 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
659 /* Check or uncheck the always on top menu item */
660 if (TaskManagerSettings
.AlwaysOnTop
) {
661 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
662 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
664 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
665 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
668 /* Check or uncheck the minimize on use menu item */
669 if (TaskManagerSettings
.MinimizeOnUse
)
670 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
672 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
674 /* Check or uncheck the hide when minimized menu item */
675 if (TaskManagerSettings
.HideWhenMinimized
)
676 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
678 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
680 /* Check or uncheck the show 16-bit tasks menu item */
681 if (TaskManagerSettings
.Show16BitTasks
)
682 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
684 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
686 /* Set the view mode */
687 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
689 if (TaskManagerSettings
.ShowKernelTimes
)
690 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
692 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
694 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, TaskManagerSettings
.UpdateSpeed
, MF_BYCOMMAND
);
696 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
697 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
699 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
701 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
702 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
703 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
704 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
705 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
707 /* Setup update speed */
708 SetUpdateSpeed(hWnd
);
711 * Refresh the performance data
712 * Sample it twice so we can establish
713 * the delta values & cpu usage
718 RefreshApplicationPage();
719 RefreshProcessPage();
720 RefreshPerformancePage();
722 TrayIcon_ShellAddTrayIcon();
728 * This function handles all the moving events for the application
729 * It moves every child window that needs moving
731 void OnMove( WPARAM nType
, int cx
, int cy
)
733 #ifdef __GNUC__TEST__
734 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
);
735 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
);
736 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
);
741 * This function handles all the sizing events for the application
742 * It re-sizes every window, and child window that needs re-sizing
744 void OnSize( WPARAM nType
, int cx
, int cy
)
751 if (nType
== SIZE_MINIMIZED
)
753 if(TaskManagerSettings
.HideWhenMinimized
)
755 ShowWindow(hMainWnd
, SW_HIDE
);
760 nXDifference
= cx
- nOldWidth
;
761 nYDifference
= cy
- nOldHeight
;
765 /* Update the status bar size */
766 GetWindowRect(hStatusWnd
, &rc
);
767 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
,rc
.bottom
- rc
.top
));
769 /* Update the status bar pane sizes */
770 nParts
[0] = bInMenuLoop
? -1 : STATUS_SIZE1
;
771 nParts
[1] = STATUS_SIZE2
;
773 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
) (LPINT
) nParts
);
775 /* Resize the tab control */
776 GetWindowRect(hTabWnd
, &rc
);
777 cx
= (rc
.right
- rc
.left
) + nXDifference
;
778 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
779 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
781 /* Resize the application page */
782 GetWindowRect(hApplicationPage
, &rc
);
783 cx
= (rc
.right
- rc
.left
) + nXDifference
;
784 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
785 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
787 /* Resize the process page */
788 GetWindowRect(hProcessPage
, &rc
);
789 cx
= (rc
.right
- rc
.left
) + nXDifference
;
790 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
791 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
793 /* Resize the performance page */
794 GetWindowRect(hPerformancePage
, &rc
);
795 cx
= (rc
.right
- rc
.left
) + nXDifference
;
796 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
797 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
800 void LoadSettings(void)
803 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
807 /* Window size & position settings */
808 TaskManagerSettings
.Maximized
= FALSE
;
809 TaskManagerSettings
.Left
= 0;
810 TaskManagerSettings
.Top
= 0;
811 TaskManagerSettings
.Right
= 0;
812 TaskManagerSettings
.Bottom
= 0;
815 TaskManagerSettings
.ActiveTabPage
= 0;
817 /* Options menu settings */
818 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
819 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
820 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
821 TaskManagerSettings
.Show16BitTasks
= TRUE
;
823 /* Update speed settings */
824 TaskManagerSettings
.UpdateSpeed
= ID_VIEW_UPDATESPEED_NORMAL
;
826 /* Applications page settings */
827 TaskManagerSettings
.ViewMode
= ID_VIEW_DETAILS
;
829 /* Processes page settings */
830 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
832 for (i
= 0; i
< COLUMN_NMAX
; i
++) {
833 TaskManagerSettings
.Columns
[i
] = ColumnPresets
[i
].bDefaults
;
834 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
835 TaskManagerSettings
.ColumnSizeArray
[i
] = ColumnPresets
[i
].size
;
838 TaskManagerSettings
.SortColumn
= COLUMN_IMAGENAME
;
839 TaskManagerSettings
.SortAscending
= TRUE
;
841 /* Performance page settings */
842 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
843 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
846 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
848 /* Read the settings */
849 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
850 RegQueryValueExW(hKey
, L
"Preferences", NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
853 * ATM, the 'ImageName' column is always visible
854 * (and grayed in configuration dialog)
855 * This will avoid troubles if the registry gets corrupted.
857 TaskManagerSettings
.Column_ImageName
= TRUE
;
863 void SaveSettings(void)
866 WCHAR szSubKey
[] = L
"Software\\ReactOS\\TaskManager";
868 /* Open (or create) the key */
869 if (RegCreateKeyExW(HKEY_CURRENT_USER
, szSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
871 /* Save the settings */
872 RegSetValueExW(hKey
, L
"Preferences", 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
877 void TaskManager_OnRestoreMainWindow(void)
879 //HMENU hMenu, hOptionsMenu;
882 //hMenu = GetMenu(hMainWnd);
883 //hOptionsMenu = GetSubMenu(hMenu, OPTIONS_MENU_INDEX);
884 OnTop
= ((GetWindowLongPtrW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
887 SetForegroundWindow(hMainWnd
);
888 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
891 void TaskManager_OnEnterMenuLoop(HWND hWnd
)
895 /* Update the status bar pane sizes */
897 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
) (LPINT
)&nParts
);
899 SendMessageW(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)L
"");
902 void TaskManager_OnExitMenuLoop(HWND hWnd
)
907 WCHAR szCpuUsage
[256], szProcesses
[256];
909 LoadStringW(hInst
, IDS_STATUS_CPUUSAGE
, szCpuUsage
, 256);
910 LoadStringW(hInst
, IDS_STATUS_PROCESSES
, szProcesses
, 256);
913 /* Update the status bar pane sizes */
914 GetClientRect(hWnd
, &rc
);
915 nParts
[0] = STATUS_SIZE1
;
916 nParts
[1] = STATUS_SIZE2
;
917 nParts
[2] = rc
.right
;
918 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
) (LPINT
) nParts
);
919 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)L
"");
920 wsprintfW(text
, szCpuUsage
, PerfDataGetProcessorUsage());
921 SendMessageW(hStatusWnd
, SB_SETTEXT
, 1, (LPARAM
)text
);
922 wsprintfW(text
, szProcesses
, PerfDataGetProcessCount());
923 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)text
);
926 void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
931 if (LoadStringW(hInst
, nItemID
, str
, 100)) {
932 /* load appropriate string */
934 /* first newline terminates actual string */
935 lpsz
= wcschr(lpsz
, '\n');
939 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
942 void TaskManager_OnViewUpdateSpeed(DWORD dwSpeed
)
946 HMENU hUpdateSpeedMenu
;
948 hMenu
= GetMenu(hMainWnd
);
949 hViewMenu
= GetSubMenu(hMenu
, 2);
950 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
952 TaskManagerSettings
.UpdateSpeed
= dwSpeed
;
953 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, dwSpeed
, MF_BYCOMMAND
);
955 KillTimer(hMainWnd
, 1);
957 SetUpdateSpeed(hMainWnd
);
960 void TaskManager_OnTabWndSelChange(void)
970 hMenu
= GetMenu(hMainWnd
);
971 hViewMenu
= GetSubMenu(hMenu
, 2);
972 hOptionsMenu
= GetSubMenu(hMenu
, 1);
973 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
974 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
975 hSubMenu
= GetSubMenu(hViewMenu
, i
);
977 DestroyMenu(hSubMenu
);
978 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
980 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
982 DestroyMenu(hWindowMenu
);
983 switch (TaskManagerSettings
.ActiveTabPage
) {
985 ShowWindow(hApplicationPage
, SW_SHOW
);
986 ShowWindow(hProcessPage
, SW_HIDE
);
987 ShowWindow(hPerformancePage
, SW_HIDE
);
988 BringWindowToTop(hApplicationPage
);
990 LoadStringW(hInst
, IDS_MENU_LARGEICONS
, szTemp
, 256);
991 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, szTemp
);
993 LoadStringW(hInst
, IDS_MENU_SMALLICONS
, szTemp
, 256);
994 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, szTemp
);
996 LoadStringW(hInst
, IDS_MENU_DETAILS
, szTemp
, 256);
997 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, szTemp
);
999 if (GetMenuItemCount(hMenu
) <= 5) {
1000 hWindowMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
1002 LoadStringW(hInst
, IDS_MENU_WINDOWS
, szTemp
, 256);
1003 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
) hWindowMenu
, szTemp
);
1005 DrawMenuBar(hMainWnd
);
1007 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, TaskManagerSettings
.ViewMode
, MF_BYCOMMAND
);
1010 * Give the application list control focus
1012 SetFocus(hApplicationPageListCtrl
);
1016 ShowWindow(hApplicationPage
, SW_HIDE
);
1017 ShowWindow(hProcessPage
, SW_SHOW
);
1018 ShowWindow(hPerformancePage
, SW_HIDE
);
1019 BringWindowToTop(hProcessPage
);
1021 LoadStringW(hInst
, IDS_MENU_SELECTCOLUMNS
, szTemp
, 256);
1022 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, szTemp
);
1024 LoadStringW(hInst
, IDS_MENU_16BITTASK
, szTemp
, 256);
1025 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, szTemp
);
1027 if (TaskManagerSettings
.Show16BitTasks
)
1028 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
1029 if (GetMenuItemCount(hMenu
) > 5)
1031 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1032 DrawMenuBar(hMainWnd
);
1035 * Give the process list control focus
1037 SetFocus(hProcessPageListCtrl
);
1041 ShowWindow(hApplicationPage
, SW_HIDE
);
1042 ShowWindow(hProcessPage
, SW_HIDE
);
1043 ShowWindow(hPerformancePage
, SW_SHOW
);
1044 BringWindowToTop(hPerformancePage
);
1045 if (GetMenuItemCount(hMenu
) > 5) {
1046 DeleteMenu(hMenu
, 3, MF_BYPOSITION
);
1047 DrawMenuBar(hMainWnd
);
1050 GetSystemInfo(&sysInfo
);
1052 /* Hide CPU graph options on single CPU systems */
1053 if (sysInfo
.dwNumberOfProcessors
> 1)
1055 hSubMenu
= CreatePopupMenu();
1057 LoadStringW(hInst
, IDS_MENU_ONEGRAPHALLCPUS
, szTemp
, 256);
1058 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, szTemp
);
1060 LoadStringW(hInst
, IDS_MENU_ONEGRAPHPERCPU
, szTemp
, 256);
1061 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, szTemp
);
1063 LoadStringW(hInst
, IDS_MENU_CPUHISTORY
, szTemp
, 256);
1064 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
) hSubMenu
, szTemp
);
1066 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
1067 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
1069 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
1072 LoadStringW(hInst
, IDS_MENU_SHOWKERNELTIMES
, szTemp
, 256);
1073 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, szTemp
);
1075 if (TaskManagerSettings
.ShowKernelTimes
)
1076 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
1078 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
1081 * Give the tab control focus
1088 VOID
ShowWin32Error(DWORD dwError
)
1090 LPWSTR lpMessageBuffer
;
1092 if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1095 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1096 (LPWSTR
)&lpMessageBuffer
,
1099 MessageBoxW(hMainWnd
, lpMessageBuffer
, NULL
, MB_OK
| MB_ICONERROR
);
1100 if (lpMessageBuffer
) LocalFree(lpMessageBuffer
);
1104 LPWSTR
GetLastErrorText(LPWSTR lpszBuf
, DWORD dwSize
)
1107 LPWSTR lpszTemp
= NULL
;
1109 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1117 /* supplied buffer is not long enough */
1118 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
1121 lpszTemp
[lstrlenW(lpszTemp
)-2] = L
'\0'; /*remove cr and newline character */
1122 wsprintfW(lpszBuf
, L
"%s (0x%x)", lpszTemp
, (int)GetLastError());
1125 LocalFree((HLOCAL
)lpszTemp
);
1130 DWORD
EndLocalThread(HANDLE
*hThread
, DWORD dwThread
)
1132 DWORD dwExitCodeThread
= 0;
1134 if (*hThread
!= NULL
) {
1135 PostThreadMessage(dwThread
,WM_QUIT
,0,0);
1139 if (WAIT_OBJECT_0
== WaitForSingleObject(*hThread
, 500))
1141 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1142 TranslateMessage(&msg
);
1143 DispatchMessage(&msg
);
1146 GetExitCodeThread(*hThread
, &dwExitCodeThread
);
1147 CloseHandle(*hThread
);
1150 return dwExitCodeThread
;