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
[] = {'A','p','p','l','i','c','a','t','i','o','n','s',0};
126 static WCHAR wszProcesses
[] = {'P','r','o','c','e','s','s','e','s',0};
127 static WCHAR wszPerformance
[] = {'P','e','r','f','o','r','m','a','n','c','e',0};
129 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIcon(hInst
, MAKEINTRESOURCE(IDI_TASKMANAGER
)));
131 /* Initialize the Windows Common Controls DLL */
132 InitCommonControls();
134 /* Get the minimum window sizes */
135 GetWindowRect(hWnd
, &rc
);
136 nMinimumWidth
= (rc
.right
- rc
.left
);
137 nMinimumHeight
= (rc
.bottom
- rc
.top
);
139 /* Create the status bar */
140 hStatusWnd
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, NULL
, hWnd
, STATUS_WINDOW
);
144 /* Create the status bar panes */
148 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
150 /* Create tab pages */
151 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
153 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
154 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
155 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
157 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
158 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
159 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
163 memset(&item
, 0, sizeof(TCITEMW
));
164 item
.mask
= TCIF_TEXT
;
165 item
.pszText
= wszApplications
;
166 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 0, (LPARAM
)&item
);
167 memset(&item
, 0, sizeof(TCITEMW
));
168 item
.mask
= TCIF_TEXT
;
169 item
.pszText
= wszProcesses
;
170 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 1, (LPARAM
)&item
);
171 memset(&item
, 0, sizeof(TCITEMW
));
172 item
.mask
= TCIF_TEXT
;
173 item
.pszText
= wszPerformance
;
174 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 2, (LPARAM
)&item
);
176 /* Size everything correctly */
177 GetClientRect(hWnd
, &rc
);
178 nOldWidth
= rc
.right
;
179 nOldHeight
= rc
.bottom
;
180 /* nOldStartX = rc.left; */
181 /*nOldStartY = rc.top; */
183 #define PAGE_OFFSET_LEFT 17
184 #define PAGE_OFFSET_TOP 72
185 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
186 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
188 if ((TaskManagerSettings
.Left
!= 0) ||
189 (TaskManagerSettings
.Top
!= 0) ||
190 (TaskManagerSettings
.Right
!= 0) ||
191 (TaskManagerSettings
.Bottom
!= 0))
193 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
194 #ifdef __GNUC__TEST__
195 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
);
196 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
);
197 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
);
200 if (TaskManagerSettings
.Maximized
)
201 ShowWindow(hWnd
, SW_MAXIMIZE
);
203 /* Set the always on top style */
204 hMenu
= GetMenu(hWnd
);
205 hEditMenu
= GetSubMenu(hMenu
, 1);
206 hViewMenu
= GetSubMenu(hMenu
, 2);
207 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
208 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
210 /* Check or uncheck the always on top menu item */
211 if (TaskManagerSettings
.AlwaysOnTop
) {
212 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
213 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
215 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
216 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
219 /* Check or uncheck the minimize on use menu item */
220 if (TaskManagerSettings
.MinimizeOnUse
)
221 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
223 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
225 /* Check or uncheck the hide when minimized menu item */
226 if (TaskManagerSettings
.HideWhenMinimized
)
227 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
229 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
231 /* Check or uncheck the show 16-bit tasks menu item */
232 if (TaskManagerSettings
.Show16BitTasks
)
233 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
235 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
237 if (TaskManagerSettings
.View_LargeIcons
)
238 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
239 else if (TaskManagerSettings
.View_SmallIcons
)
240 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
242 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
244 if (TaskManagerSettings
.ShowKernelTimes
)
245 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
247 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
249 if (TaskManagerSettings
.UpdateSpeed
== 1)
250 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
251 else if (TaskManagerSettings
.UpdateSpeed
== 2)
252 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
253 else if (TaskManagerSettings
.UpdateSpeed
== 4)
254 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
256 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
258 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
259 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
261 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
263 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
264 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 0);
265 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 1);
266 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, 2);
267 TabCtrl_SetCurFocus
/*Sel*/(hTabWnd
, nActivePage
);
269 if (TaskManagerSettings
.UpdateSpeed
== 1)
270 SetTimer(hWnd
, 1, 1000, NULL
);
271 else if (TaskManagerSettings
.UpdateSpeed
== 2)
272 SetTimer(hWnd
, 1, 2000, NULL
);
273 else if (TaskManagerSettings
.UpdateSpeed
== 4)
274 SetTimer(hWnd
, 1, 4000, NULL
);
277 * Refresh the performance data
278 * Sample it twice so we can establish
279 * the delta values & cpu usage
284 RefreshApplicationPage();
285 RefreshProcessPage();
286 RefreshPerformancePage();
288 TrayIcon_ShellAddTrayIcon();
294 * This function handles all the moving events for the application
295 * It moves every child window that needs moving
297 static void OnMove( UINT nType
, int cx
, int cy
)
299 #ifdef __GNUC__TEST__
300 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
);
301 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
);
302 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
);
307 * This function handles all the sizing events for the application
308 * It re-sizes every window, and child window that needs re-sizing
310 static void OnSize( UINT nType
, int cx
, int cy
)
317 if (nType
== SIZE_MINIMIZED
)
319 if(TaskManagerSettings
.HideWhenMinimized
)
321 ShowWindow(hMainWnd
, SW_HIDE
);
326 nXDifference
= cx
- nOldWidth
;
327 nYDifference
= cy
- nOldHeight
;
331 /* Update the status bar size */
332 GetWindowRect(hStatusWnd
, &rc
);
333 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
335 /* Update the status bar pane sizes */
336 nParts
[0] = bInMenuLoop
? -1 : 100;
339 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
)nParts
);
341 /* Resize the tab control */
342 GetWindowRect(hTabWnd
, &rc
);
343 cx
= (rc
.right
- rc
.left
) + nXDifference
;
344 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
345 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
347 /* Resize the application page */
348 GetWindowRect(hApplicationPage
, &rc
);
349 cx
= (rc
.right
- rc
.left
) + nXDifference
;
350 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
351 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
353 /* Resize the process page */
354 GetWindowRect(hProcessPage
, &rc
);
355 cx
= (rc
.right
- rc
.left
) + nXDifference
;
356 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
357 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
359 /* Resize the performance page */
360 GetWindowRect(hPerformancePage
, &rc
);
361 cx
= (rc
.right
- rc
.left
) + nXDifference
;
362 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
363 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
366 static void LoadSettings(void)
372 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
373 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
374 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
376 /* Window size & position settings */
377 TaskManagerSettings
.Maximized
= FALSE
;
378 TaskManagerSettings
.Left
= 0;
379 TaskManagerSettings
.Top
= 0;
380 TaskManagerSettings
.Right
= 0;
381 TaskManagerSettings
.Bottom
= 0;
384 TaskManagerSettings
.ActiveTabPage
= 0;
386 /* Options menu settings */
387 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
388 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
389 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
390 TaskManagerSettings
.Show16BitTasks
= TRUE
;
392 /* Update speed settings */
393 TaskManagerSettings
.UpdateSpeed
= 2;
395 /* Applications page settings */
396 TaskManagerSettings
.View_LargeIcons
= FALSE
;
397 TaskManagerSettings
.View_SmallIcons
= FALSE
;
398 TaskManagerSettings
.View_Details
= TRUE
;
400 /* Processes page settings */
401 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
402 TaskManagerSettings
.Column_ImageName
= TRUE
;
403 TaskManagerSettings
.Column_PID
= TRUE
;
404 TaskManagerSettings
.Column_CPUUsage
= TRUE
;
405 TaskManagerSettings
.Column_CPUTime
= TRUE
;
406 TaskManagerSettings
.Column_MemoryUsage
= TRUE
;
407 TaskManagerSettings
.Column_MemoryUsageDelta
= FALSE
;
408 TaskManagerSettings
.Column_PeakMemoryUsage
= FALSE
;
409 TaskManagerSettings
.Column_PageFaults
= FALSE
;
410 TaskManagerSettings
.Column_USERObjects
= FALSE
;
411 TaskManagerSettings
.Column_IOReads
= FALSE
;
412 TaskManagerSettings
.Column_IOReadBytes
= FALSE
;
413 TaskManagerSettings
.Column_SessionID
= FALSE
; /* Server-only? */
414 TaskManagerSettings
.Column_UserName
= FALSE
; /* Server-only? */
415 TaskManagerSettings
.Column_PageFaultsDelta
= FALSE
;
416 TaskManagerSettings
.Column_VirtualMemorySize
= FALSE
;
417 TaskManagerSettings
.Column_PagedPool
= FALSE
;
418 TaskManagerSettings
.Column_NonPagedPool
= FALSE
;
419 TaskManagerSettings
.Column_BasePriority
= FALSE
;
420 TaskManagerSettings
.Column_HandleCount
= FALSE
;
421 TaskManagerSettings
.Column_ThreadCount
= FALSE
;
422 TaskManagerSettings
.Column_GDIObjects
= FALSE
;
423 TaskManagerSettings
.Column_IOWrites
= FALSE
;
424 TaskManagerSettings
.Column_IOWriteBytes
= FALSE
;
425 TaskManagerSettings
.Column_IOOther
= FALSE
;
426 TaskManagerSettings
.Column_IOOtherBytes
= FALSE
;
428 for (i
= 0; i
< 25; i
++) {
429 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
431 TaskManagerSettings
.ColumnSizeArray
[0] = 105;
432 TaskManagerSettings
.ColumnSizeArray
[1] = 50;
433 TaskManagerSettings
.ColumnSizeArray
[2] = 107;
434 TaskManagerSettings
.ColumnSizeArray
[3] = 70;
435 TaskManagerSettings
.ColumnSizeArray
[4] = 35;
436 TaskManagerSettings
.ColumnSizeArray
[5] = 70;
437 TaskManagerSettings
.ColumnSizeArray
[6] = 70;
438 TaskManagerSettings
.ColumnSizeArray
[7] = 100;
439 TaskManagerSettings
.ColumnSizeArray
[8] = 70;
440 TaskManagerSettings
.ColumnSizeArray
[9] = 70;
441 TaskManagerSettings
.ColumnSizeArray
[10] = 70;
442 TaskManagerSettings
.ColumnSizeArray
[11] = 70;
443 TaskManagerSettings
.ColumnSizeArray
[12] = 70;
444 TaskManagerSettings
.ColumnSizeArray
[13] = 70;
445 TaskManagerSettings
.ColumnSizeArray
[14] = 60;
446 TaskManagerSettings
.ColumnSizeArray
[15] = 60;
447 TaskManagerSettings
.ColumnSizeArray
[16] = 60;
448 TaskManagerSettings
.ColumnSizeArray
[17] = 60;
449 TaskManagerSettings
.ColumnSizeArray
[18] = 60;
450 TaskManagerSettings
.ColumnSizeArray
[19] = 70;
451 TaskManagerSettings
.ColumnSizeArray
[20] = 70;
452 TaskManagerSettings
.ColumnSizeArray
[21] = 70;
453 TaskManagerSettings
.ColumnSizeArray
[22] = 70;
454 TaskManagerSettings
.ColumnSizeArray
[23] = 70;
455 TaskManagerSettings
.ColumnSizeArray
[24] = 70;
457 TaskManagerSettings
.SortColumn
= 1;
458 TaskManagerSettings
.SortAscending
= TRUE
;
460 /* Performance page settings */
461 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
462 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
465 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
466 if (RegOpenKeyExW(HKEY_CURRENT_USER
, wszSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
468 /* Read the settings */
469 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
470 RegQueryValueExW(hKey
, wszPreferences
, NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
476 static void SaveSettings(void)
480 static const WCHAR wszSubKey3
[] = {'S','o','f','t','w','a','r','e','\\',
481 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
482 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
484 /* Open (or create) the key */
486 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
487 if (RegCreateKeyExW(HKEY_CURRENT_USER
, wszSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
489 /* Save the settings */
490 RegSetValueExW(hKey
, wszPreferences
, 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
495 static void TaskManager_OnRestoreMainWindow(void)
497 HMENU hMenu
, hOptionsMenu
;
500 hMenu
= GetMenu(hMainWnd
);
501 hOptionsMenu
= GetSubMenu(hMenu
, OPTIONS_MENU_INDEX
);
502 OnTop
= ((GetWindowLong(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
505 SetForegroundWindow(hMainWnd
);
506 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
509 static void TaskManager_OnEnterMenuLoop(HWND hWnd
)
513 /* Update the status bar pane sizes */
515 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
517 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
520 static void TaskManager_OnExitMenuLoop(HWND hWnd
)
526 static const WCHAR wszCPU_Usage
[] = {'C','P','U',' ','U','s','a','g','e',':',' ','%','3','d','%','%',0};
527 static const WCHAR wszProcesses
[] = {'P','r','o','c','e','s','s','e','s',':',' ','%','d',0};
530 /* Update the status bar pane sizes */
531 GetClientRect(hWnd
, &rc
);
534 nParts
[2] = rc
.right
;
535 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
536 SendMessageW(hStatusWnd
, SB_SETTEXT
, 0, 0);
537 wsprintfW(text
, wszCPU_Usage
, PerfDataGetProcessorUsage());
538 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 1, (LPARAM
)text
);
539 wsprintfW(text
, wszProcesses
, PerfDataGetProcessCount());
540 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)text
);
543 static void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
545 WCHAR wstr
[256] = {0};
547 LoadStringW(hInst
, nItemID
, wstr
, sizeof(wstr
)/sizeof(WCHAR
));
548 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)wstr
);
551 static void TaskManager_OnViewUpdateSpeedHigh(void)
555 HMENU hUpdateSpeedMenu
;
557 hMenu
= GetMenu(hMainWnd
);
558 hViewMenu
= GetSubMenu(hMenu
, 2);
559 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
561 TaskManagerSettings
.UpdateSpeed
= 1;
562 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
564 KillTimer(hMainWnd
, 1);
565 SetTimer(hMainWnd
, 1, 1000, NULL
);
568 static void TaskManager_OnViewUpdateSpeedNormal(void)
572 HMENU hUpdateSpeedMenu
;
574 hMenu
= GetMenu(hMainWnd
);
575 hViewMenu
= GetSubMenu(hMenu
, 2);
576 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
578 TaskManagerSettings
.UpdateSpeed
= 2;
579 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
581 KillTimer(hMainWnd
, 1);
582 SetTimer(hMainWnd
, 1, 2000, NULL
);
585 static void TaskManager_OnViewUpdateSpeedLow(void)
589 HMENU hUpdateSpeedMenu
;
591 hMenu
= GetMenu(hMainWnd
);
592 hViewMenu
= GetSubMenu(hMenu
, 2);
593 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
595 TaskManagerSettings
.UpdateSpeed
= 4;
596 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
598 KillTimer(hMainWnd
, 1);
599 SetTimer(hMainWnd
, 1, 4000, NULL
);
602 static void TaskManager_OnViewUpdateSpeedPaused(void)
606 HMENU hUpdateSpeedMenu
;
608 hMenu
= GetMenu(hMainWnd
);
609 hViewMenu
= GetSubMenu(hMenu
, 2);
610 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
611 TaskManagerSettings
.UpdateSpeed
= 0;
612 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
613 KillTimer(hMainWnd
, 1);
616 static void TaskManager_OnTabWndSelChange(void)
624 static const WCHAR wszLargeIcons
[] = {'L','a','r','&','g','e',' ','I','c','o','n','s',0};
625 static const WCHAR wszSmallIcons
[] = {'S','&','m','a','l','l',' ','I','c','o','n','s',0};
626 static const WCHAR wszDetails
[] = {'&','D','e','t','a','i','l','s',0};
627 static const WCHAR wszWindows
[] = {'&','W','i','n','d','o','w','s',0};
628 static const WCHAR wszSelectColumns
[] = {'&','S','e','l','e','c','t',' ',
629 'C','o','l','u','m','n','s','.','.','.',0};
630 static const WCHAR wszShow16bTasks
[] = {'&','S','h','o','w',' ','1','6','-','b','i','t',' ',
631 't','a','s','k','s',0};
632 static const WCHAR wszOneGraphAllCPU
[] = {'&','O','n','e',' ','G','r','a','p','h',',',' ',
633 'A','l','l',' ','C','P','U','s',0};
634 static const WCHAR wszOneGraphPerCPU
[] = {'O','n','e',' ','G','r','a','p','h',' ',
635 '&','P','e','r',' ','C','P','U',0};
636 static const WCHAR wszCPUHistory
[] = {'&','C','P','U',' ','H','i','s','t','o','r','y',0};
637 static const WCHAR wszShowKernelTimes
[] = {'&','S','h','o','w',' ','K','e','r','n','e','l',' ',
638 'T','i','m','e','s',0};
640 hMenu
= GetMenu(hMainWnd
);
641 hViewMenu
= GetSubMenu(hMenu
, 2);
642 hOptionsMenu
= GetSubMenu(hMenu
, 1);
643 TaskManagerSettings
.ActiveTabPage
= TabCtrl_GetCurSel(hTabWnd
);
644 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
645 hSubMenu
= GetSubMenu(hViewMenu
, i
);
647 DestroyMenu(hSubMenu
);
648 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
650 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
651 switch (TaskManagerSettings
.ActiveTabPage
) {
653 ShowWindow(hApplicationPage
, SW_SHOW
);
654 ShowWindow(hProcessPage
, SW_HIDE
);
655 ShowWindow(hPerformancePage
, SW_HIDE
);
656 BringWindowToTop(hApplicationPage
);
657 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, wszLargeIcons
);
658 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, wszSmallIcons
);
659 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, wszDetails
);
661 if (GetMenuItemCount(hMenu
) <= 4) {
662 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
663 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszWindows
);
664 DrawMenuBar(hMainWnd
);
666 if (TaskManagerSettings
.View_LargeIcons
)
667 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
668 else if (TaskManagerSettings
.View_SmallIcons
)
669 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
671 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
673 * Give the application list control focus
675 SetFocus(hApplicationPageListCtrl
);
679 ShowWindow(hApplicationPage
, SW_HIDE
);
680 ShowWindow(hProcessPage
, SW_SHOW
);
681 ShowWindow(hPerformancePage
, SW_HIDE
);
682 BringWindowToTop(hProcessPage
);
683 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, wszSelectColumns
);
684 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
);
685 if (TaskManagerSettings
.Show16BitTasks
)
686 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
687 if (GetMenuItemCount(hMenu
) > 4)
689 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
690 DrawMenuBar(hMainWnd
);
693 * Give the process list control focus
695 SetFocus(hProcessPageListCtrl
);
699 ShowWindow(hApplicationPage
, SW_HIDE
);
700 ShowWindow(hProcessPage
, SW_HIDE
);
701 ShowWindow(hPerformancePage
, SW_SHOW
);
702 BringWindowToTop(hPerformancePage
);
703 if (GetMenuItemCount(hMenu
) > 4) {
704 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
705 DrawMenuBar(hMainWnd
);
707 hSubMenu
= CreatePopupMenu();
708 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
);
709 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
);
710 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszCPUHistory
);
711 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
);
712 if (TaskManagerSettings
.ShowKernelTimes
)
713 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
715 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
716 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
717 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
719 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
721 * Give the tab control focus
728 LPWSTR
GetLastErrorText(LPWSTR lpwszBuf
, DWORD dwSize
)
731 LPWSTR lpwszTemp
= NULL
;
732 static const WCHAR wszFormat
[] = {'%','s',' ','(','%','u',')',0};
734 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
742 /* supplied buffer is not long enough */
743 if (!dwRet
|| ( (long)dwSize
< (long)dwRet
+14)) {
746 lpwszTemp
[strlenW(lpwszTemp
)-2] = '\0'; /* remove cr and newline character */
747 sprintfW(lpwszBuf
, wszFormat
, lpwszTemp
, GetLastError());
750 LocalFree(lpwszTemp
);
755 /* Message handler for dialog box. */
756 static INT_PTR CALLBACK
757 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
770 return OnCreate(hDlg
);
773 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
774 EndDialog(hDlg
, LOWORD(wParam
));
777 /* Process menu commands */
778 switch (LOWORD(wParam
))
781 TaskManager_OnFileNew();
783 case ID_OPTIONS_ALWAYSONTOP
:
784 TaskManager_OnOptionsAlwaysOnTop();
786 case ID_OPTIONS_MINIMIZEONUSE
:
787 TaskManager_OnOptionsMinimizeOnUse();
789 case ID_OPTIONS_HIDEWHENMINIMIZED
:
790 TaskManager_OnOptionsHideWhenMinimized();
792 case ID_OPTIONS_SHOW16BITTASKS
:
793 TaskManager_OnOptionsShow16BitTasks();
796 TaskManager_OnRestoreMainWindow();
799 ApplicationPage_OnViewLargeIcons();
802 ApplicationPage_OnViewSmallIcons();
804 case ID_VIEW_DETAILS
:
805 ApplicationPage_OnViewDetails();
807 case ID_VIEW_SHOWKERNELTIMES
:
808 PerformancePage_OnViewShowKernelTimes();
810 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
811 PerformancePage_OnViewCPUHistoryOneGraphAll();
813 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
814 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
816 case ID_VIEW_UPDATESPEED_HIGH
:
817 TaskManager_OnViewUpdateSpeedHigh();
819 case ID_VIEW_UPDATESPEED_NORMAL
:
820 TaskManager_OnViewUpdateSpeedNormal();
822 case ID_VIEW_UPDATESPEED_LOW
:
823 TaskManager_OnViewUpdateSpeedLow();
825 case ID_VIEW_UPDATESPEED_PAUSED
:
826 TaskManager_OnViewUpdateSpeedPaused();
828 case ID_VIEW_SELECTCOLUMNS
:
829 ProcessPage_OnViewSelectColumns();
831 case ID_VIEW_REFRESH
:
832 PostMessage(hDlg
, WM_TIMER
, 0, 0);
834 case ID_WINDOWS_TILEHORIZONTALLY
:
835 ApplicationPage_OnWindowsTileHorizontally();
837 case ID_WINDOWS_TILEVERTICALLY
:
838 ApplicationPage_OnWindowsTileVertically();
840 case ID_WINDOWS_MINIMIZE
:
841 ApplicationPage_OnWindowsMinimize();
843 case ID_WINDOWS_MAXIMIZE
:
844 ApplicationPage_OnWindowsMaximize();
846 case ID_WINDOWS_CASCADE
:
847 ApplicationPage_OnWindowsCascade();
849 case ID_WINDOWS_BRINGTOFRONT
:
850 ApplicationPage_OnWindowsBringToFront();
852 case ID_APPLICATION_PAGE_SWITCHTO
:
853 ApplicationPage_OnSwitchTo();
855 case ID_APPLICATION_PAGE_ENDTASK
:
856 ApplicationPage_OnEndTask();
858 case ID_APPLICATION_PAGE_GOTOPROCESS
:
859 ApplicationPage_OnGotoProcess();
861 case ID_PROCESS_PAGE_ENDPROCESS
:
862 ProcessPage_OnEndProcess();
864 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
865 ProcessPage_OnEndProcessTree();
867 case ID_PROCESS_PAGE_DEBUG
:
868 ProcessPage_OnDebug();
870 case ID_PROCESS_PAGE_SETAFFINITY
:
871 ProcessPage_OnSetAffinity();
873 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
874 ProcessPage_OnSetPriorityRealTime();
876 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
877 ProcessPage_OnSetPriorityHigh();
879 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
880 ProcessPage_OnSetPriorityAboveNormal();
882 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
883 ProcessPage_OnSetPriorityNormal();
885 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
886 ProcessPage_OnSetPriorityBelowNormal();
888 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
889 ProcessPage_OnSetPriorityLow();
891 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
892 ProcessPage_OnDebugChannels();
898 EndDialog(hDlg
, IDOK
);
910 HMENU hMenu
, hPopupMenu
;
914 OnTop
= ((GetWindowLong(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0);
916 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
917 hPopupMenu
= GetSubMenu(hMenu
, 0);
919 if(IsWindowVisible(hMainWnd
))
921 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
925 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
930 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
933 SetForegroundWindow(hMainWnd
);
934 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
939 case WM_LBUTTONDBLCLK
:
940 TaskManager_OnRestoreMainWindow();
946 idctrl
= (int)wParam
;
947 pnmh
= (LPNMHDR
)lParam
;
948 if ((pnmh
->hwndFrom
== hTabWnd
) &&
949 (pnmh
->idFrom
== IDC_TAB
) &&
950 (pnmh
->code
== TCN_SELCHANGE
))
952 TaskManager_OnTabWndSelChange();
958 GetClientRect(hDlg
, &rc
);
959 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
960 ReleaseDC(hDlg
, hdc
);
964 hdc
= BeginPaint(hDlg
, &ps
);
965 GetClientRect(hDlg
, &rc
);
966 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
971 /* Make sure the user is sizing the dialog */
972 /* in an acceptable range */
973 pRC
= (LPRECT
)lParam
;
974 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
975 /* If the width is too small enlarge it to the minimum */
976 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
977 pRC
->left
= pRC
->right
- nMinimumWidth
;
979 /* If the width is too small enlarge it to the minimum */
980 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
981 pRC
->right
= pRC
->left
+ nMinimumWidth
;
983 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
984 /* If the height is too small enlarge it to the minimum */
985 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
986 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
988 /* If the height is too small enlarge it to the minimum */
989 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
990 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
995 /* Handle the window sizing in it's own function */
996 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1000 /* Handle the window moving in it's own function */
1001 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1005 ShowWindow(hDlg
, SW_HIDE
);
1006 TrayIcon_ShellRemoveTrayIcon();
1007 wp
.length
= sizeof(WINDOWPLACEMENT
);
1008 GetWindowPlacement(hDlg
, &wp
);
1009 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
1010 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
1011 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
1012 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
1013 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
1014 TaskManagerSettings
.Maximized
= TRUE
;
1016 TaskManagerSettings
.Maximized
= FALSE
;
1017 return DefWindowProc(hDlg
, message
, wParam
, lParam
);
1020 /* Refresh the performance data */
1022 RefreshApplicationPage();
1023 RefreshProcessPage();
1024 RefreshPerformancePage();
1025 TrayIcon_ShellUpdateTrayIcon();
1028 case WM_ENTERMENULOOP
:
1029 TaskManager_OnEnterMenuLoop(hDlg
);
1031 case WM_EXITMENULOOP
:
1032 TaskManager_OnExitMenuLoop(hDlg
);
1035 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1042 int APIENTRY
WinMain(HINSTANCE hInstance
,
1043 HINSTANCE hPrevInstance
,
1049 TOKEN_PRIVILEGES tkp
;
1051 /* Initialize global variables */
1054 /* Change our priority class to HIGH */
1055 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
1056 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
1057 CloseHandle(hProcess
);
1059 /* Now let's get the SE_DEBUG_NAME privilege
1060 * so that we can debug processes
1063 /* Get a token for this process. */
1064 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
1065 /* Get the LUID for the debug privilege. */
1066 LookupPrivilegeValue(NULL
, SE_DEBUG_NAME
, &tkp
.Privileges
[0].Luid
);
1068 tkp
.PrivilegeCount
= 1; /* one privilege to set */
1069 tkp
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1071 /* Get the debug privilege for this process. */
1072 AdjustTokenPrivileges(hToken
, FALSE
, &tkp
, 0, NULL
, 0);
1075 /* Load our settings from the registry */
1078 /* Initialize perf data */
1079 if (!PerfDataInitialize()) {
1083 DialogBoxW(hInst
, (LPWSTR
)IDD_TASKMGR_DIALOG
, NULL
, TaskManagerWndProc
);
1085 /* Save our settings to the registry */
1087 PerfDataUninitialize();