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
31 #include "wine/unicode.h"
37 #define STATUS_WINDOW 2001
39 /* Global Variables: */
40 HINSTANCE hInst
; /* current instance */
42 HWND hMainWnd
; /* Main Window */
43 HWND hStatusWnd
; /* Status Bar Window */
44 HWND hTabWnd
; /* Tab Control Window */
46 int nMinimumWidth
; /* Minimum width of the dialog (OnSize()'s cx) */
47 int nMinimumHeight
; /* Minimum height of the dialog (OnSize()'s cy) */
49 int nOldWidth
; /* Holds the previous client area width */
50 int nOldHeight
; /* Holds the previous client area height */
52 BOOL bInMenuLoop
= FALSE
; /* Tells us if we are in the menu loop */
54 TASKMANAGER_SETTINGS TaskManagerSettings
;
57 void FillSolidRect(HDC hDC
, LPCRECT lpRect
, COLORREF clr
)
60 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, lpRect
, NULL
, 0, NULL
);
63 static void FillSolidRect2(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clr
)
72 ExtTextOutW(hDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
75 static void Draw3dRect(HDC hDC
, int x
, int y
, int cx
, int cy
, COLORREF clrTopLeft
, COLORREF clrBottomRight
)
77 FillSolidRect2(hDC
, x
, y
, cx
- 1, 1, clrTopLeft
);
78 FillSolidRect2(hDC
, x
, y
, 1, cy
- 1, clrTopLeft
);
79 FillSolidRect2(hDC
, x
+ cx
, y
, -1, cy
, clrBottomRight
);
80 FillSolidRect2(hDC
, x
, y
+ cy
, cx
, -1, clrBottomRight
);
83 void Font_DrawText(HDC hDC
, LPWSTR lpwszText
, int x
, int y
)
90 hFontDC
= CreateCompatibleDC(hDC
);
91 hFontBitmap
= LoadBitmapW(hInst
, MAKEINTRESOURCEW(IDB_FONT
));
92 hOldBitmap
= SelectObject(hFontDC
, hFontBitmap
);
94 for (i
= 0; lpwszText
[i
]; i
++) {
95 if ((lpwszText
[i
] >= '0') && (lpwszText
[i
] <= '9')) {
96 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, (lpwszText
[i
] - '0') * 8, 0, SRCCOPY
);
98 else if (lpwszText
[i
] == 'K')
100 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, 80, 0, SRCCOPY
);
102 else if (lpwszText
[i
] == '%')
104 BitBlt(hDC
, x
+ (i
* 8), y
, 8, 11, hFontDC
, 88, 0, SRCCOPY
);
107 SelectObject(hFontDC
, hOldBitmap
);
108 DeleteObject(hFontBitmap
);
112 static BOOL
OnCreate(HWND hWnd
)
117 HMENU hUpdateSpeedMenu
;
118 HMENU hCPUHistoryMenu
;
124 static WCHAR wszApplications
[255];
125 static WCHAR wszProcesses
[255];
126 static WCHAR wszPerformance
[255];
128 LoadStringW(hInst
, IDS_APPLICATIONS
, wszApplications
, sizeof(wszApplications
)/sizeof(WCHAR
));
129 LoadStringW(hInst
, IDS_PROCESSES
, wszProcesses
, sizeof(wszProcesses
)/sizeof(WCHAR
));
130 LoadStringW(hInst
, IDS_PERFORMANCE
, wszPerformance
, sizeof(wszPerformance
)/sizeof(WCHAR
));
132 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)LoadIconW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
)));
133 SendMessageW(hMainWnd
, WM_SETICON
, ICON_SMALL
,
134 (LPARAM
)LoadImageW(hInst
, MAKEINTRESOURCEW(IDI_TASKMANAGER
), IMAGE_ICON
,
135 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
138 /* Initialize the Windows Common Controls DLL */
139 InitCommonControls();
141 /* Get the minimum window sizes */
142 GetWindowRect(hWnd
, &rc
);
143 nMinimumWidth
= (rc
.right
- rc
.left
);
144 nMinimumHeight
= (rc
.bottom
- rc
.top
);
146 /* Create the status bar */
147 hStatusWnd
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
, NULL
, hWnd
, STATUS_WINDOW
);
151 /* Create the status bar panes */
155 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
157 /* Create tab pages */
158 hTabWnd
= GetDlgItem(hWnd
, IDC_TAB
);
160 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hWnd
, ApplicationPageWndProc
);
161 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hWnd
, ProcessPageWndProc
);
162 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hWnd
, PerformancePageWndProc
);
164 hApplicationPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_APPLICATION_PAGE
), hTabWnd
, ApplicationPageWndProc
);
165 hProcessPage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PROCESS_PAGE
), hTabWnd
, ProcessPageWndProc
);
166 hPerformancePage
= CreateDialogW(hInst
, MAKEINTRESOURCEW(IDD_PERFORMANCE_PAGE
), hTabWnd
, PerformancePageWndProc
);
170 memset(&item
, 0, sizeof(TCITEMW
));
171 item
.mask
= TCIF_TEXT
;
172 item
.pszText
= wszApplications
;
173 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 0, (LPARAM
)&item
);
174 memset(&item
, 0, sizeof(TCITEMW
));
175 item
.mask
= TCIF_TEXT
;
176 item
.pszText
= wszProcesses
;
177 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 1, (LPARAM
)&item
);
178 memset(&item
, 0, sizeof(TCITEMW
));
179 item
.mask
= TCIF_TEXT
;
180 item
.pszText
= wszPerformance
;
181 SendMessageW(hTabWnd
, TCM_INSERTITEMW
, 2, (LPARAM
)&item
);
183 /* Size everything correctly */
184 GetClientRect(hWnd
, &rc
);
185 nOldWidth
= rc
.right
;
186 nOldHeight
= rc
.bottom
;
187 /* nOldStartX = rc.left; */
188 /*nOldStartY = rc.top; */
190 #define PAGE_OFFSET_LEFT 17
191 #define PAGE_OFFSET_TOP 72
192 #define PAGE_OFFSET_WIDTH (PAGE_OFFSET_LEFT*2)
193 #define PAGE_OFFSET_HEIGHT (PAGE_OFFSET_TOP+32)
195 if ((TaskManagerSettings
.Left
!= 0) ||
196 (TaskManagerSettings
.Top
!= 0) ||
197 (TaskManagerSettings
.Right
!= 0) ||
198 (TaskManagerSettings
.Bottom
!= 0))
200 MoveWindow(hWnd
, TaskManagerSettings
.Left
, TaskManagerSettings
.Top
, TaskManagerSettings
.Right
- TaskManagerSettings
.Left
, TaskManagerSettings
.Bottom
- TaskManagerSettings
.Top
, TRUE
);
201 #ifdef __GNUC__TEST__
202 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
);
203 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
);
204 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
);
207 if (TaskManagerSettings
.Maximized
)
208 ShowWindow(hWnd
, SW_MAXIMIZE
);
210 /* Set the always on top style */
211 hMenu
= GetMenu(hWnd
);
212 hEditMenu
= GetSubMenu(hMenu
, 1);
213 hViewMenu
= GetSubMenu(hMenu
, 2);
214 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
215 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 7);
217 /* Check or uncheck the always on top menu item */
218 if (TaskManagerSettings
.AlwaysOnTop
) {
219 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_CHECKED
);
220 SetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
222 CheckMenuItem(hEditMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
|MF_UNCHECKED
);
223 SetWindowPos(hWnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
226 /* Check or uncheck the minimize on use menu item */
227 if (TaskManagerSettings
.MinimizeOnUse
)
228 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_CHECKED
);
230 CheckMenuItem(hEditMenu
, ID_OPTIONS_MINIMIZEONUSE
, MF_BYCOMMAND
|MF_UNCHECKED
);
232 /* Check or uncheck the hide when minimized menu item */
233 if (TaskManagerSettings
.HideWhenMinimized
)
234 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_CHECKED
);
236 CheckMenuItem(hEditMenu
, ID_OPTIONS_HIDEWHENMINIMIZED
, MF_BYCOMMAND
|MF_UNCHECKED
);
238 /* Check or uncheck the show 16-bit tasks menu item */
239 if (TaskManagerSettings
.Show16BitTasks
)
240 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
242 CheckMenuItem(hEditMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_UNCHECKED
);
244 if (TaskManagerSettings
.View_LargeIcons
)
245 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
246 else if (TaskManagerSettings
.View_SmallIcons
)
247 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
249 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
251 if (TaskManagerSettings
.ShowKernelTimes
)
252 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
254 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
256 if (TaskManagerSettings
.UpdateSpeed
== 1)
257 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
258 else if (TaskManagerSettings
.UpdateSpeed
== 2)
259 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
260 else if (TaskManagerSettings
.UpdateSpeed
== 4)
261 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
263 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
265 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
266 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
268 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
270 nActivePage
= TaskManagerSettings
.ActiveTabPage
;
271 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 0, 0);
272 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 1, 0);
273 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 2, 0);
274 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, nActivePage
, 0);
276 if (TaskManagerSettings
.UpdateSpeed
== 1)
277 SetTimer(hWnd
, 1, 1000, NULL
);
278 else if (TaskManagerSettings
.UpdateSpeed
== 2)
279 SetTimer(hWnd
, 1, 2000, NULL
);
280 else if (TaskManagerSettings
.UpdateSpeed
== 4)
281 SetTimer(hWnd
, 1, 4000, NULL
);
284 * Refresh the performance data
285 * Sample it twice so we can establish
286 * the delta values & cpu usage
291 RefreshApplicationPage();
292 RefreshProcessPage();
293 RefreshPerformancePage();
295 TrayIcon_ShellAddTrayIcon();
301 * This function handles all the moving events for the application
302 * It moves every child window that needs moving
304 static void OnMove( UINT nType
, int cx
, int cy
)
306 #ifdef __GNUC__TEST__
307 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
);
308 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
);
309 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
);
314 * This function handles all the sizing events for the application
315 * It re-sizes every window, and child window that needs re-sizing
317 static void OnSize( UINT nType
, int cx
, int cy
)
324 if (nType
== SIZE_MINIMIZED
)
326 if(TaskManagerSettings
.HideWhenMinimized
)
328 ShowWindow(hMainWnd
, SW_HIDE
);
333 nXDifference
= cx
- nOldWidth
;
334 nYDifference
= cy
- nOldHeight
;
338 /* Update the status bar size */
339 GetWindowRect(hStatusWnd
, &rc
);
340 SendMessageW(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
342 /* Update the status bar pane sizes */
343 nParts
[0] = bInMenuLoop
? -1 : 100;
346 SendMessageW(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (LPARAM
)nParts
);
348 /* Resize the tab control */
349 GetWindowRect(hTabWnd
, &rc
);
350 cx
= (rc
.right
- rc
.left
) + nXDifference
;
351 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
352 SetWindowPos(hTabWnd
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
354 /* Resize the application page */
355 GetWindowRect(hApplicationPage
, &rc
);
356 cx
= (rc
.right
- rc
.left
) + nXDifference
;
357 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
358 SetWindowPos(hApplicationPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
360 /* Resize the process page */
361 GetWindowRect(hProcessPage
, &rc
);
362 cx
= (rc
.right
- rc
.left
) + nXDifference
;
363 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
364 SetWindowPos(hProcessPage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
366 /* Resize the performance page */
367 GetWindowRect(hPerformancePage
, &rc
);
368 cx
= (rc
.right
- rc
.left
) + nXDifference
;
369 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
370 SetWindowPos(hPerformancePage
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
373 static void LoadSettings(void)
379 static const WCHAR wszSubKey
[] = {'S','o','f','t','w','a','r','e','\\',
380 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
381 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
383 /* Window size & position settings */
384 TaskManagerSettings
.Maximized
= FALSE
;
385 TaskManagerSettings
.Left
= 0;
386 TaskManagerSettings
.Top
= 0;
387 TaskManagerSettings
.Right
= 0;
388 TaskManagerSettings
.Bottom
= 0;
391 TaskManagerSettings
.ActiveTabPage
= 0;
393 /* Options menu settings */
394 TaskManagerSettings
.AlwaysOnTop
= FALSE
;
395 TaskManagerSettings
.MinimizeOnUse
= TRUE
;
396 TaskManagerSettings
.HideWhenMinimized
= TRUE
;
397 TaskManagerSettings
.Show16BitTasks
= TRUE
;
399 /* Update speed settings */
400 TaskManagerSettings
.UpdateSpeed
= 2;
402 /* Applications page settings */
403 TaskManagerSettings
.View_LargeIcons
= FALSE
;
404 TaskManagerSettings
.View_SmallIcons
= FALSE
;
405 TaskManagerSettings
.View_Details
= TRUE
;
407 /* Processes page settings */
408 TaskManagerSettings
.ShowProcessesFromAllUsers
= FALSE
; /* Server-only? */
409 TaskManagerSettings
.Column_ImageName
= TRUE
;
410 TaskManagerSettings
.Column_PID
= TRUE
;
411 TaskManagerSettings
.Column_CPUUsage
= TRUE
;
412 TaskManagerSettings
.Column_CPUTime
= TRUE
;
413 TaskManagerSettings
.Column_MemoryUsage
= TRUE
;
414 TaskManagerSettings
.Column_MemoryUsageDelta
= FALSE
;
415 TaskManagerSettings
.Column_PeakMemoryUsage
= FALSE
;
416 TaskManagerSettings
.Column_PageFaults
= FALSE
;
417 TaskManagerSettings
.Column_USERObjects
= FALSE
;
418 TaskManagerSettings
.Column_IOReads
= FALSE
;
419 TaskManagerSettings
.Column_IOReadBytes
= FALSE
;
420 TaskManagerSettings
.Column_SessionID
= FALSE
; /* Server-only? */
421 TaskManagerSettings
.Column_UserName
= FALSE
; /* Server-only? */
422 TaskManagerSettings
.Column_PageFaultsDelta
= FALSE
;
423 TaskManagerSettings
.Column_VirtualMemorySize
= FALSE
;
424 TaskManagerSettings
.Column_PagedPool
= FALSE
;
425 TaskManagerSettings
.Column_NonPagedPool
= FALSE
;
426 TaskManagerSettings
.Column_BasePriority
= FALSE
;
427 TaskManagerSettings
.Column_HandleCount
= FALSE
;
428 TaskManagerSettings
.Column_ThreadCount
= FALSE
;
429 TaskManagerSettings
.Column_GDIObjects
= FALSE
;
430 TaskManagerSettings
.Column_IOWrites
= FALSE
;
431 TaskManagerSettings
.Column_IOWriteBytes
= FALSE
;
432 TaskManagerSettings
.Column_IOOther
= FALSE
;
433 TaskManagerSettings
.Column_IOOtherBytes
= FALSE
;
435 for (i
= 0; i
< 25; i
++) {
436 TaskManagerSettings
.ColumnOrderArray
[i
] = i
;
438 TaskManagerSettings
.ColumnSizeArray
[0] = 105;
439 TaskManagerSettings
.ColumnSizeArray
[1] = 50;
440 TaskManagerSettings
.ColumnSizeArray
[2] = 107;
441 TaskManagerSettings
.ColumnSizeArray
[3] = 70;
442 TaskManagerSettings
.ColumnSizeArray
[4] = 35;
443 TaskManagerSettings
.ColumnSizeArray
[5] = 70;
444 TaskManagerSettings
.ColumnSizeArray
[6] = 70;
445 TaskManagerSettings
.ColumnSizeArray
[7] = 100;
446 TaskManagerSettings
.ColumnSizeArray
[8] = 70;
447 TaskManagerSettings
.ColumnSizeArray
[9] = 70;
448 TaskManagerSettings
.ColumnSizeArray
[10] = 70;
449 TaskManagerSettings
.ColumnSizeArray
[11] = 70;
450 TaskManagerSettings
.ColumnSizeArray
[12] = 70;
451 TaskManagerSettings
.ColumnSizeArray
[13] = 70;
452 TaskManagerSettings
.ColumnSizeArray
[14] = 60;
453 TaskManagerSettings
.ColumnSizeArray
[15] = 60;
454 TaskManagerSettings
.ColumnSizeArray
[16] = 60;
455 TaskManagerSettings
.ColumnSizeArray
[17] = 60;
456 TaskManagerSettings
.ColumnSizeArray
[18] = 60;
457 TaskManagerSettings
.ColumnSizeArray
[19] = 70;
458 TaskManagerSettings
.ColumnSizeArray
[20] = 70;
459 TaskManagerSettings
.ColumnSizeArray
[21] = 70;
460 TaskManagerSettings
.ColumnSizeArray
[22] = 70;
461 TaskManagerSettings
.ColumnSizeArray
[23] = 70;
462 TaskManagerSettings
.ColumnSizeArray
[24] = 70;
464 TaskManagerSettings
.SortColumn
= 1;
465 TaskManagerSettings
.SortAscending
= TRUE
;
467 /* Performance page settings */
468 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
469 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
472 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
473 if (RegOpenKeyExW(HKEY_CURRENT_USER
, wszSubKey
, 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
475 /* Read the settings */
476 dwSize
= sizeof(TASKMANAGER_SETTINGS
);
477 RegQueryValueExW(hKey
, wszPreferences
, NULL
, NULL
, (LPBYTE
)&TaskManagerSettings
, &dwSize
);
483 static void SaveSettings(void)
487 static const WCHAR wszSubKey3
[] = {'S','o','f','t','w','a','r','e','\\',
488 'W','i','n','e','\\','T','a','s','k','M','a','n','a','g','e','r',0};
489 static const WCHAR wszPreferences
[] = {'P','r','e','f','e','r','e','n','c','e','s',0};
491 /* Open (or create) the key */
493 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
494 if (RegCreateKeyExW(HKEY_CURRENT_USER
, wszSubKey3
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
) != ERROR_SUCCESS
)
496 /* Save the settings */
497 RegSetValueExW(hKey
, wszPreferences
, 0, REG_BINARY
, (LPBYTE
)&TaskManagerSettings
, sizeof(TASKMANAGER_SETTINGS
));
502 static void TaskManager_OnRestoreMainWindow(void)
506 OnTop
= (GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
509 SetForegroundWindow(hMainWnd
);
510 SetWindowPos(hMainWnd
, (OnTop
? HWND_TOPMOST
: HWND_TOP
), 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_SHOWWINDOW
);
513 static void TaskManager_OnEnterMenuLoop(HWND hWnd
)
517 /* Update the status bar pane sizes */
519 SendMessageW(hStatusWnd
, SB_SETPARTS
, 1, (LPARAM
)&nParts
);
521 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
524 static void TaskManager_OnExitMenuLoop(HWND hWnd
)
530 WCHAR wszCPU_Usage
[255];
531 WCHAR wszProcesses
[255];
533 LoadStringW(hInst
, IDS_STATUS_BAR_CPU_USAGE
, wszCPU_Usage
, sizeof(wszCPU_Usage
)/sizeof(WCHAR
));
534 LoadStringW(hInst
, IDS_STATUS_BAR_PROCESSES
, wszProcesses
, sizeof(wszProcesses
)/sizeof(WCHAR
));
537 /* Update the status bar pane sizes */
538 GetClientRect(hWnd
, &rc
);
541 nParts
[2] = rc
.right
;
542 SendMessageW(hStatusWnd
, SB_SETPARTS
, 3, (LPARAM
)nParts
);
543 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, 0);
544 wsprintfW(text
, wszCPU_Usage
, PerfDataGetProcessorUsage());
545 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 1, (LPARAM
)text
);
546 wsprintfW(text
, wszProcesses
, PerfDataGetProcessCount());
547 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)text
);
550 static void TaskManager_OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
552 WCHAR wstr
[256] = {0};
554 LoadStringW(hInst
, nItemID
, wstr
, sizeof(wstr
)/sizeof(WCHAR
));
555 SendMessageW(hStatusWnd
, SB_SETTEXTW
, 0, (LPARAM
)wstr
);
558 static void TaskManager_OnViewUpdateSpeedHigh(void)
562 HMENU hUpdateSpeedMenu
;
564 hMenu
= GetMenu(hMainWnd
);
565 hViewMenu
= GetSubMenu(hMenu
, 2);
566 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
568 TaskManagerSettings
.UpdateSpeed
= 1;
569 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_HIGH
, MF_BYCOMMAND
);
571 KillTimer(hMainWnd
, 1);
572 SetTimer(hMainWnd
, 1, 1000, NULL
);
575 static void TaskManager_OnViewUpdateSpeedNormal(void)
579 HMENU hUpdateSpeedMenu
;
581 hMenu
= GetMenu(hMainWnd
);
582 hViewMenu
= GetSubMenu(hMenu
, 2);
583 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
585 TaskManagerSettings
.UpdateSpeed
= 2;
586 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_NORMAL
, MF_BYCOMMAND
);
588 KillTimer(hMainWnd
, 1);
589 SetTimer(hMainWnd
, 1, 2000, NULL
);
592 static void TaskManager_OnViewUpdateSpeedLow(void)
596 HMENU hUpdateSpeedMenu
;
598 hMenu
= GetMenu(hMainWnd
);
599 hViewMenu
= GetSubMenu(hMenu
, 2);
600 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
602 TaskManagerSettings
.UpdateSpeed
= 4;
603 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_LOW
, MF_BYCOMMAND
);
605 KillTimer(hMainWnd
, 1);
606 SetTimer(hMainWnd
, 1, 4000, NULL
);
609 static void TaskManager_OnViewUpdateSpeedPaused(void)
613 HMENU hUpdateSpeedMenu
;
615 hMenu
= GetMenu(hMainWnd
);
616 hViewMenu
= GetSubMenu(hMenu
, 2);
617 hUpdateSpeedMenu
= GetSubMenu(hViewMenu
, 1);
618 TaskManagerSettings
.UpdateSpeed
= 0;
619 CheckMenuRadioItem(hUpdateSpeedMenu
, ID_VIEW_UPDATESPEED_HIGH
, ID_VIEW_UPDATESPEED_PAUSED
, ID_VIEW_UPDATESPEED_PAUSED
, MF_BYCOMMAND
);
620 KillTimer(hMainWnd
, 1);
623 static void TaskManager_OnTabWndSelChange(void)
631 WCHAR wszLargeIcons
[255];
632 WCHAR wszSmallIcons
[255];
633 WCHAR wszDetails
[255];
634 WCHAR wszWindows
[255];
635 WCHAR wszSelectColumns
[255];
636 WCHAR wszShow16bTasks
[255];
637 WCHAR wszOneGraphAllCPU
[255];
638 WCHAR wszOneGraphPerCPU
[255];
639 WCHAR wszCPUHistory
[255];
640 WCHAR wszShowKernelTimes
[255];
642 LoadStringW(hInst
, IDS_VIEW_LARGE
, wszLargeIcons
, sizeof(wszLargeIcons
)/sizeof(WCHAR
));
643 LoadStringW(hInst
, IDS_VIEW_SMALL
, wszSmallIcons
, sizeof(wszSmallIcons
)/sizeof(WCHAR
));
644 LoadStringW(hInst
, IDS_VIEW_DETAILS
, wszDetails
, sizeof(wszDetails
)/sizeof(WCHAR
));
645 LoadStringW(hInst
, IDS_WINDOWS
, wszWindows
, sizeof(wszWindows
)/sizeof(WCHAR
));
646 LoadStringW(hInst
, IDS_VIEW_SELECTCOLUMNS
, wszSelectColumns
, sizeof(wszSelectColumns
)/sizeof(WCHAR
));
647 LoadStringW(hInst
, IDS_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
, sizeof(wszShow16bTasks
)/sizeof(WCHAR
));
648 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
, sizeof(wszOneGraphAllCPU
)/sizeof(WCHAR
));
649 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
, sizeof(wszOneGraphPerCPU
)/sizeof(WCHAR
));
650 LoadStringW(hInst
, IDS_VIEW_CPUHISTORY
, wszCPUHistory
, sizeof(wszCPUHistory
)/sizeof(WCHAR
));
651 LoadStringW(hInst
, IDS_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
, sizeof(wszShowKernelTimes
)/sizeof(WCHAR
));
653 hMenu
= GetMenu(hMainWnd
);
654 hViewMenu
= GetSubMenu(hMenu
, 2);
655 hOptionsMenu
= GetSubMenu(hMenu
, 1);
656 TaskManagerSettings
.ActiveTabPage
= SendMessageW(hTabWnd
, TCM_GETCURSEL
, 0, 0);
657 for (i
= GetMenuItemCount(hViewMenu
) - 1; i
> 2; i
--) {
658 hSubMenu
= GetSubMenu(hViewMenu
, i
);
660 DestroyMenu(hSubMenu
);
661 RemoveMenu(hViewMenu
, i
, MF_BYPOSITION
);
663 RemoveMenu(hOptionsMenu
, 3, MF_BYPOSITION
);
664 switch (TaskManagerSettings
.ActiveTabPage
) {
666 ShowWindow(hApplicationPage
, SW_SHOW
);
667 ShowWindow(hProcessPage
, SW_HIDE
);
668 ShowWindow(hPerformancePage
, SW_HIDE
);
669 BringWindowToTop(hApplicationPage
);
670 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_LARGE
, wszLargeIcons
);
671 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SMALL
, wszSmallIcons
);
672 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_DETAILS
, wszDetails
);
674 if (GetMenuItemCount(hMenu
) <= 4) {
675 hSubMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_WINDOWSMENU
));
676 InsertMenuW(hMenu
, 3, MF_BYPOSITION
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszWindows
);
677 DrawMenuBar(hMainWnd
);
679 if (TaskManagerSettings
.View_LargeIcons
)
680 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
681 else if (TaskManagerSettings
.View_SmallIcons
)
682 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
684 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
686 * Give the application list control focus
688 SetFocus(hApplicationPageListCtrl
);
692 ShowWindow(hApplicationPage
, SW_HIDE
);
693 ShowWindow(hProcessPage
, SW_SHOW
);
694 ShowWindow(hPerformancePage
, SW_HIDE
);
695 BringWindowToTop(hProcessPage
);
696 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SELECTCOLUMNS
, wszSelectColumns
);
697 AppendMenuW(hOptionsMenu
, MF_STRING
, ID_OPTIONS_SHOW16BITTASKS
, wszShow16bTasks
);
698 if (TaskManagerSettings
.Show16BitTasks
)
699 CheckMenuItem(hOptionsMenu
, ID_OPTIONS_SHOW16BITTASKS
, MF_BYCOMMAND
|MF_CHECKED
);
700 if (GetMenuItemCount(hMenu
) > 4)
702 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
703 DrawMenuBar(hMainWnd
);
706 * Give the process list control focus
708 SetFocus(hProcessPageListCtrl
);
712 ShowWindow(hApplicationPage
, SW_HIDE
);
713 ShowWindow(hProcessPage
, SW_HIDE
);
714 ShowWindow(hPerformancePage
, SW_SHOW
);
715 BringWindowToTop(hPerformancePage
);
716 if (GetMenuItemCount(hMenu
) > 4) {
717 RemoveMenu(hMenu
, 3, MF_BYPOSITION
);
718 DrawMenuBar(hMainWnd
);
720 hSubMenu
= CreatePopupMenu();
721 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, wszOneGraphAllCPU
);
722 AppendMenuW(hSubMenu
, MF_STRING
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, wszOneGraphPerCPU
);
723 AppendMenuW(hViewMenu
, MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, wszCPUHistory
);
724 AppendMenuW(hViewMenu
, MF_STRING
, ID_VIEW_SHOWKERNELTIMES
, wszShowKernelTimes
);
725 if (TaskManagerSettings
.ShowKernelTimes
)
726 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
728 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
729 if (TaskManagerSettings
.CPUHistory_OneGraphPerCPU
)
730 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);
732 CheckMenuRadioItem(hSubMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
734 * Give the tab control focus
741 LPWSTR
GetLastErrorText(LPWSTR lpwszBuf
, DWORD dwSize
)
744 LPWSTR lpwszTemp
= NULL
;
745 static const WCHAR wszFormat
[] = {'%','s',' ','(','%','u',')',0};
747 dwRet
= FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
755 /* supplied buffer is not long enough */
756 if (!dwRet
|| ( dwSize
< dwRet
+14)) {
759 lpwszTemp
[strlenW(lpwszTemp
)-2] = '\0'; /* remove cr and newline character */
760 sprintfW(lpwszBuf
, wszFormat
, lpwszTemp
, GetLastError());
763 LocalFree(lpwszTemp
);
768 /* Message handler for dialog box. */
769 static INT_PTR CALLBACK
770 TaskManagerWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
772 static const WCHAR wszTaskmgr
[] = {'t','a','s','k','m','g','r',0};
783 return OnCreate(hDlg
);
786 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
) {
787 EndDialog(hDlg
, LOWORD(wParam
));
790 /* Process menu commands */
791 switch (LOWORD(wParam
))
794 TaskManager_OnFileNew();
796 case ID_OPTIONS_ALWAYSONTOP
:
797 TaskManager_OnOptionsAlwaysOnTop();
799 case ID_OPTIONS_MINIMIZEONUSE
:
800 TaskManager_OnOptionsMinimizeOnUse();
802 case ID_OPTIONS_HIDEWHENMINIMIZED
:
803 TaskManager_OnOptionsHideWhenMinimized();
805 case ID_OPTIONS_SHOW16BITTASKS
:
806 TaskManager_OnOptionsShow16BitTasks();
809 TaskManager_OnRestoreMainWindow();
812 ApplicationPage_OnViewLargeIcons();
815 ApplicationPage_OnViewSmallIcons();
817 case ID_VIEW_DETAILS
:
818 ApplicationPage_OnViewDetails();
820 case ID_VIEW_SHOWKERNELTIMES
:
821 PerformancePage_OnViewShowKernelTimes();
823 case ID_VIEW_CPUHISTORY_ONEGRAPHALL
:
824 PerformancePage_OnViewCPUHistoryOneGraphAll();
826 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
:
827 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
829 case ID_VIEW_UPDATESPEED_HIGH
:
830 TaskManager_OnViewUpdateSpeedHigh();
832 case ID_VIEW_UPDATESPEED_NORMAL
:
833 TaskManager_OnViewUpdateSpeedNormal();
835 case ID_VIEW_UPDATESPEED_LOW
:
836 TaskManager_OnViewUpdateSpeedLow();
838 case ID_VIEW_UPDATESPEED_PAUSED
:
839 TaskManager_OnViewUpdateSpeedPaused();
841 case ID_VIEW_SELECTCOLUMNS
:
842 ProcessPage_OnViewSelectColumns();
844 case ID_VIEW_REFRESH
:
845 PostMessageW(hDlg
, WM_TIMER
, 0, 0);
847 case ID_WINDOWS_TILEHORIZONTALLY
:
848 ApplicationPage_OnWindowsTileHorizontally();
850 case ID_WINDOWS_TILEVERTICALLY
:
851 ApplicationPage_OnWindowsTileVertically();
853 case ID_WINDOWS_MINIMIZE
:
854 ApplicationPage_OnWindowsMinimize();
856 case ID_WINDOWS_MAXIMIZE
:
857 ApplicationPage_OnWindowsMaximize();
859 case ID_WINDOWS_CASCADE
:
860 ApplicationPage_OnWindowsCascade();
862 case ID_WINDOWS_BRINGTOFRONT
:
863 ApplicationPage_OnWindowsBringToFront();
865 case ID_APPLICATION_PAGE_SWITCHTO
:
866 ApplicationPage_OnSwitchTo();
868 case ID_APPLICATION_PAGE_ENDTASK
:
869 ApplicationPage_OnEndTask();
871 case ID_APPLICATION_PAGE_GOTOPROCESS
:
872 ApplicationPage_OnGotoProcess();
874 case ID_PROCESS_PAGE_ENDPROCESS
:
875 ProcessPage_OnEndProcess();
877 case ID_PROCESS_PAGE_ENDPROCESSTREE
:
878 ProcessPage_OnEndProcessTree();
880 case ID_PROCESS_PAGE_DEBUG
:
881 ProcessPage_OnDebug();
883 case ID_PROCESS_PAGE_SETAFFINITY
:
884 ProcessPage_OnSetAffinity();
886 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME
:
887 ProcessPage_OnSetPriorityRealTime();
889 case ID_PROCESS_PAGE_SETPRIORITY_HIGH
:
890 ProcessPage_OnSetPriorityHigh();
892 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL
:
893 ProcessPage_OnSetPriorityAboveNormal();
895 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL
:
896 ProcessPage_OnSetPriorityNormal();
898 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL
:
899 ProcessPage_OnSetPriorityBelowNormal();
901 case ID_PROCESS_PAGE_SETPRIORITY_LOW
:
902 ProcessPage_OnSetPriorityLow();
904 case ID_PROCESS_PAGE_DEBUGCHANNELS
:
905 ProcessPage_OnDebugChannels();
908 WinHelpW(hDlg
, wszTaskmgr
, HELP_FINDER
, 0);
914 EndDialog(hDlg
, IDOK
);
926 HMENU hMenu
, hPopupMenu
;
930 OnTop
= (GetWindowLongW(hMainWnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
) != 0;
932 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_TRAY_POPUP
));
933 hPopupMenu
= GetSubMenu(hMenu
, 0);
935 if(IsWindowVisible(hMainWnd
))
937 DeleteMenu(hPopupMenu
, ID_RESTORE
, MF_BYCOMMAND
);
941 SetMenuDefaultItem(hPopupMenu
, ID_RESTORE
, FALSE
);
946 CheckMenuItem(hPopupMenu
, ID_OPTIONS_ALWAYSONTOP
, MF_BYCOMMAND
| MF_CHECKED
);
949 SetForegroundWindow(hMainWnd
);
950 TrackPopupMenuEx(hPopupMenu
, 0, pt
.x
, pt
.y
, hMainWnd
, NULL
);
955 case WM_LBUTTONDBLCLK
:
956 TaskManager_OnRestoreMainWindow();
962 pnmh
= (LPNMHDR
)lParam
;
963 if ((pnmh
->hwndFrom
== hTabWnd
) &&
964 (pnmh
->idFrom
== IDC_TAB
) &&
965 (pnmh
->code
== TCN_SELCHANGE
))
967 TaskManager_OnTabWndSelChange();
973 GetClientRect(hDlg
, &rc
);
974 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
975 ReleaseDC(hDlg
, hdc
);
979 hdc
= BeginPaint(hDlg
, &ps
);
980 GetClientRect(hDlg
, &rc
);
981 Draw3dRect(hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.top
+ 2, GetSysColor(COLOR_3DSHADOW
), GetSysColor(COLOR_3DHILIGHT
));
986 /* Make sure the user is sizing the dialog */
987 /* in an acceptable range */
988 pRC
= (LPRECT
)lParam
;
989 if ((wParam
== WMSZ_LEFT
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_BOTTOMLEFT
)) {
990 /* If the width is too small enlarge it to the minimum */
991 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
992 pRC
->left
= pRC
->right
- nMinimumWidth
;
994 /* If the width is too small enlarge it to the minimum */
995 if (nMinimumWidth
> (pRC
->right
- pRC
->left
))
996 pRC
->right
= pRC
->left
+ nMinimumWidth
;
998 if ((wParam
== WMSZ_TOP
) || (wParam
== WMSZ_TOPLEFT
) || (wParam
== WMSZ_TOPRIGHT
)) {
999 /* If the height is too small enlarge it to the minimum */
1000 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
1001 pRC
->top
= pRC
->bottom
- nMinimumHeight
;
1003 /* If the height is too small enlarge it to the minimum */
1004 if (nMinimumHeight
> (pRC
->bottom
- pRC
->top
))
1005 pRC
->bottom
= pRC
->top
+ nMinimumHeight
;
1010 /* Handle the window sizing in it's own function */
1011 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1015 /* Handle the window moving in it's own function */
1016 OnMove(wParam
, LOWORD(lParam
), HIWORD(lParam
));
1020 ShowWindow(hDlg
, SW_HIDE
);
1021 TrayIcon_ShellRemoveTrayIcon();
1022 wp
.length
= sizeof(WINDOWPLACEMENT
);
1023 GetWindowPlacement(hDlg
, &wp
);
1024 TaskManagerSettings
.Left
= wp
.rcNormalPosition
.left
;
1025 TaskManagerSettings
.Top
= wp
.rcNormalPosition
.top
;
1026 TaskManagerSettings
.Right
= wp
.rcNormalPosition
.right
;
1027 TaskManagerSettings
.Bottom
= wp
.rcNormalPosition
.bottom
;
1028 if (IsZoomed(hDlg
) || (wp
.flags
& WPF_RESTORETOMAXIMIZED
))
1029 TaskManagerSettings
.Maximized
= TRUE
;
1031 TaskManagerSettings
.Maximized
= FALSE
;
1032 return DefWindowProcW(hDlg
, message
, wParam
, lParam
);
1035 /* Refresh the performance data */
1037 RefreshApplicationPage();
1038 RefreshProcessPage();
1039 RefreshPerformancePage();
1040 TrayIcon_ShellUpdateTrayIcon();
1043 case WM_ENTERMENULOOP
:
1044 TaskManager_OnEnterMenuLoop(hDlg
);
1046 case WM_EXITMENULOOP
:
1047 TaskManager_OnExitMenuLoop(hDlg
);
1050 TaskManager_OnMenuSelect(hDlg
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
1057 int APIENTRY
WinMain(HINSTANCE hInstance
,
1058 HINSTANCE hPrevInstance
,
1064 TOKEN_PRIVILEGES tkp
;
1066 /* Initialize global variables */
1069 /* Change our priority class to HIGH */
1070 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, GetCurrentProcessId());
1071 SetPriorityClass(hProcess
, HIGH_PRIORITY_CLASS
);
1072 CloseHandle(hProcess
);
1074 /* Now let's get the SE_DEBUG_NAME privilege
1075 * so that we can debug processes
1078 /* Get a token for this process. */
1079 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
| TOKEN_QUERY
, &hToken
)) {
1080 static const WCHAR SeDebugPrivilegeW
[] = {'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0};
1082 /* Get the LUID for the debug privilege. */
1083 LookupPrivilegeValueW(NULL
, SeDebugPrivilegeW
, &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();