-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.h
646 lines (532 loc) · 19.4 KB
/
pages.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
//+-------------------------------------------------------------------------
//
// TaskMan - NT TaskManager
// Copyright (C) Microsoft
//
// File: pages.h
//
// History: Nov-10-95 DavePl Created
//
//--------------------------------------------------------------------------
// CPage class
//
// Each of our tabs is represented by an instance of a class derived
// from the CPage class. This way, the main window can call a standard
// set of methods (size, paint, etc) on each page without concern about
// the particular functionality each page provides.
#pragma once
class CPage
{
public:
// Sent when page is being created
virtual HRESULT Initialize(HWND hwndParent) PURE;
// Sent when page is being displayed
virtual HRESULT Activate() PURE;
// Sent when page is being hidden
virtual void Deactivate() PURE;
// Send when page is being shut down
virtual HRESULT Destroy() PURE;
// Returns the title of the page for use on the tab control
virtual void GetTitle(LPTSTR pszText, size_t bufsize) PURE;
// Returns the handle to the page's main dialog
virtual HWND GetPageWindow() PURE;
// Sent when a timer event (update display) occurs
virtual void TimerEvent() PURE;
};
#define CPU_PENS 8
#define CUSTOM_PENS 1
#define NUM_PENS (CPU_PENS + CUSTOM_PENS)
typedef struct tagGRAPH
{
HWND hwndFrame;
HWND hwndGraph;
} GRAPH, *PGRAPH;
enum ADAPTER_HISTORY
{
BYTES_SENT_UTIL = 0,
BYTES_RECEIVED_UTIL = 1
};
extern "C" {
//
// IPHLPAPI does not have this function defines in the header file.
//
DWORD
NhGetInterfaceNameFromDeviceGuid(
IN GUID *pGuid,
OUT PWCHAR pwszBuffer,
IN OUT PULONG pulBufferSize,
IN BOOL bCache,
IN BOOL bRefresh
);
}
#define MAX_ADAPTERS 32
#define GUID_STR_LENGTH 38
typedef struct tagADAPTER_INFOEX
{
MIB_IFROW ifRowStartStats;
MIB_IFROW ifRowStats[2];
ULONG ulHistory[2][HIST_SIZE];
ULONGLONG ullLinkspeed;
BOOLEAN bAdjustLinkSpeed;
WCHAR wszDesc[MAXLEN_IFDESCR];
WCHAR wszConnectionName[MAXLEN_IFDESCR];
WCHAR wszGuid[GUID_STR_LENGTH + 1];
ULONGLONG ullLastTickCount;
ULONGLONG ullTickCountDiff;
DWORD dwScale;
} ADAPTER_INFOEX, *PADAPTER_INFOEX, **PPADAPTER_INFOEX;
class CAdapter
{
public:
CAdapter();
HRESULT Update(BOOLEAN & bAdapterListChange);
LPWSTR GetAdapterText(DWORD dwAdapter, NETCOLUMNID nStatValue);
ULONGLONG GetAdapterStat(DWORD dwAdapter, NETCOLUMNID nStatValue, BOOL bAccumulative = FALSE);
HRESULT Reset();
ULONG *GetAdapterHistory(DWORD dwAdapter, ADAPTER_HISTORY nHistoryType);
DWORD GetScale(DWORD dwAdapter);
void SetScale(DWORD dwAdapter, DWORD dwScale);
void RefreshConnectionNames();
DWORD GetNumberOfAdapters();
~CAdapter();
private:
HRESULT RefreshAdapterTable();
HRESULT InitializeAdapter(PPADAPTER_INFOEX ppaiAdapterStats, PIP_ADAPTER_INDEX_MAP pAdapterDescription);
void AdjustLinkSpeed(PADAPTER_INFOEX pAdapterInfo);
HRESULT GetConnectionName(LPWSTR pwszAdapterGuid, LPWSTR pwszConnectionName, DWORD cchConnectionName );
BOOLEAN AdvanceAdapterHistory(DWORD dwAdapter);
private:
PIP_INTERFACE_INFO m_pifTable;
PPADAPTER_INFOEX m_ppaiAdapterStats;
DWORD m_dwAdapterCount;
BOOLEAN m_bToggle;
DWORD m_dwLastReportedNumberOfAdapters;
};
// CNetworkPage
//
// Class describing the network page
//
class CNetPage : public CPage
{
public:
CNetPage();
HRESULT Initialize(HWND hwndParent);
DWORD GetNumberOfGraphs();
HRESULT SetupColumns();
void ScrollGraphs(WPARAM wParam);
void SaveColumnWidths();
void RememberColumnOrder(HWND hwndList);
void RestoreColumnOrder(HWND hwndList);
void PickColumns();
HRESULT Activate();
void Deactivate();
void DrawAdapterGraph(LPDRAWITEMSTRUCT lpdi, UINT iPane);
void SizeNetPage();
void TimerEvent();
void UpdateGraphs();
void Reset();
void Refresh();
HWND GetPageWindow()
{
return m_hPage;
}
~CNetPage();
private:
DWORD GraphsPerPage(DWORD dwHeight, DWORD dwAdapterCount);
void SizeGraph(HDWP hdwp, GRAPH *pGraph, RECT *pRect, RECT *pDimRect);
void HideGraph(HDWP hdwp, GRAPH *pGraph);
HRESULT UpdatePage();
void CreatePens();
void ReleasePens();
void CalcNetTime( void );
DWORD DrawGraph(LPRECT prc, HPEN hPen, DWORD dwZoom, ULONG *pHistory, ULONG *pHistory2 = NULL);
HRESULT CreateMemoryBitmaps(int x, int y);
void FreeMemoryBitmaps();
HRESULT Destroy();
void GetTitle(LPTSTR pszText, size_t bufsize);
void ReleaseScaleFont();
void CreateScaleFont(HDC hdc);
ULONG DrawAdapterGraphPaper(HDC hdcGraph, RECT * prcGraph, DWORD dwZoom);
INT DrawScale(HDC hdcGraph, RECT *prcGraph, DWORD dwZoom);
WCHAR * CommaNumber(ULONGLONG ullValue, WCHAR *pwsz, int cchNumber);
WCHAR * SimplifyNumber(ULONGLONG ullValue, WCHAR *psz, DWORD cch);
WCHAR * FloatToString(ULONGLONG ulValue, WCHAR *psz, DWORD cch, BOOLEAN bDisplayDecimal = FALSE);
private:
CAdapter m_Adapter;
HWND m_hPage; // Handle to this page's dlg
HWND m_hwndTabs; // Parent window
HDC m_hdcGraph; // Inmemory dc for cpu hist
HBITMAP m_hbmpGraph; // Inmemory bmp for cpu hist
HGDIOBJ m_hOldObject; // Previous object in m_hdcGraph
HPEN m_hPens[3]; // Our box of crayons
RECT m_rcGraph;
BOOL m_bReset;
BOOL m_bPageActive; // Tells the class if the Network tab is active (i.e. the user is looking at it)
// If the tab is not active we will not collect network data unless the user selects
// the menu option to do so. (We same some CPU usage then. .
HFONT m_hScaleFont;
LONG m_lScaleFontHeight;
LONG m_lScaleWidth;
private:
HRESULT CreateGraphs(DWORD dwGraphsRequired);
void DestroyGraphs();
DWORD GetFirstVisibleAdapter();
void LabelGraphs();
private:
PGRAPH m_pGraph;
DWORD m_dwGraphCount;
DWORD m_dwFirstVisibleAdapter;
DWORD m_dwGraphsPerPage;
HWND m_hScrollBar;
HWND m_hListView;
HWND m_hNoAdapterText;
};
// CPerfPage
//
// Class describing the performance page
class CPerfPage : public CPage
{
HWND m_hPage; // Handle to this page's dlg
HWND m_hwndTabs; // Parent window
HBITMAP m_hDigits; // Digits bitmap
HBITMAP m_hStripUnlit; // Digits bitmap
HBITMAP m_hStripLitRed; // Digits bitmap
HBITMAP m_hStripLit; // Digits bitmap
HDC m_hdcGraph; // Inmemory dc for cpu hist
HBITMAP m_hbmpGraph; // Inmemory bmp for cpu hist
HGDIOBJ m_hObjOld; // Original object
HPEN m_hPens[NUM_PENS]; // Our box of crayons
RECT m_rcGraph;
public:
CPerfPage()
{
ZeroMemory((LPVOID) m_hPens, sizeof(m_hPens));
}
virtual ~CPerfPage()
{
};
HRESULT Initialize(HWND hwndParent);
HRESULT Activate();
void Deactivate();
HRESULT Destroy();
void GetTitle(LPTSTR pszText, size_t bufsize);
void SizePerfPage();
void TimerEvent();
HWND GetPageWindow()
{
return m_hPage;
}
void DrawCPUGraph(LPDRAWITEMSTRUCT lpdi, UINT iPane);
void DrawMEMGraph(LPDRAWITEMSTRUCT lpdi);
void DrawCPUDigits(LPDRAWITEMSTRUCT lpdi);
void DrawMEMMeter(LPDRAWITEMSTRUCT lpdi);
void UpdateCPUHistory();
void FreeMemoryBitmaps();
HRESULT CreateMemoryBitmaps(int x, int y);
void SetTimer(HWND hwnd, UINT milliseconds);
void CreatePens();
void ReleasePens();
void UpdateGraphs();
};
// CSysInfo
//
// Some misc global info about the system
class CSysInfo
{
public:
// These fields MUST all be DWORDS because we manually index into
// them individually in procperf.cpp
DWORD m_cHandles;
DWORD m_cThreads;
DWORD m_cProcesses;
DWORD m_dwPhysicalMemory;
DWORD m_dwPhysAvail;
DWORD m_dwFileCache;
DWORD m_dwKernelPaged;
DWORD m_dwKernelNP;
DWORD m_dwKernelTotal;
DWORD m_dwCommitTotal;
DWORD m_dwCommitLimit;
DWORD m_dwCommitPeak;
CSysInfo()
{
ZeroMemory(this, sizeof(CSysInfo));
}
};
// CProcessPage
//
// Class describing the process list page
class CPtrArray; // Forward reference
class CProcInfo;
class CProcPage : public CPage
{
friend BOOL WINAPI WowTaskCallback(
DWORD dwThreadId,
WORD hMod16,
WORD hTask16,
CHAR *pszModName,
CHAR *pszFileName,
LPARAM lparam
);
HWND m_hPage; // Handle to this page's dlg
HWND m_hwndTabs; // Parent window
CPtrArray * m_pProcArray; // Ptr array of running processes
LPVOID m_pvBuffer; // Buffer for NtQuerySystemInfo
size_t m_cbBuffer; // Size of the above buffer, in bytes
CSysInfo m_SysInfo;
BOOL m_fPaused; // Updates paused (during trackpopupmenu)
LPTSTR m_pszDebugger; // Debugger command in registry
public:
HRESULT Initialize(HWND hwndParent);
HRESULT Activate();
void Deactivate();
HRESULT Destroy();
void GetTitle(LPTSTR pszText, size_t bufsize);
void TimerEvent();
HWND GetPageWindow() { return m_hPage; };
void PickColumns();
void SaveColumnWidths();
void SizeProcPage();
HRESULT SetupColumns();
HRESULT UpdateProcInfoArray();
HRESULT UpdateProcListview();
HRESULT GetProcessInfo();
INT HandleProcPageNotify(LPNMHDR);
void HandleProcListContextMenu(INT xPos, INT yPos);
CProcInfo * GetSelectedProcess();
void HandleWMCOMMAND( WORD , HWND );
BOOL IsSystemProcess(DWORD pid, CProcInfo * pProcInfo);
BOOL KillProcess(DWORD pid, BOOL bBatch = FALSE);
BOOL KillAllChildren(DWORD dwTaskPid, DWORD pid, BYTE* pbBuffer, __int64 CreateTime);
BOOL SetPriority(CProcInfo * pProc, DWORD idCmd);
BOOL AttachDebugger(DWORD pid);
UINT QuickConfirm(UINT idTitle, UINT idBody);
BOOL SetAffinity(DWORD pid);
typedef struct _TASK_LIST
{
DWORD dwProcessId;
DWORD dwInheritedFromProcessId;
unsigned __int64 CreateTime;
BOOL flags;
} TASK_LIST, *PTASK_LIST;
BOOL RecursiveKill(DWORD pid);
BYTE* GetTaskListEx();
// Constructor
CProcPage()
{
m_hPage = NULL;
m_hwndTabs = NULL;
m_pProcArray = NULL;
m_pvBuffer = NULL;
m_cbBuffer = 0;
m_fPaused = FALSE;
m_pszDebugger = NULL;
}
virtual ~CProcPage();
// The dialog proc needs to be able to set the m_hPage member, so
// make it a friend
friend INT_PTR CALLBACK ProcPageProc(
HWND hwnd, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
// The WOW task callback proc needs to be able to get m_pProcArray,
// so make it a friend.
friend BOOL WINAPI WowTaskCallback(
DWORD dwThreadId,
WORD hTask16,
PSZ pszFileName,
LPARAM lparam
);
private:
void Int64ToCommaSepString(LONGLONG n, LPTSTR pszOut, int cchOut);
void Int64ToCommaSepKString(LONGLONG n, LPTSTR pszOut, int cchOut);
void RememberColumnOrder(HWND hwndList);
void RestoreColumnOrder(HWND hwndList);
};
class TASK_LIST_ENUM; // Forward ref
// THREADPARAM
//
// Uses as a communication struct between task page and its worker thread
class THREADPARAM
{
public:
WINSTAENUMPROC m_lpEnumFunc;
LPARAM m_lParam;
HANDLE m_hEventChild;
HANDLE m_hEventParent;
BOOL m_fThreadExit;
BOOL m_fSuccess;
THREADPARAM()
{
ZeroMemory(this, sizeof(THREADPARAM));
}
};
// CTaskPage
//
// Class describing the task manager page
class CTaskPage : public CPage
{
private:
HWND m_hPage; // Handle to this page's dlg
HWND m_hwndTabs; // Parent window
CPtrArray * m_pTaskArray; // Array of active tasks
BOOL m_fPaused; // BOOL, is display refresh paused for menu
HIMAGELIST m_himlSmall; // Image lists
HIMAGELIST m_himlLarge;
VIEWMODE m_vmViewMode; // Large or small icon mode
UINT m_cSelected; // Count of items selected
THREADPARAM m_tp;
HANDLE m_hEventChild;
HANDLE m_hEventParent;
HANDLE m_hThread;
typedef struct _open_failures_
{
WCHAR *_pszWindowStationName;
WCHAR *_pszDesktopName;
struct _open_failures_ *_pofNext;
} OPEN_FAILURE, *LPOPEN_FAILURE;
OPEN_FAILURE *m_pofFailures;
protected:
void RemoveAllTasks();
HRESULT LoadDefaultIcons();
public:
CTaskPage()
{
m_hPage = NULL;
m_hwndTabs = NULL;
m_fPaused = FALSE;
m_pTaskArray = NULL;
m_himlSmall = NULL;
m_himlLarge = NULL;
m_hEventChild = NULL;
m_hEventParent = NULL;
m_hThread = NULL;
m_vmViewMode = g_Options.m_vmViewMode;
m_cSelected = 0;
m_pofFailures = NULL;
}
virtual ~CTaskPage();
HRESULT Initialize(HWND hwndParent);
HRESULT Activate();
void Deactivate();
HRESULT Destroy();
void GetTitle(LPTSTR pszText, size_t bufsize);
void TimerEvent();
HWND GetPageWindow() { return m_hPage; };
void SizeTaskPage();
HRESULT SetupColumns();
void GetRunningTasks(TASK_LIST_ENUM * te);
void HandleWMCOMMAND(INT id);
HRESULT UpdateTaskListview();
INT HandleTaskPageNotify(LPNMHDR pnmhdr);
void HandleTaskListContextMenu(INT xPos, INT yPos);
BOOL CreateNewDesktop();
void * GetSelectedTasks();
void UpdateUIState();
HWND * GetHWNDS(BOOL fSelectedOnly, DWORD * pdwCount);
void EnsureWindowsNotMinimized(HWND aHwnds[], DWORD dwCount);
BOOL HasAlreadyOpenFailed(WCHAR *pszWindowStationName, WCHAR *pszDesktopName);
void SetOpenFailed(WCHAR *pszWindowStationName, WCHAR *pszDesktopName);
void FreeOpenFailures(void);
BOOL DoEnumWindowStations(WINSTAENUMPROC lpEnumFunc, LPARAM lParam);
void OnSettingsChange();
void Pause() { m_fPaused = TRUE; };
void Unpause() { m_fPaused = FALSE; };
// The dialog proc needs to be able to set the m_hPage member, so
// make it a friend
friend INT_PTR CALLBACK TaskPageProc(
HWND hwnd, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
// The enum callback needs to get at our imagelists as it encounters
// new tasls, so it can add their icons to the lists
friend BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
};
// TASK_LIST_ENUM
//
// Object passed around during window enumeration
class TASK_LIST_ENUM
{
public:
CPtrArray * m_pTasks;
LPWSTR lpWinsta;
LPWSTR lpDesk;
__int64 uPassCount;
CTaskPage * m_pPage;
TASK_LIST_ENUM()
{
ZeroMemory(this, sizeof(TASK_LIST_ENUM));
}
};
typedef TASK_LIST_ENUM *PTASK_LIST_ENUM;
// CUserPage
//
// Class describing the task manager page
class CUserPage : public CPage
{
private:
HWND m_hPage; // Handle to this page's dlg
HWND m_hwndTabs; // Parent window
CPtrArray * m_pUserArray; // Array of active users
BOOL m_fPaused; // BOOL, is display refresh paused for menu
UINT m_cSelected; // Count of items selected
HIMAGELIST m_himlUsers; // Image list for user icons
UINT m_iUserIcon;
UINT m_iCurrentUserIcon;
THREADPARAM m_tp;
HANDLE m_hEventChild;
HANDLE m_hEventParent;
HANDLE m_hThread;
protected:
void RemoveAllUsers();
HRESULT LoadDefaultIcons();
public:
CUserPage()
{
m_hPage = NULL;
m_hwndTabs = NULL;
m_fPaused = FALSE;
m_pUserArray = NULL;
m_hEventChild = NULL;
m_hEventParent = NULL;
m_hThread = NULL;
m_cSelected = 0;
m_himlUsers = NULL;
m_iUserIcon = 0;
m_iCurrentUserIcon = 0;
}
virtual ~CUserPage();
HRESULT Initialize(HWND hwndParent);
HRESULT Activate();
void Deactivate();
HRESULT Destroy();
void GetTitle(LPTSTR pszText, size_t bufsize);
void TimerEvent();
void OnInitDialog(HWND hPage);
HWND GetPageWindow() { return m_hPage; };
void SizeUserPage();
HRESULT SetupColumns();
void GetRunningUsers(TASK_LIST_ENUM * te);
void HandleWMCOMMAND(INT id);
HRESULT UpdateUserListview();
INT HandleUserPageNotify(LPNMHDR pnmhdr);
void HandleUserListContextMenu(INT xPos, INT yPos);
CPtrArray * GetSelectedUsers();
void UpdateUIState();
HWND * GetHWNDS(BOOL fSelectedOnly, DWORD * pdwCount);
void EnsureWindowsNotMinimized(HWND aHwnds[], DWORD dwCount);
BOOL DoEnumWindowStations(WINSTAENUMPROC lpEnumFunc, LPARAM lParam);
void OnSettingsChange();
void Pause() { m_fPaused = TRUE; };
void Unpause() { m_fPaused = FALSE; };
};
INT_PTR CALLBACK UserPageProc(
HWND hwnd, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);