Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

667 lines
20 KiB

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