blob: 08acf71f8d5952c03c2c412b7a5d636595c698a7 [file] [log] [blame]
Eric Pouechd6b348f2004-03-23 01:19:54 +00001/*
2 * ReactOS Task Manager
3 *
4 * taskmgr.c : Defines the entry point for the application.
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +00007 * Copyright (C) 2008 Vladimir Pankratov
Eric Pouechd6b348f2004-03-23 01:19:54 +00008 *
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.
13 *
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.
18 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020021 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Eric Pouechd6b348f2004-03-23 01:19:54 +000022 */
23
24#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
25#include <windows.h>
26#include <commctrl.h>
27#include <stdlib.h>
Eric Pouechd6b348f2004-03-23 01:19:54 +000028#include <memory.h>
Eric Pouechd6b348f2004-03-23 01:19:54 +000029#include <stdio.h>
30#include <winnt.h>
31
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +000032#include "wine/unicode.h"
Eric Pouechd6b348f2004-03-23 01:19:54 +000033#include "resource.h"
34#include "taskmgr.h"
35#include "perfdata.h"
36#include "column.h"
37
38#define STATUS_WINDOW 2001
39
40/* Global Variables: */
41HINSTANCE hInst; /* current instance */
42
43HWND hMainWnd; /* Main Window */
44HWND hStatusWnd; /* Status Bar Window */
45HWND hTabWnd; /* Tab Control Window */
46
47int nMinimumWidth; /* Minimum width of the dialog (OnSize()'s cx) */
48int nMinimumHeight; /* Minimum height of the dialog (OnSize()'s cy) */
49
50int nOldWidth; /* Holds the previous client area width */
51int nOldHeight; /* Holds the previous client area height */
52
53BOOL bInMenuLoop = FALSE; /* Tells us if we are in the menu loop */
54
55TASKMANAGER_SETTINGS TaskManagerSettings;
56
57
Francois Gouget5c144172006-03-21 18:35:41 +010058void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
Eric Pouechd6b348f2004-03-23 01:19:54 +000059{
Francois Gouget5c144172006-03-21 18:35:41 +010060 SetBkColor(hDC, clr);
61 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
62}
Eric Pouechd6b348f2004-03-23 01:19:54 +000063
Francois Gougetfb02a4c2009-05-06 03:33:55 +020064static void FillSolidRect2(HDC hDC, int x, int y, int cx, int cy, COLORREF clr)
Francois Gouget5c144172006-03-21 18:35:41 +010065{
66 RECT rect;
Eric Pouechd6b348f2004-03-23 01:19:54 +000067
Francois Gouget5c144172006-03-21 18:35:41 +010068 SetBkColor(hDC, clr);
69 rect.left = x;
70 rect.top = y;
71 rect.right = x + cx;
72 rect.bottom = y + cy;
73 ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
74}
Eric Pouechd6b348f2004-03-23 01:19:54 +000075
Francois Gougetfb02a4c2009-05-06 03:33:55 +020076static void Draw3dRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
Francois Gouget5c144172006-03-21 18:35:41 +010077{
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);
82}
83
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +000084void Font_DrawText(HDC hDC, LPWSTR lpwszText, int x, int y)
Francois Gouget5c144172006-03-21 18:35:41 +010085{
86 HDC hFontDC;
87 HBITMAP hFontBitmap;
88 HBITMAP hOldBitmap;
89 int i;
90
91 hFontDC = CreateCompatibleDC(hDC);
92 hFontBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_FONT));
Michael Stefaniuc2d90c852008-10-25 23:39:55 +020093 hOldBitmap = SelectObject(hFontDC, hFontBitmap);
Francois Gouget5c144172006-03-21 18:35:41 +010094
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +000095 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);
Francois Gouget5c144172006-03-21 18:35:41 +010098 }
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +000099 else if (lpwszText[i] == 'K')
Francois Gouget5c144172006-03-21 18:35:41 +0100100 {
101 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 80, 0, SRCCOPY);
102 }
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000103 else if (lpwszText[i] == '%')
Francois Gouget5c144172006-03-21 18:35:41 +0100104 {
105 BitBlt(hDC, x + (i * 8), y, 8, 11, hFontDC, 88, 0, SRCCOPY);
106 }
107 }
108 SelectObject(hFontDC, hOldBitmap);
109 DeleteObject(hFontBitmap);
110 DeleteDC(hFontDC);
111}
112
113static BOOL OnCreate(HWND hWnd)
114{
115 HMENU hMenu;
116 HMENU hEditMenu;
117 HMENU hViewMenu;
118 HMENU hUpdateSpeedMenu;
119 HMENU hCPUHistoryMenu;
120 int nActivePage;
121 int nParts[3];
122 RECT rc;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000123 TCITEMW item;
Francois Gouget5c144172006-03-21 18:35:41 +0100124
Aurimas FiĊĦeras34ccc502009-06-21 15:28:09 +0300125 static WCHAR wszApplications[255];
126 static WCHAR wszProcesses[255];
127 static WCHAR wszPerformance[255];
128
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));
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000132
133 SendMessageW(hMainWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER)));
Alexandre Julliard80997b22010-04-19 20:12:39 +0200134 SendMessageW(hMainWnd, WM_SETICON, ICON_SMALL,
135 (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_TASKMANAGER), IMAGE_ICON,
136 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
137 LR_SHARED));
Francois Gouget5c144172006-03-21 18:35:41 +0100138
139 /* Initialize the Windows Common Controls DLL */
140 InitCommonControls();
141
142 /* Get the minimum window sizes */
143 GetWindowRect(hWnd, &rc);
144 nMinimumWidth = (rc.right - rc.left);
145 nMinimumHeight = (rc.bottom - rc.top);
146
147 /* Create the status bar */
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000148 hStatusWnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, NULL, hWnd, STATUS_WINDOW);
Francois Gouget5c144172006-03-21 18:35:41 +0100149 if(!hStatusWnd)
150 return FALSE;
151
152 /* Create the status bar panes */
153 nParts[0] = 100;
154 nParts[1] = 210;
155 nParts[2] = 400;
Michael Stefaniuc87b15bb2009-03-02 23:26:51 +0100156 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
Francois Gouget5c144172006-03-21 18:35:41 +0100157
158 /* Create tab pages */
159 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
160#if 1
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000161 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);
Francois Gouget5c144172006-03-21 18:35:41 +0100164#else
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000165 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);
Francois Gouget5c144172006-03-21 18:35:41 +0100168#endif
169
170 /* Insert tabs */
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000171 memset(&item, 0, sizeof(TCITEMW));
Francois Gouget5c144172006-03-21 18:35:41 +0100172 item.mask = TCIF_TEXT;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000173 item.pszText = wszApplications;
174 SendMessageW(hTabWnd, TCM_INSERTITEMW, 0, (LPARAM)&item);
175 memset(&item, 0, sizeof(TCITEMW));
Francois Gouget5c144172006-03-21 18:35:41 +0100176 item.mask = TCIF_TEXT;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000177 item.pszText = wszProcesses;
178 SendMessageW(hTabWnd, TCM_INSERTITEMW, 1, (LPARAM)&item);
179 memset(&item, 0, sizeof(TCITEMW));
Francois Gouget5c144172006-03-21 18:35:41 +0100180 item.mask = TCIF_TEXT;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000181 item.pszText = wszPerformance;
182 SendMessageW(hTabWnd, TCM_INSERTITEMW, 2, (LPARAM)&item);
Francois Gouget5c144172006-03-21 18:35:41 +0100183
184 /* Size everything correctly */
185 GetClientRect(hWnd, &rc);
186 nOldWidth = rc.right;
187 nOldHeight = rc.bottom;
188 /* nOldStartX = rc.left; */
189 /*nOldStartY = rc.top; */
190
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)
195
196 if ((TaskManagerSettings.Left != 0) ||
197 (TaskManagerSettings.Top != 0) ||
198 (TaskManagerSettings.Right != 0) ||
199 (TaskManagerSettings.Bottom != 0))
200 {
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);
206#endif
207 }
208 if (TaskManagerSettings.Maximized)
209 ShowWindow(hWnd, SW_MAXIMIZE);
210
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);
217
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);
222 } else {
223 CheckMenuItem(hEditMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND|MF_UNCHECKED);
224 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
225 }
226
227 /* Check or uncheck the minimize on use menu item */
228 if (TaskManagerSettings.MinimizeOnUse)
229 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_CHECKED);
230 else
231 CheckMenuItem(hEditMenu, ID_OPTIONS_MINIMIZEONUSE, MF_BYCOMMAND|MF_UNCHECKED);
232
233 /* Check or uncheck the hide when minimized menu item */
234 if (TaskManagerSettings.HideWhenMinimized)
235 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_CHECKED);
236 else
237 CheckMenuItem(hEditMenu, ID_OPTIONS_HIDEWHENMINIMIZED, MF_BYCOMMAND|MF_UNCHECKED);
238
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);
242 else
243 CheckMenuItem(hEditMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_UNCHECKED);
244
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);
249 else
250 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
251
252 if (TaskManagerSettings.ShowKernelTimes)
253 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
254 else
255 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
256
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);
263 else
264 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
265
266 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
267 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
268 else
269 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
270
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);
276
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);
283
284 /*
285 * Refresh the performance data
286 * Sample it twice so we can establish
287 * the delta values & cpu usage
Eric Pouechd6b348f2004-03-23 01:19:54 +0000288 */
Francois Gouget5c144172006-03-21 18:35:41 +0100289 PerfDataRefresh();
290 PerfDataRefresh();
Eric Pouechd6b348f2004-03-23 01:19:54 +0000291
Francois Gouget5c144172006-03-21 18:35:41 +0100292 RefreshApplicationPage();
293 RefreshProcessPage();
294 RefreshPerformancePage();
Eric Pouechd6b348f2004-03-23 01:19:54 +0000295
Francois Gouget5c144172006-03-21 18:35:41 +0100296 TrayIcon_ShellAddTrayIcon();
Eric Pouechd6b348f2004-03-23 01:19:54 +0000297
Francois Gouget5c144172006-03-21 18:35:41 +0100298 return TRUE;
299}
300
301/* OnMove()
302 * This function handles all the moving events for the application
303 * It moves every child window that needs moving
304 */
305static void OnMove( UINT nType, int cx, int cy )
306{
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);
311#endif
312}
313
314/* OnSize()
315 * This function handles all the sizing events for the application
316 * It re-sizes every window, and child window that needs re-sizing
317 */
318static void OnSize( UINT nType, int cx, int cy )
319{
320 int nParts[3];
321 int nXDifference;
322 int nYDifference;
323 RECT rc;
324
325 if (nType == SIZE_MINIMIZED)
326 {
327 if(TaskManagerSettings.HideWhenMinimized)
328 {
329 ShowWindow(hMainWnd, SW_HIDE);
330 }
331 return;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000332 }
333
Francois Gouget5c144172006-03-21 18:35:41 +0100334 nXDifference = cx - nOldWidth;
335 nYDifference = cy - nOldHeight;
336 nOldWidth = cx;
337 nOldHeight = cy;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000338
Francois Gouget5c144172006-03-21 18:35:41 +0100339 /* Update the status bar size */
340 GetWindowRect(hStatusWnd, &rc);
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000341 SendMessageW(hStatusWnd, WM_SIZE, nType, MAKELPARAM(cx, cy + (rc.bottom - rc.top)));
Francois Gouget5c144172006-03-21 18:35:41 +0100342
343 /* Update the status bar pane sizes */
344 nParts[0] = bInMenuLoop ? -1 : 100;
345 nParts[1] = 210;
346 nParts[2] = cx;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000347 SendMessageW(hStatusWnd, SB_SETPARTS, bInMenuLoop ? 1 : 3, (LPARAM)nParts);
Francois Gouget5c144172006-03-21 18:35:41 +0100348
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);
354
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);
360
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);
366
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);
372}
373
374static void LoadSettings(void)
375{
376 HKEY hKey;
Francois Gouget5c144172006-03-21 18:35:41 +0100377 int i;
378 DWORD dwSize;
379
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000380 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};
383
Francois Gouget5c144172006-03-21 18:35:41 +0100384 /* Window size & position settings */
385 TaskManagerSettings.Maximized = FALSE;
386 TaskManagerSettings.Left = 0;
387 TaskManagerSettings.Top = 0;
388 TaskManagerSettings.Right = 0;
389 TaskManagerSettings.Bottom = 0;
390
391 /* Tab settings */
392 TaskManagerSettings.ActiveTabPage = 0;
393
394 /* Options menu settings */
395 TaskManagerSettings.AlwaysOnTop = FALSE;
396 TaskManagerSettings.MinimizeOnUse = TRUE;
397 TaskManagerSettings.HideWhenMinimized = TRUE;
398 TaskManagerSettings.Show16BitTasks = TRUE;
399
400 /* Update speed settings */
401 TaskManagerSettings.UpdateSpeed = 2;
402
403 /* Applications page settings */
404 TaskManagerSettings.View_LargeIcons = FALSE;
405 TaskManagerSettings.View_SmallIcons = FALSE;
406 TaskManagerSettings.View_Details = TRUE;
407
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;
435
436 for (i = 0; i < 25; i++) {
437 TaskManagerSettings.ColumnOrderArray[i] = i;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000438 }
Francois Gouget5c144172006-03-21 18:35:41 +0100439 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;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000464
Francois Gouget5c144172006-03-21 18:35:41 +0100465 TaskManagerSettings.SortColumn = 1;
466 TaskManagerSettings.SortAscending = TRUE;
467
468 /* Performance page settings */
469 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
470 TaskManagerSettings.ShowKernelTimes = FALSE;
471
472 /* Open the key */
473 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000474 if (RegOpenKeyExW(HKEY_CURRENT_USER, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
Francois Gouget5c144172006-03-21 18:35:41 +0100475 return;
476 /* Read the settings */
477 dwSize = sizeof(TASKMANAGER_SETTINGS);
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000478 RegQueryValueExW(hKey, wszPreferences, NULL, NULL, (LPBYTE)&TaskManagerSettings, &dwSize);
Francois Gouget5c144172006-03-21 18:35:41 +0100479
480 /* Close the key */
481 RegCloseKey(hKey);
482}
483
484static void SaveSettings(void)
485{
486 HKEY hKey;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000487
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};
Francois Gouget5c144172006-03-21 18:35:41 +0100491
492 /* Open (or create) the key */
493
494 /* @@ Wine registry key: HKCU\Software\Wine\TaskManager */
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000495 if (RegCreateKeyExW(HKEY_CURRENT_USER, wszSubKey3, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
Francois Gouget5c144172006-03-21 18:35:41 +0100496 return;
497 /* Save the settings */
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000498 RegSetValueExW(hKey, wszPreferences, 0, REG_BINARY, (LPBYTE)&TaskManagerSettings, sizeof(TASKMANAGER_SETTINGS));
Francois Gouget5c144172006-03-21 18:35:41 +0100499 /* Close the key */
500 RegCloseKey(hKey);
501}
502
503static void TaskManager_OnRestoreMainWindow(void)
504{
Francois Gouget5c144172006-03-21 18:35:41 +0100505 BOOL OnTop;
506
Francois Gouget5c144172006-03-21 18:35:41 +0100507 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
508
509 OpenIcon(hMainWnd);
510 SetForegroundWindow(hMainWnd);
511 SetWindowPos(hMainWnd, (OnTop ? HWND_TOPMOST : HWND_TOP), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
512}
513
514static void TaskManager_OnEnterMenuLoop(HWND hWnd)
515{
516 int nParts;
517
518 /* Update the status bar pane sizes */
519 nParts = -1;
Michael Stefaniuc87b15bb2009-03-02 23:26:51 +0100520 SendMessageW(hStatusWnd, SB_SETPARTS, 1, (LPARAM)&nParts);
Francois Gouget5c144172006-03-21 18:35:41 +0100521 bInMenuLoop = TRUE;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000522 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, 0);
Francois Gouget5c144172006-03-21 18:35:41 +0100523}
524
525static void TaskManager_OnExitMenuLoop(HWND hWnd)
526{
527 RECT rc;
528 int nParts[3];
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000529 WCHAR text[256];
530
Aurimas FiĊĦeras88a08f92009-06-21 16:04:14 +0300531 WCHAR wszCPU_Usage[255];
532 WCHAR wszProcesses[255];
533
534 LoadStringW(hInst, IDS_STATUS_BAR_CPU_USAGE, wszCPU_Usage, sizeof(wszCPU_Usage)/sizeof(WCHAR));
535 LoadStringW(hInst, IDS_STATUS_BAR_PROCESSES, wszProcesses, sizeof(wszProcesses)/sizeof(WCHAR));
Francois Gouget5c144172006-03-21 18:35:41 +0100536
537 bInMenuLoop = FALSE;
538 /* Update the status bar pane sizes */
539 GetClientRect(hWnd, &rc);
540 nParts[0] = 100;
541 nParts[1] = 210;
542 nParts[2] = rc.right;
Michael Stefaniuc87b15bb2009-03-02 23:26:51 +0100543 SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM)nParts);
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000544 SendMessageW(hStatusWnd, SB_SETTEXT, 0, 0);
545 wsprintfW(text, wszCPU_Usage, PerfDataGetProcessorUsage());
546 SendMessageW(hStatusWnd, SB_SETTEXTW, 1, (LPARAM)text);
547 wsprintfW(text, wszProcesses, PerfDataGetProcessCount());
548 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)text);
Francois Gouget5c144172006-03-21 18:35:41 +0100549}
550
551static void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)
552{
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000553 WCHAR wstr[256] = {0};
Francois Gouget5c144172006-03-21 18:35:41 +0100554
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000555 LoadStringW(hInst, nItemID, wstr, sizeof(wstr)/sizeof(WCHAR));
556 SendMessageW(hStatusWnd, SB_SETTEXTW, 0, (LPARAM)wstr);
Francois Gouget5c144172006-03-21 18:35:41 +0100557}
558
559static void TaskManager_OnViewUpdateSpeedHigh(void)
560{
561 HMENU hMenu;
562 HMENU hViewMenu;
563 HMENU hUpdateSpeedMenu;
564
565 hMenu = GetMenu(hMainWnd);
566 hViewMenu = GetSubMenu(hMenu, 2);
567 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
568
569 TaskManagerSettings.UpdateSpeed = 1;
570 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_HIGH, MF_BYCOMMAND);
571
572 KillTimer(hMainWnd, 1);
573 SetTimer(hMainWnd, 1, 1000, NULL);
574}
575
576static void TaskManager_OnViewUpdateSpeedNormal(void)
577{
578 HMENU hMenu;
579 HMENU hViewMenu;
580 HMENU hUpdateSpeedMenu;
581
582 hMenu = GetMenu(hMainWnd);
583 hViewMenu = GetSubMenu(hMenu, 2);
584 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
585
586 TaskManagerSettings.UpdateSpeed = 2;
587 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_NORMAL, MF_BYCOMMAND);
588
589 KillTimer(hMainWnd, 1);
590 SetTimer(hMainWnd, 1, 2000, NULL);
591}
592
593static void TaskManager_OnViewUpdateSpeedLow(void)
594{
595 HMENU hMenu;
596 HMENU hViewMenu;
597 HMENU hUpdateSpeedMenu;
598
599 hMenu = GetMenu(hMainWnd);
600 hViewMenu = GetSubMenu(hMenu, 2);
601 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
602
603 TaskManagerSettings.UpdateSpeed = 4;
604 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_LOW, MF_BYCOMMAND);
605
606 KillTimer(hMainWnd, 1);
607 SetTimer(hMainWnd, 1, 4000, NULL);
608}
609
610static void TaskManager_OnViewUpdateSpeedPaused(void)
611{
612 HMENU hMenu;
613 HMENU hViewMenu;
614 HMENU hUpdateSpeedMenu;
615
616 hMenu = GetMenu(hMainWnd);
617 hViewMenu = GetSubMenu(hMenu, 2);
618 hUpdateSpeedMenu = GetSubMenu(hViewMenu, 1);
619 TaskManagerSettings.UpdateSpeed = 0;
620 CheckMenuRadioItem(hUpdateSpeedMenu, ID_VIEW_UPDATESPEED_HIGH, ID_VIEW_UPDATESPEED_PAUSED, ID_VIEW_UPDATESPEED_PAUSED, MF_BYCOMMAND);
621 KillTimer(hMainWnd, 1);
622}
623
624static void TaskManager_OnTabWndSelChange(void)
625{
626 int i;
627 HMENU hMenu;
628 HMENU hOptionsMenu;
629 HMENU hViewMenu;
630 HMENU hSubMenu;
631
Aurimas FiĊĦeras34ccc502009-06-21 15:28:09 +0300632 WCHAR wszLargeIcons[255];
633 WCHAR wszSmallIcons[255];
634 WCHAR wszDetails[255];
635 WCHAR wszWindows[255];
636 WCHAR wszSelectColumns[255];
637 WCHAR wszShow16bTasks[255];
638 WCHAR wszOneGraphAllCPU[255];
639 WCHAR wszOneGraphPerCPU[255];
640 WCHAR wszCPUHistory[255];
641 WCHAR wszShowKernelTimes[255];
642
643 LoadStringW(hInst, IDS_VIEW_LARGE, wszLargeIcons, sizeof(wszLargeIcons)/sizeof(WCHAR));
644 LoadStringW(hInst, IDS_VIEW_SMALL, wszSmallIcons, sizeof(wszSmallIcons)/sizeof(WCHAR));
645 LoadStringW(hInst, IDS_VIEW_DETAILS, wszDetails, sizeof(wszDetails)/sizeof(WCHAR));
646 LoadStringW(hInst, IDS_WINDOWS, wszWindows, sizeof(wszWindows)/sizeof(WCHAR));
647 LoadStringW(hInst, IDS_VIEW_SELECTCOLUMNS, wszSelectColumns, sizeof(wszSelectColumns)/sizeof(WCHAR));
648 LoadStringW(hInst, IDS_OPTIONS_SHOW16BITTASKS, wszShow16bTasks, sizeof(wszShow16bTasks)/sizeof(WCHAR));
649 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU, sizeof(wszOneGraphAllCPU)/sizeof(WCHAR));
650 LoadStringW(hInst, IDS_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU, sizeof(wszOneGraphPerCPU)/sizeof(WCHAR));
651 LoadStringW(hInst, IDS_VIEW_CPUHISTORY, wszCPUHistory, sizeof(wszCPUHistory)/sizeof(WCHAR));
652 LoadStringW(hInst, IDS_VIEW_SHOWKERNELTIMES, wszShowKernelTimes, sizeof(wszShowKernelTimes)/sizeof(WCHAR));
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000653
Francois Gouget5c144172006-03-21 18:35:41 +0100654 hMenu = GetMenu(hMainWnd);
655 hViewMenu = GetSubMenu(hMenu, 2);
656 hOptionsMenu = GetSubMenu(hMenu, 1);
657 TaskManagerSettings.ActiveTabPage = TabCtrl_GetCurSel(hTabWnd);
658 for (i = GetMenuItemCount(hViewMenu) - 1; i > 2; i--) {
659 hSubMenu = GetSubMenu(hViewMenu, i);
660 if (hSubMenu)
661 DestroyMenu(hSubMenu);
662 RemoveMenu(hViewMenu, i, MF_BYPOSITION);
663 }
664 RemoveMenu(hOptionsMenu, 3, MF_BYPOSITION);
665 switch (TaskManagerSettings.ActiveTabPage) {
666 case 0:
667 ShowWindow(hApplicationPage, SW_SHOW);
668 ShowWindow(hProcessPage, SW_HIDE);
669 ShowWindow(hPerformancePage, SW_HIDE);
670 BringWindowToTop(hApplicationPage);
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000671 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_LARGE, wszLargeIcons);
672 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SMALL, wszSmallIcons);
673 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_DETAILS, wszDetails);
Francois Gouget5c144172006-03-21 18:35:41 +0100674
675 if (GetMenuItemCount(hMenu) <= 4) {
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000676 hSubMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_WINDOWSMENU));
677 InsertMenuW(hMenu, 3, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hSubMenu, wszWindows);
Francois Gouget5c144172006-03-21 18:35:41 +0100678 DrawMenuBar(hMainWnd);
679 }
680 if (TaskManagerSettings.View_LargeIcons)
681 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
682 else if (TaskManagerSettings.View_SmallIcons)
683 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
684 else
685 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
686 /*
687 * Give the application list control focus
688 */
689 SetFocus(hApplicationPageListCtrl);
690 break;
691
692 case 1:
693 ShowWindow(hApplicationPage, SW_HIDE);
694 ShowWindow(hProcessPage, SW_SHOW);
695 ShowWindow(hPerformancePage, SW_HIDE);
696 BringWindowToTop(hProcessPage);
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000697 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SELECTCOLUMNS, wszSelectColumns);
698 AppendMenuW(hOptionsMenu, MF_STRING, ID_OPTIONS_SHOW16BITTASKS, wszShow16bTasks);
Francois Gouget5c144172006-03-21 18:35:41 +0100699 if (TaskManagerSettings.Show16BitTasks)
700 CheckMenuItem(hOptionsMenu, ID_OPTIONS_SHOW16BITTASKS, MF_BYCOMMAND|MF_CHECKED);
701 if (GetMenuItemCount(hMenu) > 4)
702 {
703 RemoveMenu(hMenu, 3, MF_BYPOSITION);
704 DrawMenuBar(hMainWnd);
705 }
706 /*
707 * Give the process list control focus
708 */
709 SetFocus(hProcessPageListCtrl);
710 break;
711
712 case 2:
713 ShowWindow(hApplicationPage, SW_HIDE);
714 ShowWindow(hProcessPage, SW_HIDE);
715 ShowWindow(hPerformancePage, SW_SHOW);
716 BringWindowToTop(hPerformancePage);
717 if (GetMenuItemCount(hMenu) > 4) {
718 RemoveMenu(hMenu, 3, MF_BYPOSITION);
719 DrawMenuBar(hMainWnd);
720 }
721 hSubMenu = CreatePopupMenu();
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000722 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHALL, wszOneGraphAllCPU);
723 AppendMenuW(hSubMenu, MF_STRING, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, wszOneGraphPerCPU);
724 AppendMenuW(hViewMenu, MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, wszCPUHistory);
725 AppendMenuW(hViewMenu, MF_STRING, ID_VIEW_SHOWKERNELTIMES, wszShowKernelTimes);
Francois Gouget5c144172006-03-21 18:35:41 +0100726 if (TaskManagerSettings.ShowKernelTimes)
727 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
728 else
729 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
730 if (TaskManagerSettings.CPUHistory_OneGraphPerCPU)
731 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
732 else
733 CheckMenuRadioItem(hSubMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
734 /*
735 * Give the tab control focus
736 */
737 SetFocus(hTabWnd);
738 break;
739 }
740}
741
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000742LPWSTR GetLastErrorText(LPWSTR lpwszBuf, DWORD dwSize)
Francois Gouget5c144172006-03-21 18:35:41 +0100743{
744 DWORD dwRet;
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000745 LPWSTR lpwszTemp = NULL;
746 static const WCHAR wszFormat[] = {'%','s',' ','(','%','u',')',0};
Francois Gouget5c144172006-03-21 18:35:41 +0100747
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000748 dwRet = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
Francois Gouget5c144172006-03-21 18:35:41 +0100749 NULL,
750 GetLastError(),
751 LANG_NEUTRAL,
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000752 (LPWSTR)&lpwszTemp,
Francois Gouget5c144172006-03-21 18:35:41 +0100753 0,
754 NULL );
755
756 /* supplied buffer is not long enough */
Michael Stefaniucefeb9ee2010-05-18 01:30:51 +0200757 if (!dwRet || ( dwSize < dwRet+14)) {
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000758 lpwszBuf[0] = '\0';
Francois Gouget5c144172006-03-21 18:35:41 +0100759 } else {
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000760 lpwszTemp[strlenW(lpwszTemp)-2] = '\0'; /* remove cr and newline character */
761 sprintfW(lpwszBuf, wszFormat, lpwszTemp, GetLastError());
Francois Gouget5c144172006-03-21 18:35:41 +0100762 }
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000763 if (lpwszTemp) {
Michael Stefaniuce8992412008-12-08 04:07:58 +0100764 LocalFree(lpwszTemp);
Francois Gouget5c144172006-03-21 18:35:41 +0100765 }
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000766 return lpwszBuf;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000767}
768
769/* Message handler for dialog box. */
Francois Gouget5c144172006-03-21 18:35:41 +0100770static INT_PTR CALLBACK
Alexandre Julliard86663762005-09-14 10:06:09 +0000771TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Eric Pouechd6b348f2004-03-23 01:19:54 +0000772{
773 HDC hdc;
774 PAINTSTRUCT ps;
775 LPRECT pRC;
776 RECT rc;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000777 LPNMHDR pnmh;
778 WINDOWPLACEMENT wp;
779
780 switch (message) {
781 case WM_INITDIALOG:
782 hMainWnd = hDlg;
783 return OnCreate(hDlg);
784
785 case WM_COMMAND:
786 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
787 EndDialog(hDlg, LOWORD(wParam));
788 return TRUE;
789 }
790 /* Process menu commands */
791 switch (LOWORD(wParam))
792 {
793 case ID_FILE_NEW:
794 TaskManager_OnFileNew();
795 break;
796 case ID_OPTIONS_ALWAYSONTOP:
797 TaskManager_OnOptionsAlwaysOnTop();
798 break;
799 case ID_OPTIONS_MINIMIZEONUSE:
800 TaskManager_OnOptionsMinimizeOnUse();
801 break;
802 case ID_OPTIONS_HIDEWHENMINIMIZED:
803 TaskManager_OnOptionsHideWhenMinimized();
804 break;
805 case ID_OPTIONS_SHOW16BITTASKS:
806 TaskManager_OnOptionsShow16BitTasks();
807 break;
Thomas Weidenmuellerec9024c2005-09-14 19:17:12 +0000808 case ID_RESTORE:
809 TaskManager_OnRestoreMainWindow();
810 break;
Eric Pouechd6b348f2004-03-23 01:19:54 +0000811 case ID_VIEW_LARGE:
812 ApplicationPage_OnViewLargeIcons();
813 break;
814 case ID_VIEW_SMALL:
815 ApplicationPage_OnViewSmallIcons();
816 break;
817 case ID_VIEW_DETAILS:
818 ApplicationPage_OnViewDetails();
819 break;
820 case ID_VIEW_SHOWKERNELTIMES:
821 PerformancePage_OnViewShowKernelTimes();
822 break;
823 case ID_VIEW_CPUHISTORY_ONEGRAPHALL:
824 PerformancePage_OnViewCPUHistoryOneGraphAll();
825 break;
826 case ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU:
827 PerformancePage_OnViewCPUHistoryOneGraphPerCPU();
828 break;
829 case ID_VIEW_UPDATESPEED_HIGH:
830 TaskManager_OnViewUpdateSpeedHigh();
831 break;
832 case ID_VIEW_UPDATESPEED_NORMAL:
833 TaskManager_OnViewUpdateSpeedNormal();
834 break;
835 case ID_VIEW_UPDATESPEED_LOW:
836 TaskManager_OnViewUpdateSpeedLow();
837 break;
838 case ID_VIEW_UPDATESPEED_PAUSED:
839 TaskManager_OnViewUpdateSpeedPaused();
840 break;
841 case ID_VIEW_SELECTCOLUMNS:
842 ProcessPage_OnViewSelectColumns();
843 break;
844 case ID_VIEW_REFRESH:
845 PostMessage(hDlg, WM_TIMER, 0, 0);
846 break;
847 case ID_WINDOWS_TILEHORIZONTALLY:
848 ApplicationPage_OnWindowsTileHorizontally();
849 break;
850 case ID_WINDOWS_TILEVERTICALLY:
851 ApplicationPage_OnWindowsTileVertically();
852 break;
853 case ID_WINDOWS_MINIMIZE:
854 ApplicationPage_OnWindowsMinimize();
855 break;
856 case ID_WINDOWS_MAXIMIZE:
857 ApplicationPage_OnWindowsMaximize();
858 break;
859 case ID_WINDOWS_CASCADE:
860 ApplicationPage_OnWindowsCascade();
861 break;
862 case ID_WINDOWS_BRINGTOFRONT:
863 ApplicationPage_OnWindowsBringToFront();
864 break;
865 case ID_APPLICATION_PAGE_SWITCHTO:
866 ApplicationPage_OnSwitchTo();
867 break;
868 case ID_APPLICATION_PAGE_ENDTASK:
869 ApplicationPage_OnEndTask();
870 break;
871 case ID_APPLICATION_PAGE_GOTOPROCESS:
872 ApplicationPage_OnGotoProcess();
873 break;
874 case ID_PROCESS_PAGE_ENDPROCESS:
875 ProcessPage_OnEndProcess();
876 break;
877 case ID_PROCESS_PAGE_ENDPROCESSTREE:
878 ProcessPage_OnEndProcessTree();
879 break;
880 case ID_PROCESS_PAGE_DEBUG:
881 ProcessPage_OnDebug();
882 break;
883 case ID_PROCESS_PAGE_SETAFFINITY:
884 ProcessPage_OnSetAffinity();
885 break;
886 case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
887 ProcessPage_OnSetPriorityRealTime();
888 break;
889 case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
890 ProcessPage_OnSetPriorityHigh();
891 break;
892 case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
893 ProcessPage_OnSetPriorityAboveNormal();
894 break;
895 case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
896 ProcessPage_OnSetPriorityNormal();
897 break;
898 case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
899 ProcessPage_OnSetPriorityBelowNormal();
900 break;
901 case ID_PROCESS_PAGE_SETPRIORITY_LOW:
902 ProcessPage_OnSetPriorityLow();
903 break;
904 case ID_PROCESS_PAGE_DEBUGCHANNELS:
905 ProcessPage_OnDebugChannels();
906 break;
907 case ID_HELP_ABOUT:
908 OnAbout();
909 break;
910 case ID_FILE_EXIT:
Filip Navarae8efed92005-09-14 15:37:25 +0000911 EndDialog(hDlg, IDOK);
Eric Pouechd6b348f2004-03-23 01:19:54 +0000912 break;
913 }
914 break;
915
Thomas Weidenmuellerec9024c2005-09-14 19:17:12 +0000916 case WM_ONTRAYICON:
917 switch(lParam)
918 {
919 case WM_RBUTTONDOWN:
920 {
921 POINT pt;
922 BOOL OnTop;
923 HMENU hMenu, hPopupMenu;
924
925 GetCursorPos(&pt);
926
927 OnTop = ((GetWindowLong(hMainWnd, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0);
928
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +0000929 hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_TRAY_POPUP));
Thomas Weidenmuellerec9024c2005-09-14 19:17:12 +0000930 hPopupMenu = GetSubMenu(hMenu, 0);
931
932 if(IsWindowVisible(hMainWnd))
933 {
934 DeleteMenu(hPopupMenu, ID_RESTORE, MF_BYCOMMAND);
935 }
936 else
937 {
938 SetMenuDefaultItem(hPopupMenu, ID_RESTORE, FALSE);
939 }
940
941 if(OnTop)
942 {
943 CheckMenuItem(hPopupMenu, ID_OPTIONS_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED);
944 }
945
946 SetForegroundWindow(hMainWnd);
947 TrackPopupMenuEx(hPopupMenu, 0, pt.x, pt.y, hMainWnd, NULL);
948
949 DestroyMenu(hMenu);
950 break;
951 }
952 case WM_LBUTTONDBLCLK:
953 TaskManager_OnRestoreMainWindow();
954 break;
955 }
956 break;
957
Eric Pouechd6b348f2004-03-23 01:19:54 +0000958 case WM_NOTIFY:
Eric Pouechd6b348f2004-03-23 01:19:54 +0000959 pnmh = (LPNMHDR)lParam;
960 if ((pnmh->hwndFrom == hTabWnd) &&
961 (pnmh->idFrom == IDC_TAB) &&
962 (pnmh->code == TCN_SELCHANGE))
963 {
964 TaskManager_OnTabWndSelChange();
965 }
966 break;
967
968 case WM_NCPAINT:
969 hdc = GetDC(hDlg);
970 GetClientRect(hDlg, &rc);
971 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
972 ReleaseDC(hDlg, hdc);
973 break;
974
975 case WM_PAINT:
976 hdc = BeginPaint(hDlg, &ps);
977 GetClientRect(hDlg, &rc);
978 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
979 EndPaint(hDlg, &ps);
980 break;
981
982 case WM_SIZING:
983 /* Make sure the user is sizing the dialog */
984 /* in an acceptable range */
985 pRC = (LPRECT)lParam;
986 if ((wParam == WMSZ_LEFT) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_BOTTOMLEFT)) {
987 /* If the width is too small enlarge it to the minimum */
988 if (nMinimumWidth > (pRC->right - pRC->left))
989 pRC->left = pRC->right - nMinimumWidth;
990 } else {
991 /* If the width is too small enlarge it to the minimum */
992 if (nMinimumWidth > (pRC->right - pRC->left))
993 pRC->right = pRC->left + nMinimumWidth;
994 }
995 if ((wParam == WMSZ_TOP) || (wParam == WMSZ_TOPLEFT) || (wParam == WMSZ_TOPRIGHT)) {
996 /* If the height is too small enlarge it to the minimum */
997 if (nMinimumHeight > (pRC->bottom - pRC->top))
998 pRC->top = pRC->bottom - nMinimumHeight;
999 } else {
1000 /* If the height is too small enlarge it to the minimum */
1001 if (nMinimumHeight > (pRC->bottom - pRC->top))
1002 pRC->bottom = pRC->top + nMinimumHeight;
1003 }
1004 return TRUE;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001005
1006 case WM_SIZE:
1007 /* Handle the window sizing in it's own function */
1008 OnSize(wParam, LOWORD(lParam), HIWORD(lParam));
1009 break;
1010
1011 case WM_MOVE:
1012 /* Handle the window moving in it's own function */
1013 OnMove(wParam, LOWORD(lParam), HIWORD(lParam));
1014 break;
1015
1016 case WM_DESTROY:
1017 ShowWindow(hDlg, SW_HIDE);
1018 TrayIcon_ShellRemoveTrayIcon();
1019 wp.length = sizeof(WINDOWPLACEMENT);
1020 GetWindowPlacement(hDlg, &wp);
1021 TaskManagerSettings.Left = wp.rcNormalPosition.left;
1022 TaskManagerSettings.Top = wp.rcNormalPosition.top;
1023 TaskManagerSettings.Right = wp.rcNormalPosition.right;
1024 TaskManagerSettings.Bottom = wp.rcNormalPosition.bottom;
1025 if (IsZoomed(hDlg) || (wp.flags & WPF_RESTORETOMAXIMIZED))
1026 TaskManagerSettings.Maximized = TRUE;
1027 else
1028 TaskManagerSettings.Maximized = FALSE;
1029 return DefWindowProc(hDlg, message, wParam, lParam);
1030
1031 case WM_TIMER:
1032 /* Refresh the performance data */
1033 PerfDataRefresh();
1034 RefreshApplicationPage();
1035 RefreshProcessPage();
1036 RefreshPerformancePage();
1037 TrayIcon_ShellUpdateTrayIcon();
1038 break;
1039
1040 case WM_ENTERMENULOOP:
1041 TaskManager_OnEnterMenuLoop(hDlg);
1042 break;
1043 case WM_EXITMENULOOP:
1044 TaskManager_OnExitMenuLoop(hDlg);
1045 break;
1046 case WM_MENUSELECT:
1047 TaskManager_OnMenuSelect(hDlg, LOWORD(wParam), HIWORD(wParam), (HMENU)lParam);
1048 break;
1049 }
1050
1051 return 0;
1052}
1053
Francois Gouget5c144172006-03-21 18:35:41 +01001054int APIENTRY WinMain(HINSTANCE hInstance,
1055 HINSTANCE hPrevInstance,
1056 LPSTR lpCmdLine,
1057 int nCmdShow)
Eric Pouechd6b348f2004-03-23 01:19:54 +00001058{
Francois Gouget5c144172006-03-21 18:35:41 +01001059 HANDLE hProcess;
1060 HANDLE hToken;
1061 TOKEN_PRIVILEGES tkp;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001062
Francois Gouget5c144172006-03-21 18:35:41 +01001063 /* Initialize global variables */
1064 hInst = hInstance;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001065
Francois Gouget5c144172006-03-21 18:35:41 +01001066 /* Change our priority class to HIGH */
1067 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
1068 SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
1069 CloseHandle(hProcess);
Eric Pouechd6b348f2004-03-23 01:19:54 +00001070
Francois Gouget5c144172006-03-21 18:35:41 +01001071 /* Now let's get the SE_DEBUG_NAME privilege
1072 * so that we can debug processes
Eric Pouechd6b348f2004-03-23 01:19:54 +00001073 */
Eric Pouechd6b348f2004-03-23 01:19:54 +00001074
Francois Gouget5c144172006-03-21 18:35:41 +01001075 /* Get a token for this process. */
1076 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
1077 /* Get the LUID for the debug privilege. */
1078 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
Eric Pouechd6b348f2004-03-23 01:19:54 +00001079
Francois Gouget5c144172006-03-21 18:35:41 +01001080 tkp.PrivilegeCount = 1; /* one privilege to set */
1081 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001082
Francois Gouget5c144172006-03-21 18:35:41 +01001083 /* Get the debug privilege for this process. */
Michael Stefaniuc4f199a12008-11-02 00:27:00 +01001084 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
Thomas Weidenmuellerec9024c2005-09-14 19:17:12 +00001085 }
Eric Pouechd6b348f2004-03-23 01:19:54 +00001086
Francois Gouget5c144172006-03-21 18:35:41 +01001087 /* Load our settings from the registry */
1088 LoadSettings();
Eric Pouechd6b348f2004-03-23 01:19:54 +00001089
Francois Gouget5c144172006-03-21 18:35:41 +01001090 /* Initialize perf data */
1091 if (!PerfDataInitialize()) {
1092 return -1;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001093 }
Eric Pouechd6b348f2004-03-23 01:19:54 +00001094
Vladimir Pankratovb28a6c12008-08-20 08:32:24 +00001095 DialogBoxW(hInst, (LPWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);
Francois Gouget5c144172006-03-21 18:35:41 +01001096
1097 /* Save our settings to the registry */
1098 SaveSettings();
1099 PerfDataUninitialize();
1100 return 0;
Eric Pouechd6b348f2004-03-23 01:19:54 +00001101}