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.

271 lines
6.6 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:4127) // Conditional expression is constant
  15. #define STRICT
  16. #if DBG
  17. #define DEBUG 1
  18. #endif
  19. #ifndef UNICODE
  20. #define UNICODE
  21. #endif
  22. #ifndef _UNICODE
  23. #define _UNICODE
  24. #endif
  25. extern "C"
  26. {
  27. #include <nt.h>
  28. #include <ntrtl.h>
  29. #include <nturtl.h>
  30. #include <ntexapi.h>
  31. }
  32. #include <windows.h>
  33. #include <windowsx.h>
  34. #include <Iphlpapi.h>
  35. #include <objbase.h>
  36. #include <winuserp.h>
  37. #include <commctrl.h>
  38. #include <comctrlp.h>
  39. #include <shlobj.h>
  40. #include <shlobjp.h>
  41. #include <shlwapi.h>
  42. #include <shlwapip.h>
  43. #include <shlapip.h>
  44. #include <vdmdbg.h>
  45. #include <ccstock.h>
  46. #include <wtsapi32.h>
  47. #include <hydrix.h> // internal hydra defines
  48. #include <msginaexports.h>
  49. #include <strsafe.h>
  50. #include <TokenUtil.h> // CPrivilegeEnable
  51. #include <winsta.h> // WinStationGetProcessSid
  52. #include <utildll.h> // CachedGetUserFromSid
  53. #include <htmlhelp.h>
  54. #include <lmcons.h>
  55. #include <sspi.h>
  56. #include <secext.h> // for GetUserNameEx
  57. #include <security.h>
  58. //
  59. // Global data externs
  60. //
  61. #define PWM_TRAYICON WM_USER + 10
  62. #define PWM_ACTIVATE WM_USER + 11
  63. #define DEFSPACING_BASE 3
  64. #define INNERSPACING_BASE 2
  65. #define TOPSPACING_BASE 10
  66. extern long g_DefSpacing;
  67. extern long g_InnerSpacing;
  68. extern long g_TopSpacing;
  69. #define CONTROL_WIDTH_SPACING 13
  70. #define CONTROL_HEIGHT_SPACING 2
  71. extern long g_ControlWidthSpacing;
  72. extern long g_ControlHeightSpacing;
  73. #define MAX_NETWORKCARDS 32 // Maximum number of Network cards (i.e. max number of network graphs)
  74. #define HIST_SIZE 2000 // Number of data points to track in the history windows
  75. extern HINSTANCE g_hInstance;
  76. extern HWND g_hMainWnd;
  77. extern HDESK g_hMainDesktop;
  78. extern DWORD g_cTasks;
  79. extern DWORD g_cProcesses;
  80. extern BYTE g_cProcessors;
  81. extern BYTE g_CPUUsage;
  82. extern __int64 g_MEMUsage;
  83. extern __int64 g_MEMMax;
  84. extern HMENU g_hMenu;
  85. extern BYTE g_CPUUsage;
  86. extern BYTE * g_pCPUHistory[MAXIMUM_PROCESSORS];
  87. extern BYTE * g_pKernelHistory[MAXIMUM_PROCESSORS];
  88. extern BOOL g_fInPopup;
  89. extern WCHAR g_szK[];
  90. extern WCHAR g_szRealtime[];
  91. extern WCHAR g_szNormal[];
  92. extern WCHAR g_szHigh[];
  93. extern WCHAR g_szLow[];
  94. extern WCHAR g_szUnknown[];
  95. extern WCHAR g_szAboveNormal[];
  96. extern WCHAR g_szBelowNormal[];
  97. extern WCHAR g_szHung[];
  98. extern WCHAR g_szRunning[];
  99. extern WCHAR g_szfmtCPUNum[];
  100. extern WCHAR g_szfmtCPU[];
  101. extern WCHAR g_szTotalCPU[];
  102. extern WCHAR g_szKernelCPU[];
  103. extern WCHAR g_szMemUsage[];
  104. extern HICON g_aTrayIcons[];
  105. extern UINT g_cTrayIcons;
  106. class COptions;
  107. extern COptions g_Options;
  108. //
  109. // Prototypes
  110. //
  111. BYTE InitNetInfo(); // netpage.cpp
  112. void CalcCpuTime(BOOL); // perfpage.cpp
  113. BYTE InitPerfInfo(); // perfpage.cpp
  114. void ReleasePerfInfo(); // perfpage.cpp
  115. void DisplayFailureMsg(HWND hWnd, UINT idTitle, DWORD dwError); // main.cpp
  116. BOOL CreateNewDesktop(); // main.cpp
  117. void ShowRunningInstance();
  118. HMENU LoadPopupMenu(HINSTANCE hinst, UINT id); // main.cpp
  119. BOOL CheckParentDeferrals(UINT uMsg, WPARAM wParam, LPARAM lParam);
  120. void Tray_Notify(HWND hWnd, LPARAM lParam);
  121. void UpdateTrayIcon(HWND hWnd);
  122. #include "taskmgr.h"
  123. #include "resource.h"
  124. #include "pages.h"
  125. #include "ptrarray.h"
  126. /*++ ShiftArrayWorker
  127. Routine Description:
  128. Shifts a section of an array up or down. If shifting
  129. down, the given element is lost. For up, an empty slot
  130. (with an undefined value) is opened.
  131. Arguments:
  132. pArray - Array starting address
  133. cbArraySize - Size of Array (in BYTES)
  134. cElementSize - Size of array elements
  135. iFirstElement - First element to move
  136. Direction - SHIFT_UP or SHIFT_DOWN
  137. Return Value:
  138. None. No error checking either. Should compile out to
  139. a movememory
  140. Notes:
  141. Call this with the ShiftArray macro which does the size
  142. calcs for you
  143. Revision History:
  144. Jan-26-95 Davepl Created
  145. --*/
  146. #define ShiftArray(array, index, direction) \
  147. \
  148. ShiftArrayWorker((LPBYTE) array, sizeof(array), sizeof(array[0]), index, direction)
  149. typedef enum SHIFT_DIRECTION { SHIFT_UP, SHIFT_DOWN };
  150. static inline void ShiftArrayWorker(const LPBYTE pArray,
  151. const size_t cbArraySize,
  152. const size_t cElementSize,
  153. const UINT iFirstElement,
  154. const SHIFT_DIRECTION Direction)
  155. {
  156. ASSERT( ((cbArraySize / cElementSize) * cElementSize) == cbArraySize);
  157. ASSERT( (iFirstElement + 1) * cElementSize <= cbArraySize );
  158. const LPBYTE pFirst = pArray + (iFirstElement * cElementSize);
  159. const LPBYTE pLast = pArray + cbArraySize - cElementSize;
  160. const UINT cBytesToMove = (UINT)(pLast - pFirst);
  161. ASSERT (pLast >= pFirst);
  162. if (cBytesToMove)
  163. {
  164. if (SHIFT_DOWN == Direction)
  165. {
  166. CopyMemory(pFirst, pFirst + cElementSize, cBytesToMove);
  167. }
  168. else if (Direction == SHIFT_UP)
  169. {
  170. CopyMemory(pFirst + cElementSize, pFirst, cBytesToMove);
  171. }
  172. else
  173. {
  174. ASSERT( FALSE );
  175. }
  176. }
  177. }
  178. //////////////////////////////////////////////////////////////////////////////
  179. //
  180. // MACRO
  181. // DEBUG_BREAK
  182. //
  183. // Description:
  184. // Because the system expection handler can hick-up over INT 3s and
  185. // DebugBreak()s, This x86 only macro causes the program to break in the
  186. // right spot.
  187. //
  188. //////////////////////////////////////////////////////////////////////////////
  189. #if defined( _X86_ )
  190. #define DEBUG_BREAK do { _try { _asm int 3 } _except (EXCEPTION_EXECUTE_HANDLER) {;} } while (0)
  191. #else
  192. #define DEBUG_BREAK DebugBreak()
  193. #endif
  194. //
  195. // Assert
  196. //
  197. #ifdef Assert
  198. #undef Assert
  199. #endif
  200. #ifdef DEBUG
  201. #define Assert(x) \
  202. do \
  203. { \
  204. if ( !(x) ) \
  205. { \
  206. DEBUG_BREAK; \
  207. } \
  208. } while (0)
  209. #else
  210. #define Assert(x)
  211. #endif
  212. #ifdef ASSERT
  213. #undef ASSERT
  214. #endif
  215. #define ASSERT(x) Assert(x)
  216. extern const WCHAR szTaskmanKey[];
  217. #pragma hdrstop