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.

447 lines
9.0 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. utils.h
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #ifndef _UTILS_H_
  9. #define _UTILS_H_
  10. #include <pdh.h>
  11. #include <wtypes.h> // for DATE typedef
  12. extern LPCWSTR cszSqlDataSourceFormat;
  13. //===========================================================================
  14. // Macro Definitions
  15. //===========================================================================
  16. //
  17. // String lengths
  18. //
  19. #define MAX_MESSAGE_LEN (MAX_PATH)
  20. // If RESOURCE_STRING_BUF_LEN > MAX_PATH, must check all calls to ResourceString()
  21. // to ensure caller's buffer size is correct.
  22. #define RESOURCE_STRING_BUF_LEN (MAX_PATH * 2)
  23. #define MAX_VALUE_LEN 30
  24. //
  25. // General purpose
  26. //
  27. #define PinInclusive(x, lo, hi) \
  28. max (lo, min (x, hi))
  29. #define PinExclusive(x, lo, hi) \
  30. max ((lo) + 1, min (x, (hi) - 1))
  31. //
  32. // Text
  33. //
  34. #define ELLIPSES L"..."
  35. #define ELLIPSES_CNT 3
  36. //
  37. // Window
  38. //
  39. #define WindowInvalidate(hWnd) \
  40. InvalidateRect (hWnd, NULL, TRUE)
  41. #define WindowShow(hWnd, bShow) \
  42. ShowWindow (hWnd, (bShow) ? SW_SHOW : SW_HIDE)
  43. #define WindowID(hWnd) \
  44. GetWindowLongPtr(hWnd, GWLP_ID)
  45. #define WindowStyle(hWnd) \
  46. GetWindowLong (hWnd, GWL_STYLE)
  47. #define WindowSetStyle(hWnd, lStyle) \
  48. SetWindowLong (hWnd, GWL_STYLE, lStyle)
  49. #define WindowParent(hWnd) \
  50. ((HWND) GetWindowLongPtr (hWnd, GWLP_HWNDPARENT))
  51. //
  52. // Dialog
  53. //
  54. #define DialogControl(hDlg, wControlID) \
  55. GetDlgItem (hDlg, wControlID)
  56. #define DialogText(hDlg, wControlID, szText) \
  57. ((INT)(DWORD)GetDlgItemText (hDlg, wControlID, szText, (sizeof(szText) / sizeof(WCHAR))))
  58. //
  59. // GDI
  60. //
  61. #define ClearRect(hDC, lpRect) \
  62. ExtTextOut (hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL )
  63. //===========================================================================
  64. // Exported Functions
  65. //===========================================================================
  66. //
  67. // Font/Text
  68. //
  69. INT TextWidth (
  70. HDC hDC,
  71. LPCWSTR lpszText
  72. ) ;
  73. INT FontHeight (
  74. HDC hDC,
  75. BOOL bIncludeLeading
  76. ) ;
  77. BOOL NeedEllipses (
  78. IN HDC hAttribDC,
  79. IN LPCWSTR pszText,
  80. IN INT nTextLen,
  81. IN INT xMaxExtent,
  82. IN INT xEllipses,
  83. OUT INT *pnChars
  84. ) ;
  85. VOID FitTextOut (
  86. IN HDC hDC,
  87. IN HDC hAttribDC,
  88. IN UINT fuOptions,
  89. IN CONST RECT *lprc,
  90. IN LPCWSTR lpString,
  91. IN INT cbCount,
  92. IN INT iAlign,
  93. IN BOOL fVertical
  94. ) ;
  95. //
  96. // Dialog
  97. //
  98. BOOL DialogEnable (HWND hDlg, WORD wID, BOOL bEnable) ;
  99. void DialogShow (HWND hDlg, WORD wID, BOOL bShow) ;
  100. FLOAT DialogFloat (HWND hDlg, WORD wControlID, BOOL *pbOK) ;
  101. //
  102. // Graphic
  103. //
  104. void Line (HDC hDC, HPEN hPen, INT x1, INT y1, INT x2, INT y2) ;
  105. void Fill (HDC hDC, COLORREF rgbColor, LPRECT lpRect);
  106. #ifdef __IEnumFORMATETC_INTERFACE_DEFINED__
  107. HDC CreateTargetDC(HDC hdc, DVTARGETDEVICE* ptd);
  108. #endif
  109. //
  110. // Conversion
  111. //
  112. BOOL TruncateLLTime (LONGLONG llTime, LONGLONG* pllTime);
  113. BOOL LLTimeToVariantDate (LONGLONG llTime, DATE *pDate);
  114. BOOL VariantDateToLLTime (DATE Date, LONGLONG *pllTime);
  115. //
  116. // Stream I/O - only include if user knows about IStream
  117. //
  118. #ifdef __IStream_INTERFACE_DEFINED__
  119. HRESULT WideStringFromStream (LPSTREAM pIStream, LPWSTR *ppsz, INT nLen);
  120. #endif
  121. //
  122. // Property bag I/O - only include if user knows about IStream
  123. //
  124. #ifdef __IPropertyBag_INTERFACE_DEFINED__
  125. HRESULT
  126. IntegerToPropertyBag (
  127. IPropertyBag* pPropBag,
  128. LPCWSTR szPropName,
  129. INT intData );
  130. HRESULT
  131. OleColorToPropertyBag (
  132. IPropertyBag* pIPropBag,
  133. LPCWSTR szPropName,
  134. OLE_COLOR& clrData );
  135. HRESULT
  136. ShortToPropertyBag (
  137. IPropertyBag* pPropBag,
  138. LPCWSTR szPropName,
  139. SHORT iData );
  140. HRESULT
  141. BOOLToPropertyBag (
  142. IPropertyBag* pPropBag,
  143. LPCWSTR szPropName,
  144. BOOL bData );
  145. HRESULT
  146. DoubleToPropertyBag (
  147. IPropertyBag* pPropBag,
  148. LPCWSTR szPropName,
  149. DOUBLE dblData );
  150. HRESULT
  151. FloatToPropertyBag (
  152. IPropertyBag* pIPropBag,
  153. LPCWSTR szPropName,
  154. FLOAT fData );
  155. HRESULT
  156. CyToPropertyBag (
  157. IPropertyBag* pPropBag,
  158. LPCWSTR szPropName,
  159. CY& cyData );
  160. HRESULT
  161. StringToPropertyBag (
  162. IPropertyBag* pPropBag,
  163. LPCWSTR szPropName,
  164. LPCWSTR szData );
  165. HRESULT
  166. LLTimeToPropertyBag (
  167. IPropertyBag* pIPropBag,
  168. LPCWSTR szPropName,
  169. LONGLONG& rllData );
  170. HRESULT
  171. IntegerFromPropertyBag (
  172. IPropertyBag* pIPropBag,
  173. IErrorLog* pIErrorLog,
  174. LPCWSTR szPropName,
  175. INT& rintData );
  176. HRESULT
  177. OleColorFromPropertyBag (
  178. IPropertyBag* pIPropBag,
  179. IErrorLog* pIErrorLog,
  180. LPCWSTR szPropName,
  181. OLE_COLOR& rintData );
  182. HRESULT
  183. ShortFromPropertyBag (
  184. IPropertyBag* pIPropBag,
  185. IErrorLog* pIErrorLog,
  186. LPCWSTR szPropName,
  187. SHORT& riData );
  188. HRESULT
  189. BOOLFromPropertyBag (
  190. IPropertyBag* pIPropBag,
  191. IErrorLog* pIErrorLog,
  192. LPCWSTR szPropName,
  193. BOOL& rbData );
  194. HRESULT
  195. DoubleFromPropertyBag (
  196. IPropertyBag* pIPropBag,
  197. IErrorLog* pIErrorLog,
  198. LPCWSTR szPropName,
  199. DOUBLE& rdblData );
  200. HRESULT
  201. FloatFromPropertyBag (
  202. IPropertyBag* pIPropBag,
  203. IErrorLog* pIErrorLog,
  204. LPCWSTR szPropName,
  205. FLOAT& rfData );
  206. HRESULT
  207. CyFromPropertyBag (
  208. IPropertyBag* pIPropBag,
  209. IErrorLog* pIErrorLog,
  210. LPCWSTR szPropName,
  211. CY& rcyData );
  212. HRESULT
  213. StringFromPropertyBag (
  214. IPropertyBag* pIPropBag,
  215. IErrorLog* pIErrorLog,
  216. LPCWSTR szPropName,
  217. LPWSTR szData,
  218. INT& riBufSize );
  219. HRESULT
  220. LLTimeFromPropertyBag (
  221. IPropertyBag* pIPropBag,
  222. IErrorLog* pIErrorLog,
  223. LPCWSTR szPropName,
  224. LONGLONG& rllData );
  225. #endif
  226. //
  227. // Resources
  228. //
  229. LPWSTR ResourceString(UINT uID);
  230. //
  231. // Message format
  232. //
  233. DWORD
  234. FormatSystemMessage (
  235. DWORD dwMessageId,
  236. LPWSTR pszSystemMessage,
  237. DWORD dwBufSize );
  238. //
  239. // Locale and format
  240. //
  241. #define MAX_TIME_CHARS 20
  242. #define MAX_DATE_CHARS 20
  243. INT
  244. FormatHex (
  245. double dValue,
  246. LPWSTR pNumFormatted,
  247. BOOL bLargeFormat
  248. );
  249. INT
  250. FormatNumber (
  251. double dValue,
  252. LPWSTR pNumFormatted,
  253. INT ccharsFormatted,
  254. UINT uiMinimumWidth,
  255. UINT uiPrecision );
  256. INT
  257. FormatScientific (
  258. double dValue,
  259. LPWSTR pNumFormatted,
  260. INT ccharsFormatted,
  261. UINT uiMinimumWidth,
  262. UINT uiPrecision );
  263. void
  264. FormatDateTime (
  265. LONGLONG llTime,
  266. LPWSTR pszDate,
  267. LPWSTR pszTime );
  268. LPWSTR
  269. GetTimeSeparator ( void );
  270. BOOL
  271. DisplayThousandsSeparator ( void );
  272. BOOL
  273. DisplaySingleLogSampleValue ( void );
  274. //
  275. // Hit testing
  276. //
  277. BOOL
  278. HitTestLine (
  279. POINT pt0,
  280. POINT pt1,
  281. POINTS ptMouse,
  282. INT nWidth );
  283. #define MPOINT2POINT(mpt, pt) ((pt).x = (mpt).x, (pt).y = (mpt).y)
  284. #define POINT2MPOINT(pt, mpt) ((mpt).x = (SHORT)(pt).x, (mpt).y = (SHORT)(pt).y)
  285. #define POINTS2VECTOR2D(pt0, pt1, vect) ((vect).x = (double)((pt1).x - (pt0).x), \
  286. (vect).y = (double)((pt1).y - (pt0).y))
  287. typedef struct tagVECTOR2D {
  288. double x;
  289. double y;
  290. } VECTOR2D, *PVECTOR2D, FAR *LPVECTOR2D;
  291. typedef struct tagPROJECTION {
  292. VECTOR2D ttProjection;
  293. VECTOR2D ttPerpProjection;
  294. double LenProjection;
  295. double LenPerpProjection;
  296. } PROJECTION, *PPROJECTION, FAR *LPPROJECTION;
  297. typedef struct tagPOINTNORMAL {
  298. VECTOR2D vNormal;
  299. double D;
  300. } POINTNORMAL, *PPOINTNORMAL, FAR *LPPOINTNORMAL;
  301. PVECTOR2D vSubtractVectors(PVECTOR2D v0, PVECTOR2D v1, PVECTOR2D v);
  302. double vVectorSquared(PVECTOR2D v0);
  303. double vVectorMagnitude(PVECTOR2D v0);
  304. double vDotProduct(PVECTOR2D v, PVECTOR2D v1);
  305. void vProjectAndResolve(PVECTOR2D v0, PVECTOR2D v1, PPROJECTION ppProj);
  306. double vDistFromPointToLine(LPPOINT pt0, LPPOINT pt1, LPPOINT ptTest);
  307. BOOL
  308. FileRead (
  309. HANDLE hFile,
  310. void* lpMemory,
  311. DWORD nAmtToRead );
  312. BOOL
  313. FileWrite (
  314. HANDLE hFile,
  315. void* lpMemory,
  316. DWORD nAmtToWrite );
  317. LPWSTR
  318. ExtractFileName (
  319. LPWSTR pFileSpec );
  320. // Folder path
  321. DWORD
  322. LoadDefaultLogFileFolder(
  323. WCHAR *szFolder,
  324. INT* piBufLen );
  325. // Pdh counter paths
  326. BOOL
  327. AreSameCounterPath (
  328. PPDH_COUNTER_PATH_ELEMENTS pFirst,
  329. PPDH_COUNTER_PATH_ELEMENTS pSecond );
  330. // SQL data source
  331. DWORD
  332. FormatSqlDataSourceName (
  333. LPCWSTR szSqlDsn,
  334. LPCWSTR szSqlLogSetName,
  335. LPWSTR szSqlDataSourceName,
  336. ULONG* pulBufLen );
  337. DWORD
  338. DisplayDataSourceError (
  339. HWND hwndOwner,
  340. DWORD dwErrorStatus,
  341. INT iDataSourceType,
  342. LPCWSTR szLogFileName,
  343. LPCWSTR szSqlDsn,
  344. LPCWSTR szSqlLogSetName );
  345. /////////////////////////////////////////////////////////////////////////////
  346. // class CWaitCursor
  347. class CWaitCursor
  348. {
  349. // Construction/Destruction
  350. public:
  351. CWaitCursor();
  352. virtual ~CWaitCursor();
  353. private:
  354. void DoWaitCursor ( INT nCode );
  355. HCURSOR m_hcurWaitCursorRestore;
  356. };
  357. #endif //_UTILS_H_