Leaked source code of windows server 2003
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.

644 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. } GRAPH, *PGRAPH;
  43. enum ADAPTER_HISTORY
  44. {
  45. BYTES_SENT_UTIL = 0,
  46. BYTES_RECEIVED_UTIL = 1
  47. };
  48. extern "C" {
  49. //
  50. // IPHLPAPI does not have this function defines in the header file.
  51. //
  52. DWORD
  53. NhGetInterfaceNameFromDeviceGuid(
  54. IN GUID *pGuid,
  55. OUT PWCHAR pwszBuffer,
  56. IN OUT PULONG pulBufferSize,
  57. IN BOOL bCache,
  58. IN BOOL bRefresh
  59. );
  60. }
  61. #define MAX_ADAPTERS 32
  62. #define GUID_STR_LENGTH 38
  63. typedef struct tagADAPTER_INFOEX
  64. {
  65. MIB_IFROW ifRowStartStats;
  66. MIB_IFROW ifRowStats[2];
  67. ULONG ulHistory[2][HIST_SIZE];
  68. ULONGLONG ullLinkspeed;
  69. BOOLEAN bAdjustLinkSpeed;
  70. WCHAR wszDesc[MAXLEN_IFDESCR];
  71. WCHAR wszConnectionName[MAXLEN_IFDESCR];
  72. WCHAR wszGuid[GUID_STR_LENGTH + 1];
  73. ULONGLONG ullLastTickCount;
  74. ULONGLONG ullTickCountDiff;
  75. DWORD dwScale;
  76. } ADAPTER_INFOEX, *PADAPTER_INFOEX, **PPADAPTER_INFOEX;
  77. class CAdapter
  78. {
  79. public:
  80. CAdapter();
  81. HRESULT Update(BOOLEAN & bAdapterListChange);
  82. LPWSTR GetAdapterText(DWORD dwAdapter, NETCOLUMNID nStatValue);
  83. ULONGLONG GetAdapterStat(DWORD dwAdapter, NETCOLUMNID nStatValue, BOOL bAccumulative = FALSE);
  84. HRESULT Reset();
  85. ULONG *GetAdapterHistory(DWORD dwAdapter, ADAPTER_HISTORY nHistoryType);
  86. DWORD GetScale(DWORD dwAdapter);
  87. void SetScale(DWORD dwAdapter, DWORD dwScale);
  88. void RefreshConnectionNames();
  89. DWORD GetNumberOfAdapters();
  90. ~CAdapter();
  91. private:
  92. HRESULT RefreshAdapterTable();
  93. HRESULT InitializeAdapter(PPADAPTER_INFOEX ppaiAdapterStats, PIP_ADAPTER_INDEX_MAP pAdapterDescription);
  94. void AdjustLinkSpeed(PADAPTER_INFOEX pAdapterInfo);
  95. HRESULT GetConnectionName(LPWSTR pwszAdapterGuid, LPWSTR pwszConnectionName, DWORD cchConnectionName );
  96. BOOLEAN AdvanceAdapterHistory(DWORD dwAdapter);
  97. private:
  98. PIP_INTERFACE_INFO m_pifTable;
  99. PPADAPTER_INFOEX m_ppaiAdapterStats;
  100. DWORD m_dwAdapterCount;
  101. BOOLEAN m_bToggle;
  102. DWORD m_dwLastReportedNumberOfAdapters;
  103. };
  104. // CNetworkPage
  105. //
  106. // Class describing the network page
  107. //
  108. class CNetPage : public CPage
  109. {
  110. public:
  111. CNetPage();
  112. HRESULT Initialize(HWND hwndParent);
  113. DWORD GetNumberOfGraphs();
  114. HRESULT SetupColumns();
  115. void ScrollGraphs(WPARAM wParam);
  116. void SaveColumnWidths();
  117. void RememberColumnOrder(HWND hwndList);
  118. void RestoreColumnOrder(HWND hwndList);
  119. void PickColumns();
  120. HRESULT Activate();
  121. void Deactivate();
  122. void DrawAdapterGraph(LPDRAWITEMSTRUCT lpdi, UINT iPane);
  123. void SizeNetPage();
  124. void TimerEvent();
  125. void UpdateGraphs();
  126. void Reset();
  127. void Refresh();
  128. HWND GetPageWindow()
  129. {
  130. return m_hPage;
  131. }
  132. ~CNetPage();
  133. private:
  134. DWORD GraphsPerPage(DWORD dwHeight, DWORD dwAdapterCount);
  135. void SizeGraph(HDWP hdwp, GRAPH *pGraph, RECT *pRect, RECT *pDimRect);
  136. void HideGraph(HDWP hdwp, GRAPH *pGraph);
  137. HRESULT UpdatePage();
  138. void CreatePens();
  139. void ReleasePens();
  140. void CalcNetTime( void );
  141. DWORD DrawGraph(LPRECT prc, HPEN hPen, DWORD dwZoom, ULONG *pHistory, ULONG *pHistory2 = NULL);
  142. HRESULT CreateMemoryBitmaps(int x, int y);
  143. void FreeMemoryBitmaps();
  144. HRESULT Destroy();
  145. void GetTitle(LPTSTR pszText, size_t bufsize);
  146. void ReleaseScaleFont();
  147. void CreateScaleFont(HDC hdc);
  148. ULONG DrawAdapterGraphPaper(HDC hdcGraph, RECT * prcGraph, DWORD dwZoom);
  149. INT DrawScale(HDC hdcGraph, RECT *prcGraph, DWORD dwZoom);
  150. WCHAR * CommaNumber(ULONGLONG ullValue, WCHAR *pwsz, int cchNumber);
  151. WCHAR * SimplifyNumber(ULONGLONG ullValue, WCHAR *psz, DWORD cch);
  152. WCHAR * FloatToString(ULONGLONG ulValue, WCHAR *psz, DWORD cch, BOOLEAN bDisplayDecimal = FALSE);
  153. private:
  154. CAdapter m_Adapter;
  155. HWND m_hPage; // Handle to this page's dlg
  156. HWND m_hwndTabs; // Parent window
  157. HDC m_hdcGraph; // Inmemory dc for cpu hist
  158. HBITMAP m_hbmpGraph; // Inmemory bmp for cpu hist
  159. HGDIOBJ m_hOldObject; // Previous object in m_hdcGraph
  160. HPEN m_hPens[3]; // Our box of crayons
  161. RECT m_rcGraph;
  162. BOOL m_bReset;
  163. BOOL m_bPageActive; // Tells the class if the Network tab is active (i.e. the user is looking at it)
  164. // If the tab is not active we will not collect network data unless the user selects
  165. // the menu option to do so. (We same some CPU usage then. .
  166. HFONT m_hScaleFont;
  167. LONG m_lScaleFontHeight;
  168. LONG m_lScaleWidth;
  169. private:
  170. HRESULT CreateGraphs(DWORD dwGraphsRequired);
  171. void DestroyGraphs();
  172. DWORD GetFirstVisibleAdapter();
  173. void LabelGraphs();
  174. private:
  175. PGRAPH m_pGraph;
  176. DWORD m_dwGraphCount;
  177. DWORD m_dwFirstVisibleAdapter;
  178. DWORD m_dwGraphsPerPage;
  179. HWND m_hScrollBar;
  180. HWND m_hListView;
  181. HWND m_hNoAdapterText;
  182. };
  183. // CPerfPage
  184. //
  185. // Class describing the performance page
  186. class CPerfPage : public CPage
  187. {
  188. HWND m_hPage; // Handle to this page's dlg
  189. HWND m_hwndTabs; // Parent window
  190. HBITMAP m_hStripUnlit; // Digits bitmap
  191. HBITMAP m_hStripLitRed; // Digits bitmap
  192. HBITMAP m_hStripLit; // Digits bitmap
  193. HDC m_hdcGraph; // Inmemory dc for cpu hist
  194. HBITMAP m_hbmpGraph; // Inmemory bmp for cpu hist
  195. HGDIOBJ m_hObjOld; // Original object
  196. HPEN m_hPens[NUM_PENS]; // Our box of crayons
  197. RECT m_rcGraph;
  198. public:
  199. CPerfPage()
  200. {
  201. ZeroMemory((LPVOID) m_hPens, sizeof(m_hPens));
  202. }
  203. virtual ~CPerfPage()
  204. {
  205. };
  206. HRESULT Initialize(HWND hwndParent);
  207. HRESULT Activate();
  208. void Deactivate();
  209. HRESULT Destroy();
  210. void GetTitle(LPTSTR pszText, size_t bufsize);
  211. void SizePerfPage();
  212. void TimerEvent();
  213. HWND GetPageWindow()
  214. {
  215. return m_hPage;
  216. }
  217. void DrawCPUGraph(LPDRAWITEMSTRUCT lpdi, UINT iPane);
  218. void DrawMEMGraph(LPDRAWITEMSTRUCT lpdi);
  219. void DrawCPUDigits(LPDRAWITEMSTRUCT lpdi);
  220. void DrawMEMMeter(LPDRAWITEMSTRUCT lpdi);
  221. void UpdateCPUHistory();
  222. void FreeMemoryBitmaps();
  223. HRESULT CreateMemoryBitmaps(int x, int y);
  224. void SetTimer(HWND hwnd, UINT milliseconds);
  225. void CreatePens();
  226. void ReleasePens();
  227. void UpdateGraphs();
  228. };
  229. // CSysInfo
  230. //
  231. // Some misc global info about the system
  232. class CSysInfo
  233. {
  234. public:
  235. // These fields MUST all be DWORDS because we manually index into
  236. // them individually in procperf.cpp
  237. DWORD m_cHandles;
  238. DWORD m_cThreads;
  239. DWORD m_cProcesses;
  240. DWORD m_dwPhysicalMemory;
  241. DWORD m_dwPhysAvail;
  242. DWORD m_dwFileCache;
  243. DWORD m_dwKernelPaged;
  244. DWORD m_dwKernelNP;
  245. DWORD m_dwKernelTotal;
  246. DWORD m_dwCommitTotal;
  247. DWORD m_dwCommitLimit;
  248. DWORD m_dwCommitPeak;
  249. CSysInfo()
  250. {
  251. ZeroMemory(this, sizeof(CSysInfo));
  252. }
  253. };
  254. // CProcessPage
  255. //
  256. // Class describing the process list page
  257. class CPtrArray; // Forward reference
  258. class CProcInfo;
  259. class CProcPage : public CPage
  260. {
  261. friend BOOL WINAPI WowTaskCallback(
  262. DWORD dwThreadId,
  263. WORD hMod16,
  264. WORD hTask16,
  265. CHAR *pszModName,
  266. CHAR *pszFileName,
  267. LPARAM lparam
  268. );
  269. HWND m_hPage; // Handle to this page's dlg
  270. HWND m_hwndTabs; // Parent window
  271. CPtrArray * m_pProcArray; // Ptr array of running processes
  272. LPVOID m_pvBuffer; // Buffer for NtQuerySystemInfo
  273. size_t m_cbBuffer; // Size of the above buffer, in bytes
  274. CSysInfo m_SysInfo;
  275. BOOL m_fPaused; // Updates paused (during trackpopupmenu)
  276. LPTSTR m_pszDebugger; // Debugger command in registry
  277. public:
  278. HRESULT Initialize(HWND hwndParent);
  279. HRESULT Activate();
  280. void Deactivate();
  281. HRESULT Destroy();
  282. void GetTitle(LPTSTR pszText, size_t bufsize);
  283. void TimerEvent();
  284. HWND GetPageWindow() { return m_hPage; };
  285. void PickColumns();
  286. void SaveColumnWidths();
  287. void SizeProcPage();
  288. HRESULT SetupColumns();
  289. HRESULT UpdateProcInfoArray();
  290. HRESULT UpdateProcListview();
  291. HRESULT GetProcessInfo();
  292. INT HandleProcPageNotify(LPNMHDR);
  293. void HandleProcListContextMenu(INT xPos, INT yPos);
  294. CProcInfo * GetSelectedProcess();
  295. void HandleWMCOMMAND( WORD , HWND );
  296. BOOL IsSystemProcess(DWORD pid, CProcInfo * pProcInfo);
  297. BOOL KillProcess(DWORD pid, BOOL bBatch = FALSE);
  298. BOOL KillAllChildren(DWORD dwTaskPid, DWORD pid, BYTE* pbBuffer, LARGE_INTEGER CreateTime);
  299. BOOL SetPriority(CProcInfo * pProc, DWORD idCmd);
  300. BOOL AttachDebugger(DWORD pid);
  301. UINT QuickConfirm(UINT idTitle, UINT idBody);
  302. BOOL SetAffinity(DWORD pid);
  303. typedef struct _TASK_LIST
  304. {
  305. DWORD dwProcessId;
  306. DWORD dwInheritedFromProcessId;
  307. ULARGE_INTEGER CreateTime;
  308. BOOL flags;
  309. } TASK_LIST, *PTASK_LIST;
  310. BOOL RecursiveKill(DWORD pid);
  311. BYTE* GetTaskListEx();
  312. // Constructor
  313. CProcPage()
  314. {
  315. m_hPage = NULL;
  316. m_hwndTabs = NULL;
  317. m_pProcArray = NULL;
  318. m_pvBuffer = NULL;
  319. m_cbBuffer = 0;
  320. m_fPaused = FALSE;
  321. m_pszDebugger = NULL;
  322. }
  323. virtual ~CProcPage();
  324. // The dialog proc needs to be able to set the m_hPage member, so
  325. // make it a friend
  326. friend INT_PTR CALLBACK ProcPageProc(
  327. HWND hwnd, // handle to dialog box
  328. UINT uMsg, // message
  329. WPARAM wParam, // first message parameter
  330. LPARAM lParam // second message parameter
  331. );
  332. // The WOW task callback proc needs to be able to get m_pProcArray,
  333. // so make it a friend.
  334. friend BOOL WINAPI WowTaskCallback(
  335. DWORD dwThreadId,
  336. WORD hTask16,
  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. WCHAR *_pszWindowStationName;
  385. WCHAR *_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() { return m_hPage; };
  416. void SizeTaskPage();
  417. HRESULT SetupColumns();
  418. void GetRunningTasks(TASK_LIST_ENUM * te);
  419. void HandleWMCOMMAND(INT id);
  420. HRESULT UpdateTaskListview();
  421. INT HandleTaskPageNotify(LPNMHDR pnmhdr);
  422. void HandleTaskListContextMenu(INT xPos, INT yPos);
  423. BOOL CreateNewDesktop();
  424. CPtrArray * GetSelectedTasks();
  425. void UpdateUIState();
  426. HWND * GetHWNDS(BOOL fSelectedOnly, DWORD * pdwCount);
  427. void EnsureWindowsNotMinimized(HWND aHwnds[], DWORD dwCount);
  428. BOOL HasAlreadyOpenFailed(WCHAR *pszWindowStationName, WCHAR *pszDesktopName);
  429. void SetOpenFailed(WCHAR *pszWindowStationName, WCHAR *pszDesktopName);
  430. void FreeOpenFailures(void);
  431. BOOL DoEnumWindowStations(WINSTAENUMPROC lpEnumFunc, LPARAM lParam);
  432. void OnSettingsChange();
  433. void Pause() { m_fPaused = TRUE; };
  434. void Unpause() { m_fPaused = FALSE; };
  435. // The dialog proc needs to be able to set the m_hPage member, so
  436. // make it a friend
  437. friend INT_PTR CALLBACK TaskPageProc(
  438. HWND hwnd, // handle to dialog box
  439. UINT uMsg, // message
  440. WPARAM wParam, // first message parameter
  441. LPARAM lParam // second message parameter
  442. );
  443. // The enum callback needs to get at our imagelists as it encounters
  444. // new tasls, so it can add their icons to the lists
  445. friend BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
  446. };
  447. // TASK_LIST_ENUM
  448. //
  449. // Object passed around during window enumeration
  450. class TASK_LIST_ENUM
  451. {
  452. public:
  453. CPtrArray * m_pTasks;
  454. LPWSTR lpWinsta;
  455. LPWSTR lpDesk;
  456. LARGE_INTEGER uPassCount;
  457. CTaskPage * m_pPage;
  458. TASK_LIST_ENUM()
  459. {
  460. ZeroMemory(this, sizeof(TASK_LIST_ENUM));
  461. }
  462. };
  463. typedef TASK_LIST_ENUM *PTASK_LIST_ENUM;
  464. // CUserPage
  465. //
  466. // Class describing the task manager page
  467. class CUserPage : public CPage
  468. {
  469. private:
  470. HWND m_hPage; // Handle to this page's dlg
  471. HWND m_hwndTabs; // Parent window
  472. CPtrArray * m_pUserArray; // Array of active users
  473. BOOL m_fPaused; // BOOL, is display refresh paused for menu
  474. UINT m_cSelected; // Count of items selected
  475. HIMAGELIST m_himlUsers; // Image list for user icons
  476. UINT m_iUserIcon;
  477. UINT m_iCurrentUserIcon;
  478. THREADPARAM m_tp;
  479. HANDLE m_hEventChild;
  480. HANDLE m_hEventParent;
  481. HANDLE m_hThread;
  482. protected:
  483. void RemoveAllUsers();
  484. HRESULT LoadDefaultIcons();
  485. public:
  486. CUserPage()
  487. {
  488. m_hPage = NULL;
  489. m_hwndTabs = NULL;
  490. m_fPaused = FALSE;
  491. m_pUserArray = NULL;
  492. m_hEventChild = NULL;
  493. m_hEventParent = NULL;
  494. m_hThread = NULL;
  495. m_cSelected = 0;
  496. m_himlUsers = NULL;
  497. m_iUserIcon = 0;
  498. m_iCurrentUserIcon = 0;
  499. }
  500. virtual ~CUserPage();
  501. HRESULT Initialize(HWND hwndParent);
  502. HRESULT Activate();
  503. void Deactivate();
  504. HRESULT Destroy();
  505. void GetTitle(LPTSTR pszText, size_t bufsize);
  506. void TimerEvent();
  507. void OnInitDialog(HWND hPage);
  508. HWND GetPageWindow() { return m_hPage; };
  509. void SizeUserPage();
  510. HRESULT SetupColumns();
  511. void GetRunningUsers(TASK_LIST_ENUM * te);
  512. void HandleWMCOMMAND(INT id);
  513. HRESULT UpdateUserListview();
  514. INT HandleUserPageNotify(LPNMHDR pnmhdr);
  515. void HandleUserListContextMenu(INT xPos, INT yPos);
  516. CPtrArray * GetSelectedUsers();
  517. void UpdateUIState();
  518. HWND * GetHWNDS(BOOL fSelectedOnly, DWORD * pdwCount);
  519. void EnsureWindowsNotMinimized(HWND aHwnds[], DWORD dwCount);
  520. BOOL DoEnumWindowStations(WINSTAENUMPROC lpEnumFunc, LPARAM lParam);
  521. void OnSettingsChange();
  522. void Pause() { m_fPaused = TRUE; };
  523. void Unpause() { m_fPaused = FALSE; };
  524. };
  525. INT_PTR CALLBACK UserPageProc(
  526. HWND hwnd, // handle to dialog box
  527. UINT uMsg, // message
  528. WPARAM wParam, // first message parameter
  529. LPARAM lParam // second message parameter
  530. );