4 * taskmgr.c : Defines the entry point for the application.
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * Copyright (C) 2008 Vladimir Pankratov
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 St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
32 #include "wine/unicode.h"
38 #define STATUS_WINDOW 2001
40 /* Global Variables: */
41 HINSTANCE hInst
; /* current instance */
43 HWND hMainWnd
; /* Main Window */
44 HWND hStatusWnd
; /* Status Bar Window */
45 HWND hTabWnd
; /* Tab Control Window */
47 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
48 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
50 int nOldWidth
; /* Holds the previous client area width */
51 int nOldHeight
; /* Holds the previous client area height */
53 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
55 TASKMANAGER_SETTINGS TaskManagerSettings
;
58 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
61 ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
64 static void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
73 ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
76 static void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
78 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
79 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
80 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
81 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
84 void Font_DrawText(HDC hDC
, LPWSTR lpwszText
, int x
, int y
)
91 hFontDC
= CreateCompatibleDC(hDC
);
92 hFontBitmap
= LoadBitmap(hInst
, MAKEINTRESOURCE(IDB_FONT
));
93 hOldBitmap
= SelectObject(hFontDC
, hFontBitmap
);
95 for (i
= 0; lpwszText
[i
]; i
++) {
96 if ((lpwszText
[i
] >= '0') && (lpwszText
[i
] <= '9')) {
97 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, (lpwszText
[i
] - '0') * 8, 0, SRCCOPY
);
99 else if (lpwszText
[i
] == 'K')
101 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, 80, 0, SRCCOPY
);
103 else if (lpwszText
[i
] == '%')
105 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, 88, 0, SRCCOPY
);
108 SelectObject(hFontDC
, hOldBitmap
);
109 DeleteObject(hFontBitmap
);
113 static BOOL
OnCreate(HWND hWnd
)
118 HMENU hUpdateSpeedMenu
;
119 HMENU hCPUHistoryMenu
;
125 static WCHAR wszApplications
[255];
126 static WCHAR wszProcesses
[255];
127 static WCHAR wszPerformance
[255];
129 LoadStringW(hInst
, IDS_APPLICATIONS
, wszApplications
, sizeof(wszApplications
)/sizeof(WCHAR
));
130 LoadStringW(hInst
, IDS_PROCESSES
, wszProcesses
, sizeof(wszProcesses
)/sizeof(WCHAR
));
131 LoadStringW(hInst
, IDS_PERFORMANCE
, wszPerformance
, sizeof(wszPerformance
)/sizeof(WCHAR
));
133 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIcon(hInst
, MAKEINTRESOURCE(IDI_TASKMANAGER
)));
134 SendMessageW(hMainWnd
, WM_SETICON
, ICON_SMALL
,
135 (LPARAM
)LoadImage(hInst
, MAKEINTRESOURCE(IDI_TASKMANAGER
), IMAGE_ICON
,
136 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
139 /* Initialize the Windows Common Controls DLL */
140 InitCommonControls();
142 /* Get the minimum window sizes */
143 GetWindowRect(hWnd
, &rc
);
144 nMinimumWidth
= (rc
.right
- rc
.left
);
145 nMinimumHeight
= (rc
.bottom
- rc
.top
);
147 /* Create the status bar */
148 hStatusWnd
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, NULL
, hWnd
, STATUS_WINDOW
);
152 /* Create the status bar panes */
156 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
158 /* Create tab pages */
159 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
161 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
162 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
163 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
165 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
166 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
167 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
171 memset(&item
, 0, sizeof(TCITEMW
));
172 item
.mask
= TCIF_TEXT
;
173 item
.pszText
= wszApplications
;
174 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 0, (LPARAM
)&item
);
175 memset(&item
, 0, sizeof(TCITEMW
));
176 item
.mask
= TCIF_TEXT
;
177 item
.pszText
= wszProcesses
;
178 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 1, (LPARAM
)&item
);
179 memset(&item
, 0, sizeof(TCITEMW
));
180 item
.mask
= TCIF_TEXT
;
181 item
.pszText
= wszPerformance
;
182 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 2, (LPARAM
)&item
);
184 /* Size everything correctly */
185 GetClientRect(hWnd
, &rc
);
186 nOldWidth
= rc
.right
;
187 nOldHeight
= rc
.bottom
;
188 /* nOldStartX = rc.left; */
189 /*nOldStartY = rc.top; */
191 #define PAGE_OFFSET_LEFT 17
192 #define PAGE_OFFSET_TOP 72
193 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
194 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
196 if ((TaskManagerSettings
.Left
!= 0) ||
197 (TaskManagerSettings
.Top
!= 0) ||
198 (TaskManagerSettings
.Right
!= 0) ||
199 (TaskManagerSettings
.Bottom
!= 0))
201 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
202 #ifdef __GNUC__TEST__
203 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
);
204 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
);
205 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
);
208 if (TaskManagerSettings
.Maximized
)
209 ShowWindow(hWnd
, SW_MAXIMIZE
);
211 /* Set the always on top style */
212 hMenu
= GetMenu(hWnd
);
213 hEditMenu
= GetSubMenu(hMenu
, 1);
214 hViewMenu
= GetSubMenu(hMenu
, 2);
215 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
216 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
218 /* Check or uncheck the always on top menu item */
219 if (TaskManagerSettings
.AlwaysOnTop
) {
220 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
221 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
223 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
224 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
227 /* Check or uncheck the minimize on use menu item */
228 if (TaskManagerSettings
.MinimizeOnUse
)
229 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
231 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
233 /* Check or uncheck the hide when minimized menu item */
234 if (TaskManagerSettings
.HideWhenMinimized
)
235 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
237 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
239 /* Check or uncheck the show 16-bit tasks menu item */
240 if (TaskManagerSettings
.Show16BitTasks
)
241 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
243 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
245 if (TaskManagerSettings
.View_LargeIcons
)
246 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
247 else if (TaskManagerSettings
.View_SmallIcons
)
248 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
250 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
252 if (TaskManagerSettings
.ShowKernelTimes
)
253 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
255 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
257 if (TaskManagerSettings
.UpdateSpeed
== 1)
258 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
259 else if (TaskManagerSettings
.UpdateSpeed
== 2)
260 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
261 else if (TaskManagerSettings
.UpdateSpeed
== 4)
262 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
264 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
266 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
267 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
269 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
271 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
272 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
273 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
274 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
275 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
277 if (TaskManagerSettings
.UpdateSpeed
== 1)
278 SetTimer(hWnd
, 1, 1000, NULL
);
279 else if (TaskManagerSettings
.UpdateSpeed
== 2)
280 SetTimer(hWnd
, 1, 2000, NULL
);
281 else if (TaskManagerSettings
.UpdateSpeed
== 4)
282 SetTimer(hWnd
, 1, 4000, NULL
);
285 * Refresh the performance data
286 * Sample it twice so we can establish
287 * the delta values & cpu usage
292 RefreshApplicationPage();
293 RefreshProcessPage();
294 RefreshPerformancePage();
296 TrayIcon_ShellAddTrayIcon();
302 * This function handles all the moving events for the application
303 * It moves every child window that needs moving
305 static void OnMove( UINT nType
, int cx
, int cy
)
307 #ifdef __GNUC__TEST__
308 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
);
309 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
);
310 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
);
315 * This function handles all the sizing events for the application
316 * It re-sizes every window, and child window that needs re-sizing
318 static void OnSize( UINT nType
, int cx
, int cy
)
325 if (nType
== SIZE_MINIMIZED
)
327 if(TaskManagerSettings
.HideWhenMinimized
)
329 ShowWindow(hMainWnd
, SW_HIDE
);
334 nXDifference
= cx
- nOldWidth
;
335 nYDifference
= cy
- nOldHeight
;
339 /* Update the status bar size */
340 GetWindowRect(hStatusWnd
, &rc
);
341 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
343 /* Update the status bar pane sizes */
344 nParts
[0] = bInMenuLoop
? -1 : 100;
347 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
)nParts
);
349 /* Resize the tab control */
350 GetWindowRect(hTabWnd
, &rc
);
351 cx
= (rc
.right
- rc
.left
) + nXDifference
;
352 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
353 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
355 /* Resize the application page */
356 GetWindowRect(hApplicationPage
, &rc
);
357 cx
= (rc
.right
- rc
.left
) + nXDifference
;
358 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
359 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
361 /* Resize the process page */
362 GetWindowRect(hProcessPage
, &rc
);
363 cx
= (rc
.right
- rc
.left
) + nXDifference
;
364 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
365 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
367 /* Resize the performance page */
368 GetWindowRect(hPerformancePage
, &rc
);
369 cx
= (rc
.right
- rc
.left
) + nXDifference
;
370 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
371 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
374 static void LoadSettings(void)
380 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
381 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
382 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
384 /* Window size & position settings */
385 TaskManagerSettings
.Maximized
= FALSE
;
386 TaskManagerSettings
.Left
= 0;
387 TaskManagerSettings
.Top
= 0;
388 TaskManagerSettings
.Right
= 0;
389 TaskManagerSettings
.Bottom
= 0;
392 TaskManagerSettings
.ActiveTabPage
= 0;
394 /* Options menu settings */
395 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
396 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
397 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
398 TaskManagerSettings
.Show16BitTasks
= TRUE
;
400 /* Update speed settings */
401 TaskManagerSettings
.UpdateSpeed
= 2;
403 /* Applications page settings */
404 TaskManagerSettings
.View_LargeIcons
= FALSE
;
405 TaskManagerSettings
.View_SmallIcons
= FALSE
;
406 TaskManagerSettings
.View_Details
= TRUE
;
408 /* Processes page settings */
409 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
410 TaskManagerSettings
.Column_ImageName
= TRUE
;
411 TaskManagerSettings
.Column_PID
= TRUE
;
412 TaskManagerSettings
.Column_CPUUsage
= TRUE
;
413 TaskManagerSettings
.Column_CPUTime
= TRUE
;
414 TaskManagerSettings
.Column_MemoryUsage
= TRUE
;
415 TaskManagerSettings
.Column_MemoryUsageDelta
= FALSE
;
416 TaskManagerSettings
.Column_PeakMemoryUsage
= FALSE
;
417 TaskManagerSettings
.Column_PageFaults
= FALSE
;
418 TaskManagerSettings
.Column_USERObjects
= FALSE
;
419 TaskManagerSettings
.Column_IOReads
= FALSE
;
420 TaskManagerSettings
.Column_IOReadBytes
= FALSE
;
421 TaskManagerSettings
.Column_SessionID
= FALSE
; /* Server-only? */
422 TaskManagerSettings
.Column_UserName
= FALSE
; /* Server-only? */
423 TaskManagerSettings
.Column_PageFaultsDelta
= FALSE
;
424 TaskManagerSettings
.Column_VirtualMemorySize
= FALSE
;
425 TaskManagerSettings
.Column_PagedPool
= FALSE
;
426 TaskManagerSettings
.Column_NonPagedPool
= FALSE
;
427 TaskManagerSettings
.Column_BasePriority
= FALSE
;
428 TaskManagerSettings
.Column_HandleCount
= FALSE
;
429 TaskManagerSettings
.Column_ThreadCount
= FALSE
;
430 TaskManagerSettings
.Column_GDIObjects
= FALSE
;
431 TaskManagerSettings
.Column_IOWrites
= FALSE
;
432 TaskManagerSettings
.Column_IOWriteBytes
= FALSE
;
433 TaskManagerSettings
.Column_IOOther
= FALSE
;
434 TaskManagerSettings
.Column_IOOtherBytes
= FALSE
;
436 for (i
= 0; i
< 25; i
++) {
437 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
439 TaskManagerSettings
.ColumnSizeArray
[0] = 105;
440 TaskManagerSettings
.ColumnSizeArray
[1] = 50;
441 TaskManagerSettings
.ColumnSizeArray
[2] = 107;
442 TaskManagerSettings
.ColumnSizeArray
[3] = 70;
443 TaskManagerSettings
.ColumnSizeArray
[4] = 35;
444 TaskManagerSettings
.ColumnSizeArray
[5] = 70;
445 TaskManagerSettings
.ColumnSizeArray
[6] = 70;
446 TaskManagerSettings
.ColumnSizeArray
[7] = 100;
447 TaskManagerSettings
.ColumnSizeArray
[8] = 70;
448 TaskManagerSettings
.ColumnSizeArray
[9] = 70;
449 TaskManagerSettings
.ColumnSizeArray
[10] = 70;
450 TaskManagerSettings
.ColumnSizeArray
[11] = 70;
451 TaskManagerSettings
.ColumnSizeArray
[12] = 70;
452 TaskManagerSettings
.ColumnSizeArray
[13] = 70;
453 TaskManagerSettings
.ColumnSizeArray
[14] = 60;
454 TaskManagerSettings
.ColumnSizeArray
[15] = 60;
455 TaskManagerSettings
.ColumnSizeArray
[16] = 60;
456 TaskManagerSettings
.ColumnSizeArray
[17] = 60;
457 TaskManagerSettings
.ColumnSizeArray
[18] = 60;
458 TaskManagerSettings
.ColumnSizeArray
[19] = 70;
459 TaskManagerSettings
.ColumnSizeArray
[20] = 70;
460 TaskManagerSettings
.ColumnSizeArray
[21] = 70;
461 TaskManagerSettings
.ColumnSizeArray
[22] = 70;
462 TaskManagerSettings
.ColumnSizeArray
[23] = 70;
463 TaskManagerSettings
.ColumnSizeArray
[24] = 70;
465 TaskManagerSettings
.SortColumn
= 1;
466 TaskManagerSettings
.SortAscending
= TRUE
;
468 /* Performance page settings */
469 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
470 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
473 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
474 if (RegOpenKeyExW(HKEY_CURRENT_USER
, wszSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
476 /* Read the settings */
477 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
478 RegQueryValueExW(hKey
, wszPreferences
, NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
484 static void SaveSettings(void)
488 static const WCHAR wszSubKey3
[] = {'S','o','f','t','w','a','r','e','\\',
489 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
490 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
492 /* Open (or create) the key */
494 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
495 if (RegCreateKeyExW(HKEY_CURRENT_USER
, wszSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
497 /* Save the settings */
498 RegSetValueExW(hKey
, wszPreferences
, 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
503 static void TaskManager_OnRestoreMainWindow(void)
505 HMENU hMenu
, hOptionsMenu
;
508 hMenu
= GetMenu(hMainWnd
);
509 hOptionsMenu
= GetSubMenu(hMenu
, OPTIONS_MENU_INDEX
);
510 OnTop
= ((GetWindowLong(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
513 SetForegroundWindow(hMainWnd
);
514 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
517 static void TaskManager_OnEnterMenuLoop(HWND hWnd
)
521 /* Update the status bar pane sizes */
523 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
525 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
528 static void TaskManager_OnExitMenuLoop(HWND hWnd
)
534 WCHAR wszCPU_Usage
[255];
535 WCHAR wszProcesses
[255];
537 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, sizeof(wszCPU_Usage
)/sizeof(WCHAR
));
538 LoadStringW(hInst
, IDS_STATUS_BAR_PROCESSES
, wszProcesses
, sizeof(wszProcesses
)/sizeof(WCHAR
));
541 /* Update the status bar pane sizes */
542 GetClientRect(hWnd
, &rc
);
545 nParts
[2] = rc
.right
;
546 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
547 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, 0);
548 wsprintfW(text
, wszCPU_Usage
, PerfDataGetProcessorUsage());
549 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 1, (LPARAM
)text
);
550 wsprintfW(text
, wszProcesses
, PerfDataGetProcessCount());
551 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)text
);
554 static void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
556 WCHAR wstr
[256] = {0};
558 LoadStringW(hInst
, nItemID
, wstr
, sizeof(wstr
)/sizeof(WCHAR
));
559 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)wstr
);
562 static void TaskManager_OnViewUpdateSpeedHigh(void)
566 HMENU hUpdateSpeedMenu
;
568 hMenu
= GetMenu(hMainWnd
);
569 hViewMenu
= GetSubMenu(hMenu
, 2);
570 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
572 TaskManagerSettings
.UpdateSpeed
= 1;
573 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
575 KillTimer(hMainWnd
, 1);
576 SetTimer(hMainWnd
, 1, 1000, NULL
);
579 static void TaskManager_OnViewUpdateSpeedNormal(void)
583 HMENU hUpdateSpeedMenu
;
585 hMenu
= GetMenu(hMainWnd
);
586 hViewMenu
= GetSubMenu(hMenu
, 2);
587 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
589 TaskManagerSettings
.UpdateSpeed
= 2;
590 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
592 KillTimer(hMainWnd
, 1);
593 SetTimer(hMainWnd
, 1, 2000, NULL
);
596 static void TaskManager_OnViewUpdateSpeedLow(void)
600 HMENU hUpdateSpeedMenu
;
602 hMenu
= GetMenu(hMainWnd
);
603 hViewMenu
= GetSubMenu(hMenu
, 2);
604 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
606 TaskManagerSettings
.UpdateSpeed
= 4;
607 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
609 KillTimer(hMainWnd
, 1);
610 SetTimer(hMainWnd
, 1, 4000, NULL
);
613 static void TaskManager_OnViewUpdateSpeedPaused(void)
617 HMENU hUpdateSpeedMenu
;
619 hMenu
= GetMenu(hMainWnd
);
620 hViewMenu
= GetSubMenu(hMenu
, 2);
621 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
622 TaskManagerSettings
.UpdateSpeed
= 0;
623 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
624 KillTimer(hMainWnd
, 1);
627 static void TaskManager_OnTabWndSelChange(void)
635 WCHAR wszLargeIcons
[255];
636 WCHAR wszSmallIcons
[255];
637 WCHAR wszDetails
[255];
638 WCHAR wszWindows
[255];
639 WCHAR wszSelectColumns
[255];
640 WCHAR wszShow16bTasks
[255];
641 WCHAR wszOneGraphAllCPU
[255];
642 WCHAR wszOneGraphPerCPU
[255];
643 WCHAR wszCPUHistory
[255];
644 WCHAR wszShowKernelTimes
[255];
646 LoadStringW(hInst
, IDS_VIEW_LARGE
, wszLargeIcons
, sizeof(wszLargeIcons
)/sizeof(WCHAR
));
647 LoadStringW(hInst
, IDS_VIEW_SMALL
, wszSmallIcons
, sizeof(wszSmallIcons
)/sizeof(WCHAR
));
648 LoadStringW(hInst
, IDS_VIEW_DETAILS
, wszDetails
, sizeof(wszDetails
)/sizeof(WCHAR
));
649 LoadStringW(hInst
, IDS_WINDOWS
, wszWindows
, sizeof(wszWindows
)/sizeof(WCHAR
));
650 LoadStringW(hInst
, IDS_VIEW_SELECTCOLUMNS
, wszSelectColumns
, sizeof(wszSelectColumns
)/sizeof(WCHAR
));
651 LoadStringW(hInst
, IDS_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
, sizeof(wszShow16bTasks
)/sizeof(WCHAR
));
652 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
, sizeof(wszOneGraphAllCPU
)/sizeof(WCHAR
));
653 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
, sizeof(wszOneGraphPerCPU
)/sizeof(WCHAR
));
654 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY
, wszCPUHistory
, sizeof(wszCPUHistory
)/sizeof(WCHAR
));
655 LoadStringW(hInst
, IDS_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
, sizeof(wszShowKernelTimes
)/sizeof(WCHAR
));
657 hMenu
= GetMenu(hMainWnd
);
658 hViewMenu
= GetSubMenu(hMenu
, 2);
659 hOptionsMenu
= GetSubMenu(hMenu
, 1);
660 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
661 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
662 hSubMenu
= GetSubMenu(hViewMenu
, i
);
664 DestroyMenu(hSubMenu
);
665 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
667 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
668 switch (TaskManagerSettings
.ActiveTabPage
) {
670 ShowWindow(hApplicationPage
, SW_SHOW
);
671 ShowWindow(hProcessPage
, SW_HIDE
);
672 ShowWindow(hPerformancePage
, SW_HIDE
);
673 BringWindowToTop(hApplicationPage
);
674 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, wszLargeIcons
);
675 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, wszSmallIcons
);
676 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, wszDetails
);
678 if (GetMenuItemCount(hMenu
) <= 4) {
679 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
680 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszWindows
);
681 DrawMenuBar(hMainWnd
);
683 if (TaskManagerSettings
.View_LargeIcons
)
684 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
685 else if (TaskManagerSettings
.View_SmallIcons
)
686 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
688 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
690 * Give the application list control focus
692 SetFocus(hApplicationPageListCtrl
);
696 ShowWindow(hApplicationPage
, SW_HIDE
);
697 ShowWindow(hProcessPage
, SW_SHOW
);
698 ShowWindow(hPerformancePage
, SW_HIDE
);
699 BringWindowToTop(hProcessPage
);
700 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, wszSelectColumns
);
701 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
);
702 if (TaskManagerSettings
.Show16BitTasks
)
703 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
704 if (GetMenuItemCount(hMenu
) > 4)
706 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
707 DrawMenuBar(hMainWnd
);
710 * Give the process list control focus
712 SetFocus(hProcessPageListCtrl
);
716 ShowWindow(hApplicationPage
, SW_HIDE
);
717 ShowWindow(hProcessPage
, SW_HIDE
);
718 ShowWindow(hPerformancePage
, SW_SHOW
);
719 BringWindowToTop(hPerformancePage
);
720 if (GetMenuItemCount(hMenu
) > 4) {
721 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
722 DrawMenuBar(hMainWnd
);
724 hSubMenu
= CreatePopupMenu();
725 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
);
726 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
);
727 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszCPUHistory
);
728 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
);
729 if (TaskManagerSettings
.ShowKernelTimes
)
730 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
732 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
733 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
734 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
736 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
738 * Give the tab control focus
745 LPWSTR
GetLastErrorText(LPWSTR lpwszBuf
, DWORD dwSize
)
748 LPWSTR lpwszTemp
= NULL
;
749 static const WCHAR wszFormat
[] = {'%','s',' ','(','%','u',')',0};
751 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
759 /* supplied buffer is not long enough */
760 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
763 lpwszTemp
[strlenW(lpwszTemp
)-2] = '\0'; /* remove cr and newline character */
764 sprintfW(lpwszBuf
, wszFormat
, lpwszTemp
, GetLastError());
767 LocalFree(lpwszTemp
);
772 /* Message handler for dialog box. */
773 static INT_PTR CALLBACK
774 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
787 return OnCreate(hDlg
);
790 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
791 EndDialog(hDlg
, LOWORD(wParam
));
794 /* Process menu commands */
795 switch (LOWORD(wParam
))
798 TaskManager_OnFileNew();
800 case ID_OPTIONS_ALWAYSONTOP
:
801 TaskManager_OnOptionsAlwaysOnTop();
803 case ID_OPTIONS_MINIMIZEONUSE
:
804 TaskManager_OnOptionsMinimizeOnUse();
806 case ID_OPTIONS_HIDEWHENMINIMIZED
:
807 TaskManager_OnOptionsHideWhenMinimized();
809 case ID_OPTIONS_SHOW16BITTASKS
:
810 TaskManager_OnOptionsShow16BitTasks();
813 TaskManager_OnRestoreMainWindow();
816 ApplicationPage_OnViewLargeIcons();
819 ApplicationPage_OnViewSmallIcons();
821 case ID_VIEW_DETAILS
:
822 ApplicationPage_OnViewDetails();
824 case ID_VIEW_SHOWKERNELTIMES
:
825 PerformancePage_OnViewShowKernelTimes();
827 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
828 PerformancePage_OnViewCPUHistoryOneGraphAll();
830 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
831 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
833 case ID_VIEW_UPDATESPEED_HIGH
:
834 TaskManager_OnViewUpdateSpeedHigh();
836 case ID_VIEW_UPDATESPEED_NORMAL
:
837 TaskManager_OnViewUpdateSpeedNormal();
839 case ID_VIEW_UPDATESPEED_LOW
:
840 TaskManager_OnViewUpdateSpeedLow();
842 case ID_VIEW_UPDATESPEED_PAUSED
:
843 TaskManager_OnViewUpdateSpeedPaused();
845 case ID_VIEW_SELECTCOLUMNS
:
846 ProcessPage_OnViewSelectColumns();
848 case ID_VIEW_REFRESH
:
849 PostMessage(hDlg
, WM_TIMER
, 0, 0);
851 case ID_WINDOWS_TILEHORIZONTALLY
:
852 ApplicationPage_OnWindowsTileHorizontally();
854 case ID_WINDOWS_TILEVERTICALLY
:
855 ApplicationPage_OnWindowsTileVertically();
857 case ID_WINDOWS_MINIMIZE
:
858 ApplicationPage_OnWindowsMinimize();
860 case ID_WINDOWS_MAXIMIZE
:
861 ApplicationPage_OnWindowsMaximize();
863 case ID_WINDOWS_CASCADE
:
864 ApplicationPage_OnWindowsCascade();
866 case ID_WINDOWS_BRINGTOFRONT
:
867 ApplicationPage_OnWindowsBringToFront();
869 case ID_APPLICATION_PAGE_SWITCHTO
:
870 ApplicationPage_OnSwitchTo();
872 case ID_APPLICATION_PAGE_ENDTASK
:
873 ApplicationPage_OnEndTask();
875 case ID_APPLICATION_PAGE_GOTOPROCESS
:
876 ApplicationPage_OnGotoProcess();
878 case ID_PROCESS_PAGE_ENDPROCESS
:
879 ProcessPage_OnEndProcess();
881 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
882 ProcessPage_OnEndProcessTree();
884 case ID_PROCESS_PAGE_DEBUG
:
885 ProcessPage_OnDebug();
887 case ID_PROCESS_PAGE_SETAFFINITY
:
888 ProcessPage_OnSetAffinity();
890 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
891 ProcessPage_OnSetPriorityRealTime();
893 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
894 ProcessPage_OnSetPriorityHigh();
896 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
897 ProcessPage_OnSetPriorityAboveNormal();
899 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
900 ProcessPage_OnSetPriorityNormal();
902 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
903 ProcessPage_OnSetPriorityBelowNormal();
905 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
906 ProcessPage_OnSetPriorityLow();
908 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
909 ProcessPage_OnDebugChannels();
915 EndDialog(hDlg
, IDOK
);
927 HMENU hMenu
, hPopupMenu
;
931 OnTop
= ((GetWindowLong(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
933 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
934 hPopupMenu
= GetSubMenu(hMenu
, 0);
936 if(IsWindowVisible(hMainWnd
))
938 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
942 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
947 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
950 SetForegroundWindow(hMainWnd
);
951 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
956 case WM_LBUTTONDBLCLK
:
957 TaskManager_OnRestoreMainWindow();
963 idctrl
= (int)wParam
;
964 pnmh
= (LPNMHDR
)lParam
;
965 if ((pnmh
->hwndFrom
== hTabWnd
) &&
966 (pnmh
->idFrom
== IDC_TAB
) &&
967 (pnmh
->code
== TCN_SELCHANGE
))
969 TaskManager_OnTabWndSelChange();
975 GetClientRect(hDlg
, &rc
);
976 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
977 ReleaseDC(hDlg
, hdc
);
981 hdc
= BeginPaint(hDlg
, &ps
);
982 GetClientRect(hDlg
, &rc
);
983 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
988 /* Make sure the user is sizing the dialog */
989 /* in an acceptable range */
990 pRC
= (LPRECT
)lParam
;
991 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
992 /* If the width is too small enlarge it to the minimum */
993 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
994 pRC
->left
= pRC
->right
- nMinimumWidth
;
996 /* If the width is too small enlarge it to the minimum */
997 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
998 pRC
->right
= pRC
->left
+ nMinimumWidth
;
1000 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
1001 /* If the height is too small enlarge it to the minimum */
1002 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
1003 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
1005 /* If the height is too small enlarge it to the minimum */
1006 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
1007 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
1012 /* Handle the window sizing in it's own function */
1013 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1017 /* Handle the window moving in it's own function */
1018 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1022 ShowWindow(hDlg
, SW_HIDE
);
1023 TrayIcon_ShellRemoveTrayIcon();
1024 wp
.length
= sizeof(WINDOWPLACEMENT
);
1025 GetWindowPlacement(hDlg
, &wp
);
1026 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
1027 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
1028 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
1029 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
1030 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
1031 TaskManagerSettings
.Maximized
= TRUE
;
1033 TaskManagerSettings
.Maximized
= FALSE
;
1034 return DefWindowProc(hDlg
, message
, wParam
, lParam
);
1037 /* Refresh the performance data */
1039 RefreshApplicationPage();
1040 RefreshProcessPage();
1041 RefreshPerformancePage();
1042 TrayIcon_ShellUpdateTrayIcon();
1045 case WM_ENTERMENULOOP
:
1046 TaskManager_OnEnterMenuLoop(hDlg
);
1048 case WM_EXITMENULOOP
:
1049 TaskManager_OnExitMenuLoop(hDlg
);
1052 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1059 int APIENTRY
WinMain(HINSTANCE hInstance
,
1060 HINSTANCE hPrevInstance
,
1066 TOKEN_PRIVILEGES tkp
;
1068 /* Initialize global variables */
1071 /* Change our priority class to HIGH */
1072 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
1073 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
1074 CloseHandle(hProcess
);
1076 /* Now let's get the SE_DEBUG_NAME privilege
1077 * so that we can debug processes
1080 /* Get a token for this process. */
1081 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
1082 /* Get the LUID for the debug privilege. */
1083 LookupPrivilegeValue(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
1085 tkp
.PrivilegeCount
= 1; /* one privilege to set */
1086 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1088 /* Get the debug privilege for this process. */
1089 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, NULL
, 0);
1092 /* Load our settings from the registry */
1095 /* Initialize perf data */
1096 if (!PerfDataInitialize()) {
1100 DialogBoxW(hInst
, (LPWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
1102 /* Save our settings to the registry */
1104 PerfDataUninitialize();