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.

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