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.

324 lines
7.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // TaskMan - NT TaskManager
  4. // Copyright (C) Microsoft
  5. //
  6. // File: Precomp.H
  7. //
  8. // History: Nov-10-95 DavePl Created
  9. //
  10. //--------------------------------------------------------------------------
  11. //
  12. // Warnings turned off to appease our header files
  13. //
  14. #pragma warning(disable:4201) // Nameless struct or union
  15. #pragma warning(disable:4100) // Unreferenced formal parameter
  16. #pragma warning(disable:4514) // Unreferenced inline func removed
  17. #pragma warning(disable:4127) // Conditional expression is constant
  18. #pragma warning(disable:4121) // alignment of a member was sensitive to packing
  19. #define STRICT
  20. #ifndef UNICODE
  21. #define UNICODE
  22. #endif
  23. #ifndef _UNICODE
  24. #define _UNICODE
  25. #endif
  26. extern "C"
  27. {
  28. #include <nt.h>
  29. #include <ntrtl.h>
  30. #include <nturtl.h>
  31. #include <ntexapi.h>
  32. }
  33. #include <windows.h>
  34. #include <windowsx.h>
  35. #include <Iphlpapi.h>
  36. #pragma warning(disable:4201) // Nameless struct or union
  37. #include <objbase.h>
  38. #include <winuserp.h>
  39. #include <commctrl.h>
  40. #include <comctrlp.h>
  41. #include <shlobj.h>
  42. #include <shlobjp.h>
  43. #include <shlwapi.h>
  44. #include <shlwapip.h>
  45. #include <shlapip.h>
  46. #include <vdmdbg.h>
  47. #include <ccstock.h>
  48. #include <wtsapi32.h>
  49. #include <hydrix.h> // internal hydra defines
  50. #include <msginaexports.h>
  51. #ifndef ARRAYSIZE
  52. #define ARRAYSIZE(x) ((sizeof(x) / sizeof(x[0])))
  53. #endif
  54. //
  55. // Global data externs
  56. //
  57. #define PWM_TRAYICON WM_USER + 10
  58. #define PWM_ACTIVATE WM_USER + 11
  59. #define DEFSPACING_BASE 3
  60. #define INNERSPACING_BASE 2
  61. #define TOPSPACING_BASE 10
  62. extern long g_DefSpacing;
  63. extern long g_InnerSpacing;
  64. extern long g_TopSpacing;
  65. #define MAX_NETWORKCARDS 32 // Maximum number of Network cards (i.e. max number of network graphs)
  66. #define MAX_PROCESSOR 32
  67. #define HIST_SIZE 2000 // Number of data points to track
  68. // in the history windows
  69. extern HINSTANCE g_hInstance;
  70. extern HWND g_hMainWnd;
  71. extern HDESK g_hMainDesktop;
  72. extern DWORD g_cTasks;
  73. extern DWORD g_cProcesses;
  74. extern BYTE g_cProcessors;
  75. extern BYTE g_CPUUsage;
  76. extern __int64 g_MEMUsage;
  77. extern __int64 g_MEMMax;
  78. extern HMENU g_hMenu;
  79. extern BYTE g_CPUUsage;
  80. extern BYTE * g_pCPUHistory[MAX_PROCESSOR];
  81. extern BYTE * g_pKernelHistory[MAX_PROCESSOR];
  82. extern BOOL g_fInPopup;
  83. extern TCHAR g_szK[];
  84. extern TCHAR g_szRealtime[];
  85. extern TCHAR g_szNormal[];
  86. extern TCHAR g_szHigh[];
  87. extern TCHAR g_szLow[];
  88. extern TCHAR g_szUnknown[];
  89. extern TCHAR g_szAboveNormal[];
  90. extern TCHAR g_szBelowNormal[];
  91. extern TCHAR g_szHung[];
  92. extern TCHAR g_szRunning[];
  93. extern TCHAR g_szfmtCPUNum[];
  94. extern TCHAR g_szfmtCPU[];
  95. extern TCHAR g_szTotalCPU[];
  96. extern TCHAR g_szKernelCPU[];
  97. extern TCHAR g_szMemUsage[];
  98. extern HICON g_aTrayIcons[];
  99. extern UINT g_cTrayIcons;
  100. class COptions;
  101. extern COptions g_Options;
  102. //
  103. // Prototypes
  104. //
  105. BYTE InitNetInfo(); // netpage.cpp
  106. void CalcCpuTime(BOOL); // perfpage.cpp
  107. BYTE InitPerfInfo(); // perfpage.cpp
  108. void ReleasePerfInfo(); // perfpage.cpp
  109. void DisplayFailureMsg(HWND hWnd, UINT idTitle, DWORD dwError); // main.cpp
  110. BOOL CreateNewDesktop(); // main.cpp
  111. void ShowRunningInstance();
  112. HMENU LoadPopupMenu(HINSTANCE hinst, UINT id); // main.cpp
  113. BOOL CheckParentDeferrals(UINT uMsg, WPARAM wParam, LPARAM lParam);
  114. void Tray_Notify(HWND hWnd, WPARAM wParam, LPARAM lParam);
  115. void UpdateTrayIcon(HWND hWnd);
  116. #include "taskmgr.h"
  117. #include "resource.h"
  118. #include "pages.h"
  119. #include "ptrarray.h"
  120. /*++ ShiftArrayWorker
  121. Routine Description:
  122. Shifts a section of an array up or down. If shifting
  123. down, the given element is lost. For up, an empty slot
  124. (with an undefined value) is opened.
  125. Arguments:
  126. pArray - Array starting address
  127. cbArraySize - Size of Array (in BYTES)
  128. cElementSize - Size of array elements
  129. iFirstElement - First element to move
  130. Direction - SHIFT_UP or SHIFT_DOWN
  131. Return Value:
  132. None. No error checking either. Should compile out to
  133. a movememory
  134. Notes:
  135. Call this with the ShiftArray macro which does the size
  136. calcs for you
  137. Revision History:
  138. Jan-26-95 Davepl Created
  139. --*/
  140. #define ShiftArray(array, index, direction) \
  141. \
  142. ShiftArrayWorker((LPBYTE) array, sizeof(array), sizeof(array[0]), index, direction)
  143. typedef enum SHIFT_DIRECTION { SHIFT_UP, SHIFT_DOWN };
  144. static inline void ShiftArrayWorker(const LPBYTE pArray,
  145. const size_t cbArraySize,
  146. const size_t cElementSize,
  147. const UINT iFirstElement,
  148. const SHIFT_DIRECTION Direction)
  149. {
  150. ASSERT( ((cbArraySize / cElementSize) * cElementSize) == cbArraySize);
  151. ASSERT( (iFirstElement + 1) * cElementSize <= cbArraySize );
  152. const LPBYTE pFirst = pArray + (iFirstElement * cElementSize);
  153. const LPBYTE pLast = pArray + cbArraySize - cElementSize;
  154. const UINT cBytesToMove = (UINT)(pLast - pFirst);
  155. ASSERT (pLast >= pFirst);
  156. if (cBytesToMove)
  157. {
  158. if (SHIFT_DOWN == Direction)
  159. {
  160. CopyMemory(pFirst, pFirst + cElementSize, cBytesToMove);
  161. }
  162. else
  163. {
  164. ASSERT(Direction == SHIFT_UP);
  165. CopyMemory(pFirst + cElementSize, pFirst, cBytesToMove);
  166. }
  167. }
  168. }
  169. //+----------------------------------------------------------------------------
  170. //
  171. // Member: dprintf
  172. //
  173. // Synopsis: Dumps a printf style string to the debugger.
  174. //
  175. // Notes:
  176. //
  177. // History: 2-07-95 davepl Created
  178. //
  179. //-----------------------------------------------------------------------------
  180. #if DBG
  181. #define DEBUG 1
  182. #endif
  183. #ifdef DEBUG
  184. inline int dprintf(LPCTSTR szFormat, ...)
  185. {
  186. TCHAR szBuffer[MAX_PATH];
  187. va_list vaList;
  188. va_start(vaList, szFormat);
  189. int retval = wvsprintf(szBuffer, szFormat, vaList);
  190. OutputDebugString(szBuffer);
  191. va_end (vaList);
  192. return retval;
  193. }
  194. #else
  195. inline int dprintf(LPCTSTR, ...)
  196. {
  197. return 0;
  198. }
  199. #endif
  200. //////////////////////////////////////////////////////////////////////////////
  201. //
  202. // MACRO
  203. // DEBUG_BREAK
  204. //
  205. // Description:
  206. // Because the system expection handler can hick-up over INT 3s and
  207. // DebugBreak()s, This x86 only macro causes the program to break in the
  208. // right spot.
  209. //
  210. //////////////////////////////////////////////////////////////////////////////
  211. #if defined( _X86_ )
  212. #define DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while (0)
  213. #else
  214. #define DEBUG_BREAK DebugBreak()
  215. #endif
  216. //
  217. // Assert
  218. //
  219. #ifdef Assert
  220. #undef Assert
  221. #endif
  222. #ifdef DEBUG
  223. #define Assert(x) \
  224. do \
  225. { \
  226. if ( !(x) ) \
  227. { \
  228. dprintf( TEXT(__FILE__) TEXT("(%d): Assertion '") TEXT( #x ) TEXT("' failed.\n"), __LINE__ ); \
  229. DEBUG_BREAK; \
  230. } \
  231. } while (0)
  232. #else
  233. #define Assert(x)
  234. #endif
  235. //
  236. // Verify
  237. //
  238. #if DEBUG
  239. #define VERIFY(x) Assert(x)
  240. #else
  241. #define VERIFY(x) (x)
  242. #endif
  243. #ifdef ASSERT
  244. #undef ASSERT
  245. #endif
  246. #define ASSERT(x) Assert(x)
  247. extern const TCHAR szTaskmanKey[];
  248. #pragma hdrstop