Windows NT 4.0 source code leak
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.

1574 lines
40 KiB

4 years ago
  1. /*
  2. ==============================================================================
  3. Application:
  4. Microsoft Windows NT (TM) Performance Monitor
  5. File:
  6. utils.c -- miscellaneous utility routines.
  7. This file contains miscellaneous utiltity routines, mostly
  8. low-level windows helpers. These routines are not specific
  9. to the perfmon utillity.
  10. Copyright 1992, Microsoft Corporation. All Rights Reserved.
  11. Microsoft Confidential.
  12. ==============================================================================
  13. */
  14. //==========================================================================//
  15. // Includes //
  16. //==========================================================================//
  17. #include <stdarg.h> // For ANSI variable args. Dont use UNIX <varargs.h>
  18. #include <stdlib.h> // For itoa
  19. #include <stdio.h> // for vsprintf.
  20. #include <string.h> // for strtok
  21. #include <wchar.h> // for swscanf
  22. #include "perfmon.h"
  23. #include "pmemory.h" // for MemoryXXX (mallloc-type) routines
  24. #include "utils.h"
  25. #include "pmhelpid.h" // IDs for WinHelp
  26. #include "perfmops.h" // for ConvertDecimalPoint() & ReconvertDecimalPoint()
  27. #include "sizes.h"
  28. //==========================================================================//
  29. // Constants //
  30. //==========================================================================//
  31. #define DOS_FILES 0x0000 // Ordinary files
  32. #define DOS_READONLY 0x0001 // Read-only files
  33. #define DOS_HIDDEN 0x0002 // Hidden files
  34. #define DOS_SYSTEM 0x0004 // System files
  35. #define DOS_SUBDIRECTORIES 0x0010 // Subdirectories
  36. #define DOS_ARCHIVES 0x0020 // Archives
  37. #define DOS_LIB_DIR 0x2000 // LB_DIR flag
  38. #define DOS_DRIVES 0x4000 // Drives
  39. #define DOS_EXCLUSIVE 0x8000 // Exclusive bit
  40. #define DOS_DRIVES_DIRECTORIES 0xC010 // Find drives and directories only
  41. #define WILD_ONE '?'
  42. #define WILD_ANY '*'
  43. //==========================================================================//
  44. // Local Functions //
  45. //==========================================================================//
  46. void ClientRectToScreen (HWND hWnd,
  47. LPRECT lpRect)
  48. /*
  49. Effect: Remaps lpRect from client coordinates to screen
  50. coordinates. Analogous to ClientToScreen for rectangles.
  51. Note: To convert a rectangle from the client coordinates of
  52. Wnd1 to the client coordinates of Wnd2, call:
  53. ClientRectToScreen (hWnd1, &rect) ;
  54. ScreenRectToClient (hWnd2, &rect) ;
  55. See Also: ClientToScreen (windows), ScreenRectToClient.
  56. Internals: Since a rectangle is really only two points, let
  57. windows do the work with ClientToScreen.
  58. */
  59. { /* ClientRectToScreen */
  60. POINT pt1, pt2 ;
  61. pt1.x = lpRect->left ;
  62. pt1.y = lpRect->top ;
  63. pt2.x = lpRect->right ;
  64. pt2.y = lpRect->bottom ;
  65. ClientToScreen (hWnd, &pt1) ;
  66. ClientToScreen (hWnd, &pt2) ;
  67. lpRect->left = pt1.x ;
  68. lpRect->top = pt1.y ;
  69. lpRect->right = pt2.x ;
  70. lpRect->bottom = pt2.y ;
  71. } // ClientRectToScreen
  72. void ScreenRectToClient (HWND hWnd, LPRECT lpRect)
  73. /*
  74. Effect: Remaps lpRect from screen coordinates to client
  75. coordinates. Analogous to ScreenToClient for rectangles.
  76. Note: To convert a rectangle from the client coordinates of
  77. Wnd1 to the client coordinates of Wnd2, call:
  78. ClientRectToScreen (hWnd1, &rect) ;
  79. ScreenRectToClient (hWnd2, &rect) ;
  80. See Also: ScreenToClient (windows), ClientRectToScreen.
  81. Internals: Since a rectangle is really only two points, let
  82. windows do the work with ScreenToClient.
  83. */
  84. { // ScreenRectToClient
  85. POINT pt1, pt2 ;
  86. pt1.x = lpRect->left ;
  87. pt1.y = lpRect->top ;
  88. pt2.x = lpRect->right ;
  89. pt2.y = lpRect->bottom ;
  90. ScreenToClient (hWnd, &pt1) ;
  91. ScreenToClient (hWnd, &pt2) ;
  92. lpRect->left = pt1.x ;
  93. lpRect->top = pt1.y ;
  94. lpRect->right = pt2.x ;
  95. lpRect->bottom = pt2.y ;
  96. } // ScreenRectToClient
  97. //==========================================================================//
  98. // Exported Functions //
  99. //==========================================================================//
  100. void Line (HDC hDC,
  101. HPEN hPen,
  102. int x1, int y1,
  103. int x2, int y2)
  104. { // Line
  105. HPEN hPenPrevious = NULL;
  106. if (hPen)
  107. hPenPrevious = SelectPen (hDC, hPen) ;
  108. MoveToEx (hDC, x1, y1, NULL) ;
  109. LineTo (hDC, x2, y2) ;
  110. if (hPen)
  111. SelectObject (hDC, hPenPrevious) ;
  112. } // Line
  113. #if 0
  114. void HLine (HDC hDC,
  115. HPEN hPen,
  116. int x1,
  117. int x2,
  118. int y)
  119. { // HLine
  120. Line (hDC, hPen, x1, y, x2, y) ;
  121. }
  122. void VLine (HDC hDC,
  123. HPEN hPen,
  124. int x,
  125. int y1,
  126. int y2)
  127. { // VLine
  128. Line (hDC, hPen, x, y1, x, y2) ;
  129. } // VLine
  130. #endif
  131. #ifdef KEEP_UTIL
  132. void Fill (HDC hDC,
  133. DWORD rgbColor,
  134. LPRECT lpRect)
  135. { // Fill
  136. HBRUSH hBrush ;
  137. hBrush = CreateSolidBrush (rgbColor) ;
  138. FillRect (hDC, lpRect, hBrush) ;
  139. DeleteBrush (hBrush) ;
  140. } // Fill
  141. void ThreeDConvex (HDC hDC,
  142. int x1, int y1,
  143. int x2, int y2)
  144. { // ThreeDConvex
  145. HBRUSH hBrushPrevious ;
  146. POINT aPoints [8] ;
  147. DWORD aCounts [2] ;
  148. HPEN hPenPrevious ;
  149. //����������������������������Ŀ
  150. //� Draw Face �
  151. //������������������������������
  152. hBrushPrevious = SelectBrush (hDC, hBrushFace) ;
  153. PatBlt (hDC,
  154. x1 + ThreeDPad, y1 + ThreeDPad,
  155. x2 - x1 - ThreeDPad, y2 - y1 - ThreeDPad,
  156. PATCOPY) ;
  157. SelectBrush (hDC, hBrushPrevious) ;
  158. //����������������������������Ŀ
  159. //� Draw Highlight �
  160. //������������������������������
  161. if (hPenHighlight)
  162. hPenPrevious = SelectPen (hDC, hPenHighlight) ;
  163. aPoints [0].x = x1 ;
  164. aPoints [0].y = y2 - 1 ; // this works slightly diff. than Line ??
  165. aPoints [1].x = x1 ;
  166. aPoints [1].y = y1 ;
  167. aPoints [2].x = x2 ;
  168. aPoints [2].y = y1 ;
  169. aPoints [3].x = x1 + 1 ;
  170. aPoints [3].y = y2 - 1 ;
  171. aPoints [4].x = x1 + 1 ;
  172. aPoints [4].y = y1 + 1 ;
  173. aPoints [5].x = x2 - 1 ;
  174. aPoints [5].y = y1 + 1 ;
  175. aCounts [0] = 3 ;
  176. aCounts [1] = 3 ;
  177. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  178. if (hPenHighlight)
  179. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  180. // HLine (hDC, hPenHighlight, x1, x2, y1) ; // outside top line
  181. // HLine (hDC, hPenHighlight, x1 + 1, x2 - 1, y1 + 1) ; // inside top line
  182. // VLine (hDC, hPenHighlight, x1, y1, y2) ; // outside left line
  183. // VLine (hDC, hPenHighlight, x1 + 1, y1 + 1, y2 - 1) ; // inside left line
  184. //����������������������������Ŀ
  185. //� Draw Shadow �
  186. //������������������������������
  187. if (hPenShadow)
  188. hPenPrevious = SelectPen (hDC, hPenShadow) ;
  189. aPoints [0].x = x1 + 1 ;
  190. aPoints [0].y = y2 - 1 ;
  191. aPoints [1].x = x2 ;
  192. aPoints [1].y = y2 - 1 ;
  193. aPoints [2].x = x2 ;
  194. aPoints [2].y = y2 - 2 ;
  195. aPoints [3].x = x1 + 2 ;
  196. aPoints [3].y = y2 - 2 ;
  197. aPoints [4].x = x2 - 1 ;
  198. aPoints [4].y = y1 ;
  199. aPoints [5].x = x2 - 1 ;
  200. aPoints [5].y = y2 - 1;
  201. aPoints [6].x = x2 - 2 ;
  202. aPoints [6].y = y2 - 1 ;
  203. aPoints [7].x = x2 - 2 ;
  204. aPoints [7].y = y1 ;
  205. aCounts [0] = 4 ;
  206. aCounts [1] = 4 ;
  207. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  208. if (hPenShadow)
  209. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  210. // HLine (hDC, hPenShadow, x1 + 1, x2, y2 - 1) ; // outside bottom line
  211. // HLine (hDC, hPenShadow, x1 + 2, x2, y2 - 2) ; // inside bottom line
  212. // VLine (hDC, hPenShadow, x2 - 1, y1 + 1, y2) ; // outside right line
  213. // VLine (hDC, hPenShadow, x2 - 2, y1 + 2, y2) ; // inside right line
  214. } // ThreeDConvex
  215. void ThreeDConcave (HDC hDC,
  216. int x1, int y1,
  217. int x2, int y2,
  218. BOOL bFace)
  219. { // ThreeDConcave
  220. HBRUSH hBrushPrevious ;
  221. POINT aPoints [6] ;
  222. DWORD aCounts [2] ;
  223. HPEN hPenPrevious ;
  224. //����������������������������Ŀ
  225. //� Draw Face �
  226. //������������������������������
  227. if (bFace)
  228. {
  229. hBrushPrevious = SelectBrush (hDC, hBrushFace) ;
  230. PatBlt (hDC,
  231. x1 + ThreeDPad, y1 + ThreeDPad,
  232. x2 - x1 - ThreeDPad, y2 - y1 - ThreeDPad,
  233. PATCOPY) ;
  234. SelectBrush (hDC, hBrushPrevious) ;
  235. }
  236. //����������������������������Ŀ
  237. //� Draw Shadow �
  238. //������������������������������
  239. #if 1
  240. if (hPenShadow)
  241. hPenPrevious = SelectPen (hDC, hPenShadow) ;
  242. aPoints [0].x = x1 ;
  243. aPoints [0].y = y2 - 1 ;
  244. aPoints [1].x = x1 ;
  245. aPoints [1].y = y1 ;
  246. aPoints [2].x = x2 ;
  247. aPoints [2].y = y1 ;
  248. aPoints [3].x = x1 + 1 ;
  249. aPoints [3].y = y2 - 1 ;
  250. aPoints [4].x = x1 + 1 ;
  251. aPoints [4].y = y1 + 1 ;
  252. aPoints [5].x = x2 - 1 ;
  253. aPoints [5].y = y1 + 1 ;
  254. aCounts [0] = 3 ;
  255. aCounts [1] = 3 ;
  256. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  257. if (hPenShadow)
  258. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  259. #else
  260. HLine (hDC, hPenShadow, x1, x2, y1) ; // outside top line
  261. HLine (hDC, hPenShadow, x1 + 1, x2 - 1, y1 + 1) ; // inside top line
  262. VLine (hDC, hPenShadow, x1, y1, y2) ; // outside left line
  263. VLine (hDC, hPenShadow, x1 + 1, y1 + 1, y2 - 1) ; // inside left line
  264. #endif
  265. //����������������������������Ŀ
  266. //� Draw Highlight �
  267. //������������������������������
  268. #if 1
  269. if (hPenHighlight)
  270. hPenPrevious = SelectPen (hDC, hPenHighlight) ;
  271. aPoints [0].x = x1 + 1 ;
  272. aPoints [0].y = y2 - 1 ;
  273. aPoints [1].x = x2 ;
  274. aPoints [1].y = y2 - 1 ;
  275. aPoints [2].x = x2 - 1 ;
  276. aPoints [2].y = y2 - 1 ;
  277. aPoints [3].x = x2 - 1 ;
  278. aPoints [3].y = y1 ;
  279. aCounts [0] = 2 ;
  280. aCounts [1] = 2 ;
  281. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  282. if (hPenHighlight)
  283. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  284. #else
  285. HLine (hDC, hPenHighlight, x1 + 1, x2, y2 - 1) ; // outside bottom line
  286. VLine (hDC, hPenHighlight, x2 - 1, y1 + 1, y2) ; // outside right line
  287. #endif
  288. } // ThreeDConcave
  289. #endif // KEEP_UTIL
  290. void ThreeDConvex1 (HDC hDC,
  291. int x1, int y1,
  292. int x2, int y2)
  293. { // ThreeDConvex1
  294. HBRUSH hBrushPrevious ;
  295. POINT aPoints [6] ;
  296. DWORD aCounts [2] ;
  297. HPEN hPenPrevious = NULL;
  298. //����������������������������Ŀ
  299. //� Draw Face �
  300. //������������������������������
  301. #if 1
  302. hBrushPrevious = SelectBrush (hDC, hBrushFace) ;
  303. PatBlt (hDC,
  304. x1 + 1, y1 + 1,
  305. x2 - x1 - 1, y2 - y1 - 1,
  306. PATCOPY) ;
  307. SelectBrush (hDC, hBrushPrevious) ;
  308. //����������������������������Ŀ
  309. //� Draw Highlight �
  310. //������������������������������
  311. if (hPenHighlight)
  312. hPenPrevious = SelectPen (hDC, hPenHighlight) ;
  313. aPoints [0].x = x1 ;
  314. aPoints [0].y = y2 - 1 ;
  315. aPoints [1].x = x1 ;
  316. aPoints [1].y = y1 ;
  317. aPoints [2].x = x2 ;
  318. aPoints [2].y = y1 ;
  319. Polyline (hDC, aPoints, 3) ;
  320. if (hPenHighlight)
  321. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  322. #else
  323. HLine (hDC, hPenHighlight, x1, x2, y1) ; // outside top line
  324. VLine (hDC, hPenHighlight, x1, y1, y2) ; // outside left line
  325. #endif
  326. //����������������������������Ŀ
  327. //� Draw Shadow �
  328. //������������������������������
  329. #if 1
  330. if (hPenShadow)
  331. hPenPrevious = SelectPen (hDC, hPenShadow) ;
  332. aPoints [0].x = x1 + 1 ;
  333. aPoints [0].y = y2 - 1 ;
  334. aPoints [1].x = x2 ;
  335. aPoints [1].y = y2 - 1 ;
  336. aPoints [2].x = x2 - 1 ;
  337. aPoints [2].y = y2 - 1 ;
  338. aPoints [3].x = x2 - 1 ;
  339. aPoints [3].y = y1 ;
  340. aCounts [0] = 2 ;
  341. aCounts [1] = 2 ;
  342. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  343. if (hPenShadow)
  344. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  345. #else
  346. HLine (hDC, hPenShadow, x1 + 1, x2, y2 - 1) ; // outside bottom line
  347. VLine (hDC, hPenShadow, x2 - 1, y1 + 1, y2) ; // outside right line
  348. #endif
  349. } // ThreeDConvex1
  350. void ThreeDConcave1 (HDC hDC,
  351. int x1, int y1,
  352. int x2, int y2)
  353. { // ThreeDConcave1
  354. HBRUSH hBrushPrevious ;
  355. POINT aPoints [6] ;
  356. DWORD aCounts [2] ;
  357. HPEN hPenPrevious = NULL;
  358. //����������������������������Ŀ
  359. //� Draw Face �
  360. //������������������������������
  361. hBrushPrevious = SelectBrush (hDC, hBrushFace) ;
  362. PatBlt (hDC,
  363. x1 + 1, y1 + 1,
  364. x2 - x1 - 1, y2 - y1 - 1,
  365. PATCOPY) ;
  366. SelectBrush (hDC, hBrushPrevious) ;
  367. //����������������������������Ŀ
  368. //� Draw Shadow �
  369. //������������������������������
  370. #if 1
  371. if (hPenShadow)
  372. hPenPrevious = SelectPen (hDC, hPenShadow) ;
  373. aPoints [0].x = x1 ;
  374. aPoints [0].y = y2 - 1 ;
  375. aPoints [1].x = x1 ;
  376. aPoints [1].y = y1 ;
  377. aPoints [2].x = x2 ;
  378. aPoints [2].y = y1 ;
  379. Polyline (hDC, aPoints, 3) ;
  380. if (hPenShadow)
  381. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  382. #else
  383. HLine (hDC, hPenShadow, x1, x2, y1) ; // outside top line
  384. VLine (hDC, hPenShadow, x1, y1, y2) ; // outside left line
  385. #endif
  386. //����������������������������Ŀ
  387. //� Draw Highlight �
  388. //������������������������������
  389. #if 1
  390. if (hPenHighlight)
  391. hPenPrevious = SelectPen (hDC, hPenHighlight) ;
  392. aPoints [0].x = x1 + 1 ;
  393. aPoints [0].y = y2 - 1 ;
  394. aPoints [1].x = x2 ;
  395. aPoints [1].y = y2 - 1 ;
  396. aPoints [2].x = x2 - 1 ;
  397. aPoints [2].y = y2 - 2 ;
  398. aPoints [3].x = x2 - 1 ;
  399. aPoints [3].y = y1 ;
  400. aCounts [0] = 2 ;
  401. aCounts [1] = 2 ;
  402. PolyPolyline (hDC, aPoints, aCounts, 2) ;
  403. if (hPenHighlight)
  404. hPenPrevious = SelectPen (hDC, hPenPrevious) ;
  405. #else
  406. HLine (hDC, hPenHighlight, x1 + 1, x2, y2 - 1) ; // outside bottom line
  407. VLine (hDC, hPenHighlight, x2 - 1, y1 + 1, y2) ; // outside right line
  408. #endif
  409. } // ThreeDConcave1
  410. int TextWidth (HDC hDC, LPTSTR lpszText)
  411. {
  412. SIZE size ;
  413. if (!lpszText)
  414. return (0) ;
  415. GetTextExtentPoint (hDC, lpszText, lstrlen (lpszText), &size) ;
  416. return (size.cx) ;
  417. }
  418. int _cdecl DlgErrorBox (HWND hDlg, UINT id, ...)
  419. {
  420. TCHAR szMessageFmt [FilePathLen + 1] ;
  421. TCHAR szBuffer [FilePathLen * 2] ;
  422. va_list vaList ;
  423. int NumOfChar ;
  424. TCHAR szApplication [WindowCaptionLen] ;
  425. NumOfChar = StringLoad (id, szMessageFmt) ;
  426. if (NumOfChar)
  427. {
  428. va_start (vaList, id) ;
  429. TSPRINTF (szBuffer, szMessageFmt, va_arg(vaList, LPTSTR)) ;
  430. va_end (vaList) ;
  431. StringLoad (IDS_APPNAME, szApplication) ;
  432. MessageBox (hDlg, szBuffer, szApplication,
  433. MB_OK | MB_ICONSTOP | MB_TASKMODAL) ;
  434. }
  435. return (0) ;
  436. }
  437. int FontHeight (HDC hDC,
  438. BOOL bIncludeLeading)
  439. { // FontHeight
  440. TEXTMETRIC tm ;
  441. GetTextMetrics (hDC, &tm) ;
  442. if (bIncludeLeading)
  443. return (tm.tmHeight + tm.tmExternalLeading) ;
  444. else
  445. return (tm.tmHeight) ;
  446. } // FontHeight
  447. int TextAvgWidth (HDC hDC,
  448. int iNumChars)
  449. {
  450. TEXTMETRIC tm ;
  451. int xAvgWidth ;
  452. GetTextMetrics (hDC, &tm) ;
  453. xAvgWidth = iNumChars * tm.tmAveCharWidth ;
  454. // add 10% slop
  455. return (MulDiv (xAvgWidth, 11, 10)) ;
  456. }
  457. void WindowCenter (HWND hWnd)
  458. /*
  459. Effect: Center the window hWnd in the center of the screen.
  460. Physically update the windows appearance as well.
  461. Globals: xScreenWidth, yScreenHeight.
  462. */
  463. { // WindowCenter
  464. RECT rectWindow ;
  465. int xWindowWidth, yWindowHeight ;
  466. GetWindowRect (hWnd, &rectWindow) ;
  467. xWindowWidth = rectWindow.right - rectWindow.left ;
  468. yWindowHeight = rectWindow.bottom - rectWindow.top ;
  469. MoveWindow (hWnd,
  470. (xScreenWidth - xWindowWidth) / 2,
  471. (yScreenHeight - yWindowHeight) / 2,
  472. xWindowWidth,
  473. yWindowHeight,
  474. TRUE) ;
  475. } // WindowCenter
  476. BOOL DialogMove (HDLG hDlg,
  477. WORD wControlID,
  478. int xPos,
  479. int yPos,
  480. int xWidth,
  481. int yHeight)
  482. /*
  483. Effect: Move the control identified by wControlID in the dialog
  484. hDlg to the new position (xPos, yPos), and resize to
  485. (xWidth, yHeight). If any of these values are NOCHANGE, retain
  486. the current value.
  487. Examples: DialogMove (hDlg, IDD_FOO, 10, 20, NOCHANGE, NOCHANGE)
  488. moves control but does not resize it
  489. DialogMove (hDlg, IDD_FOO, NOCHANGE, NOCHANGE, 100, NOCHANGE)
  490. sets width of control to 100
  491. */
  492. { // DialogMove
  493. HWND hWndControl ;
  494. RECT rectControl ;
  495. hWndControl = DialogControl (hDlg, wControlID) ;
  496. if (!hWndControl)
  497. return (FALSE) ;
  498. GetWindowRect (hWndControl, &rectControl) ;
  499. ScreenRectToClient (hDlg, &rectControl) ;
  500. MoveWindow (hWndControl,
  501. (xPos == NOCHANGE) ? rectControl.left : xPos,
  502. (yPos == NOCHANGE) ? rectControl.top : yPos,
  503. (xWidth == NOCHANGE) ? rectControl.right - rectControl.left : xWidth,
  504. (yHeight == NOCHANGE) ? rectControl.bottom - rectControl.top : yHeight,
  505. TRUE) ;
  506. return (TRUE) ;
  507. } // DialogMove
  508. int DialogWidth (HDLG hDlg,
  509. WORD wControlID)
  510. {
  511. HWND hWndControl ;
  512. RECT rectControl ;
  513. hWndControl = DialogControl (hDlg, wControlID) ;
  514. if (!hWndControl)
  515. return (0) ;
  516. GetWindowRect (hWndControl, &rectControl) ;
  517. return (rectControl.right - rectControl.left) ;
  518. }
  519. int DialogHeight (HDLG hDlg,
  520. WORD wControlID)
  521. {
  522. HWND hWndControl ;
  523. RECT rectControl ;
  524. hWndControl = DialogControl (hDlg, wControlID) ;
  525. if (!hWndControl)
  526. return (0) ;
  527. GetWindowRect (hWndControl, &rectControl) ;
  528. return (rectControl.bottom - rectControl.top) ;
  529. }
  530. int DialogXPos (HDLG hDlg,
  531. WORD wControlID)
  532. { // DialogXPos
  533. HWND hWndControl ;
  534. RECT rectControl ;
  535. hWndControl = DialogControl (hDlg, wControlID) ;
  536. if (!hWndControl)
  537. return (0) ;
  538. GetWindowRect (hWndControl, &rectControl) ;
  539. ScreenRectToClient (hDlg, &rectControl) ;
  540. return (rectControl.left) ;
  541. } // DialogXPos
  542. int DialogYPos (HDLG hDlg,
  543. WORD wControlID)
  544. { // DialogYPos
  545. HWND hWndControl ;
  546. RECT rectControl ;
  547. hWndControl = DialogControl (hDlg, wControlID) ;
  548. if (!hWndControl)
  549. return (0) ;
  550. GetWindowRect (hWndControl, &rectControl) ;
  551. ScreenRectToClient (hDlg, &rectControl) ;
  552. return (rectControl.top) ;
  553. } // DialogYPos
  554. void DialogEnable (HDLG hDlg,
  555. WORD wID,
  556. BOOL bEnable)
  557. /*
  558. Effect: Enable or disable (based on bEnable) the control
  559. identified by wID in dialog hDlg.
  560. See Also: DialogShow.
  561. */
  562. { // DialogEnable
  563. HCONTROL hControl ;
  564. hControl = GetDlgItem (hDlg, wID) ;
  565. if (hControl)
  566. EnableWindow (hControl, bEnable) ;
  567. } // DialogEnable
  568. void DialogShow (HDLG hDlg,
  569. WORD wID,
  570. BOOL bShow)
  571. { // DialogShow
  572. HCONTROL hControl ;
  573. hControl = GetDlgItem (hDlg, wID) ;
  574. if (hControl)
  575. ShowWindow (hControl, bShow ? SW_SHOW : SW_HIDE) ;
  576. } // DialogShow
  577. BOOL _cdecl DialogSetText (HDLG hDlg,
  578. WORD wControlID,
  579. WORD wStringID,
  580. ...)
  581. { // DialogSetText
  582. TCHAR szFormat [ControlStringLen] ;
  583. TCHAR szText [ControlStringLen] ;
  584. va_list vaList ;
  585. if (LoadString (hInstance, wStringID,
  586. szFormat, ControlStringLen - 1))
  587. {
  588. va_start (vaList, wStringID) ;
  589. TSPRINTF (szText, szFormat, va_arg(vaList, LPTSTR)) ;
  590. va_end (vaList) ;
  591. SetDlgItemText (hDlg, wControlID, szText) ;
  592. return (TRUE) ;
  593. } // if
  594. else
  595. return (FALSE) ;
  596. } // DialogSetText
  597. // Bug - lpszFormat could contain % in it
  598. #if 0
  599. BOOL _cdecl DialogSetString (HDLG hDlg,
  600. WORD wControlID,
  601. LPTSTR lpszFormat,
  602. ...)
  603. { // DialogSetString
  604. TCHAR szText [ControlStringLen] ;
  605. va_list vaList ;
  606. va_start (vaList, lpszFormat) ;
  607. TSPRINTF (szText, lpszFormat, va_arg(vaList, LPTSTR)) ;
  608. va_end (vaList) ;
  609. SetDlgItemText (hDlg, wControlID, szText) ;
  610. return (TRUE) ;
  611. } // DialogSetString
  612. #endif
  613. LPTSTR LongToCommaString (LONG lNumber,
  614. LPTSTR lpszText)
  615. { // LongToCommaString
  616. BOOL bNegative ;
  617. TCHAR szTemp1 [40] ;
  618. TCHAR szTemp2 [40] ;
  619. LPTSTR lpsz1 ;
  620. LPTSTR lpsz2 ;
  621. int i ;
  622. int iDigit ;
  623. // 1. Convert the number to a reversed string.
  624. lpsz1 = szTemp1 ;
  625. bNegative = (lNumber < 0) ;
  626. lNumber = labs (lNumber) ;
  627. if (lNumber)
  628. while (lNumber)
  629. {
  630. iDigit = (int) (lNumber % 10L) ;
  631. lNumber /= 10L ;
  632. *lpsz1++ = (TCHAR) (TEXT('0') + iDigit) ;
  633. }
  634. else
  635. *lpsz1++ = TEXT('0') ;
  636. *lpsz1++ = TEXT('\0') ;
  637. // 2. reverse the string and add commas
  638. lpsz1 = szTemp1 + lstrlen (szTemp1) - 1 ;
  639. lpsz2 = szTemp2 ;
  640. if (bNegative)
  641. *lpsz2++ = TEXT('-') ;
  642. for (i = lstrlen (szTemp1) - 1;
  643. i >= 0 ;
  644. i--)
  645. { // for
  646. *lpsz2++ = *lpsz1-- ;
  647. if (i && !(i % 3))
  648. *lpsz2++ = TEXT(',') ;
  649. } // for
  650. *lpsz2++ = TEXT('\0') ;
  651. return (lstrcpy (lpszText, szTemp2)) ;
  652. } // LongToCommaString
  653. BOOL MenuSetPopup (HWND hWnd,
  654. int iPosition,
  655. WORD wControlID,
  656. LPTSTR lpszResourceID)
  657. {
  658. HMENU hMenuMain ;
  659. HMENU hMenuPopup ;
  660. TCHAR szTopChoice [MenuStringLen + 1] ;
  661. hMenuMain = GetMenu (hWnd) ;
  662. hMenuPopup = LoadMenu (hInstance, lpszResourceID) ;
  663. if (!hMenuMain || !hMenuPopup)
  664. return (FALSE) ;
  665. StringLoad (wControlID, szTopChoice) ;
  666. return (ModifyMenu (hMenuMain, iPosition, MF_BYPOSITION | MF_POPUP,
  667. (UINT) hMenuPopup, szTopChoice)) ;
  668. }
  669. LPTSTR FileCombine (LPTSTR lpszFileSpec,
  670. LPTSTR lpszFileDirectory,
  671. LPTSTR lpszFileName)
  672. { // FileCombine
  673. int stringLen ;
  674. TCHAR DIRECTORY_DELIMITER[2] ;
  675. DIRECTORY_DELIMITER[0] = TEXT('\\') ;
  676. DIRECTORY_DELIMITER[1] = TEXT('\0') ;
  677. lstrcpy (lpszFileSpec, lpszFileDirectory) ;
  678. stringLen = lstrlen (lpszFileSpec) ;
  679. if (stringLen > 0 &&
  680. lpszFileSpec [stringLen - 1] != DIRECTORY_DELIMITER [0])
  681. lstrcat (lpszFileSpec, DIRECTORY_DELIMITER) ;
  682. lstrcat (lpszFileSpec, lpszFileName) ;
  683. return (lpszFileSpec) ;
  684. } // FileCombine
  685. // This routine extract the filename portion from a given full-path filename
  686. LPTSTR ExtractFileName (LPTSTR pFileSpec)
  687. {
  688. LPTSTR pFileName = NULL ;
  689. TCHAR DIRECTORY_DELIMITER1 = TEXT('\\') ;
  690. TCHAR DIRECTORY_DELIMITER2 = TEXT(':') ;
  691. if (pFileSpec)
  692. {
  693. pFileName = pFileSpec + lstrlen (pFileSpec) ;
  694. while (*pFileName != DIRECTORY_DELIMITER1 &&
  695. *pFileName != DIRECTORY_DELIMITER2)
  696. {
  697. if (pFileName == pFileSpec)
  698. {
  699. // done when no directory delimiter is found
  700. break ;
  701. }
  702. pFileName-- ;
  703. }
  704. if (*pFileName == DIRECTORY_DELIMITER1 ||
  705. *pFileName == DIRECTORY_DELIMITER2)
  706. {
  707. // directory delimiter found, point the
  708. // filename right after it
  709. pFileName++ ;
  710. }
  711. }
  712. return pFileName ;
  713. } // ExtractFileName
  714. int CBAddInt (HWND hWndCB,
  715. int iValue)
  716. { // CBAddInt
  717. TCHAR szValue [ShortTextLen + 1] ;
  718. CHAR szCharValue [ShortTextLen + 1] ;
  719. _itoa (iValue, (LPSTR)szCharValue, 10) ;
  720. #ifdef UNICODE
  721. mbstowcs (szValue, (LPSTR)szCharValue, strlen((LPSTR)szCharValue)+1) ;
  722. return (CBAdd (hWndCB, szValue)) ;
  723. #else
  724. return (CBAdd (hWndCB, szCharValue)) ;
  725. #endif
  726. } // CBAddInt
  727. void DialogSetInterval (HDLG hDlg,
  728. WORD wControlID,
  729. int IntervalMSec)
  730. {
  731. TCHAR szValue [MiscTextLen] ;
  732. TSPRINTF (szValue, TEXT("%3.3f"),
  733. (FLOAT)(IntervalMSec / 1000)) ;
  734. ConvertDecimalPoint (szValue) ;
  735. SetDlgItemText (hDlg, wControlID, szValue) ;
  736. }
  737. void DialogSetFloat (HDLG hDlg,
  738. WORD wControlID,
  739. FLOAT eValue)
  740. {
  741. TCHAR szValue [40] ;
  742. FLOAT tempValue = eValue ;
  743. if (tempValue < (FLOAT) 0.0)
  744. {
  745. tempValue = - tempValue ;
  746. }
  747. if (tempValue < (FLOAT) 1.0E+8)
  748. {
  749. TSPRINTF (szValue, TEXT("%1.4f"), eValue) ;
  750. }
  751. else
  752. {
  753. TSPRINTF (szValue, TEXT("%14.6e"), eValue) ;
  754. }
  755. ConvertDecimalPoint (szValue) ;
  756. SetDlgItemText (hDlg, wControlID, szValue) ;
  757. }
  758. FLOAT DialogFloat (HDLG hDlg,
  759. WORD wControlID,
  760. BOOL *pbOK)
  761. /*
  762. Effect: Return a floating point representation of the string
  763. value found in the control wControlID of hDlg.
  764. Internals: We use sscanf instead of atof becuase atof returns a
  765. double. This may or may not be the right thing to do.
  766. */
  767. { // DialogFloat
  768. TCHAR szValue [ShortTextLen+1] ;
  769. FLOAT eValue ;
  770. int iNumScanned ;
  771. DialogText (hDlg, wControlID, szValue) ;
  772. ReconvertDecimalPoint (szValue) ;
  773. iNumScanned = swscanf (szValue, TEXT("%e"), &eValue) ;
  774. if (pbOK)
  775. *pbOK = (iNumScanned == 1) ;
  776. return (eValue) ;
  777. } // DialogFloat
  778. LPTSTR StringAllocate (LPTSTR lpszText1)
  779. { // StringAllocate
  780. LPTSTR lpszText2 ;
  781. if (!lpszText1)
  782. return (NULL) ;
  783. if (lstrlen (lpszText1) == 0)
  784. return (NULL) ;
  785. lpszText2 = MemoryAllocate ((lstrlen (lpszText1)+1) * sizeof (TCHAR)) ;
  786. if (lpszText2)
  787. lstrcpy (lpszText2, lpszText1) ;
  788. return (lpszText2) ;
  789. } // StringAllocate
  790. int DivRound (int iNumerator, int iDenominator)
  791. /*
  792. Effect: Return the quotient (iNumerator / iDenominator).
  793. Round the quotient to the nearest integer.
  794. This function is similar to normal integer division (/),
  795. but normal division always rounds down.
  796. Note: Surely there must already be a runtime version of this,
  797. but I couldn't find it.
  798. Note: This function originally used the runtime div function
  799. instead of (/ and %), but the div runtime function is
  800. now broken (build 265).
  801. */
  802. { // DivRound
  803. int iQuotient ;
  804. int iRemainder ;
  805. iQuotient = iNumerator / iDenominator ;
  806. iRemainder = iNumerator % iDenominator ;
  807. if (iRemainder >= (iDenominator / 2))
  808. iQuotient++ ;
  809. return (iQuotient) ;
  810. }
  811. BOOL MenuEnableItem (HMENU hMenu,
  812. WORD wID,
  813. BOOL bEnable)
  814. /*
  815. Effect: Enable or disable, depending on bEnable, the menu item
  816. associated with id wID in the menu hMenu.
  817. Any disabled menu items are displayed grayed out.
  818. See Also: EnableMenuItem (windows).
  819. */
  820. { // MenuEnableItem
  821. return (EnableMenuItem (hMenu, wID,
  822. bEnable ?
  823. (MF_ENABLED | MF_BYCOMMAND) :
  824. (MF_GRAYED | MF_BYCOMMAND))) ;
  825. } // MenuEnableItem
  826. void BitmapDimemsion (HBITMAP hBitmap, int *pHeight, int *pWidth)
  827. { // BitmapDimemsion
  828. BITMAP bm ;
  829. GetObject (hBitmap, sizeof (BITMAP), (LPSTR) &bm) ;
  830. if (pHeight)
  831. *pHeight = bm.bmHeight ;
  832. if (pWidth)
  833. *pWidth = bm.bmWidth ;
  834. } // BitmapDimemsion
  835. int WindowHeight (HWND hWnd)
  836. { // WindowHeight
  837. RECT rectWindow ;
  838. GetWindowRect (hWnd, &rectWindow) ;
  839. return (rectWindow.bottom - rectWindow.top) ;
  840. } // WindowHeight
  841. #ifdef KEEP_UTIL
  842. int WindowWidth (HWND hWnd)
  843. { // WindowWidth
  844. RECT rectWindow ;
  845. GetWindowRect (hWnd, &rectWindow) ;
  846. return (rectWindow.right - rectWindow.left) ;
  847. } // WindowWidth
  848. void WindowResize (HWND hWnd,
  849. int xWidth,
  850. int yHeight)
  851. /*
  852. Effect: Change the size of the window hWnd, leaving the
  853. starting position intact. Redraw the window.
  854. If either xWidth or yHeight is NULL, keep the
  855. corresponding dimension unchanged.
  856. Internals: Since hWnd may be a child of another parent, we need
  857. to scale the MoveWindow arguments to be in the client
  858. coordinates of the parent.
  859. */
  860. { // WindowResize
  861. RECT rectWindow ;
  862. HWND hWndParent ;
  863. GetWindowRect (hWnd, &rectWindow) ;
  864. hWndParent = WindowParent (hWnd) ;
  865. if (hWndParent)
  866. ScreenRectToClient (hWndParent, &rectWindow) ;
  867. MoveWindow (hWnd,
  868. rectWindow.left,
  869. rectWindow.top,
  870. xWidth ? xWidth : rectWindow.right - rectWindow.left,
  871. yHeight ? yHeight : rectWindow.bottom - rectWindow.top,
  872. TRUE) ;
  873. } // WindowResize
  874. #endif
  875. void WindowSetTopmost (HWND hWnd, BOOL bTopmost)
  876. /*
  877. Effect: Set or clear the "topmost" attribute of hWnd. If a window
  878. is "topmost", it remains ontop of other windows, even ones
  879. that have the focus.
  880. */
  881. {
  882. SetWindowPos (hWnd, bTopmost ? HWND_TOPMOST : HWND_NOTOPMOST,
  883. 0, 0, 0, 0,
  884. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE) ;
  885. }
  886. void WindowEnableTitle (HWND hWnd, BOOL bTitle)
  887. {
  888. DWORD dwStyle ;
  889. dwStyle = WindowStyle (hWnd) ;
  890. if (bTitle)
  891. dwStyle = WS_TILEDWINDOW | dwStyle ;
  892. else
  893. dwStyle =
  894. dwStyle &
  895. ~ (WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) ;
  896. if (!bTitle)
  897. SetMenu (hWnd, NULL) ;
  898. WindowSetStyle (hWnd, dwStyle) ;
  899. SetWindowPos (hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
  900. SWP_NOZORDER | SWP_FRAMECHANGED );
  901. }
  902. // removing the following routines since LINK32 is not doing that for us
  903. #ifdef KEEP_UTIL
  904. int MessageBoxResource (HWND hWndParent,
  905. WORD wTextID,
  906. WORD wTitleID,
  907. UINT uiStyle)
  908. /*
  909. Effect: Just like MessageBox, but takes the title and format
  910. strings from the resoure. In addition, the format string
  911. is used as a printf style format, combined with the
  912. additional arguments.
  913. */
  914. { // MessageBoxResource
  915. TCHAR szText [MessageLen + 1] ;
  916. TCHAR szCaption [WindowCaptionLen + 1] ;
  917. StringLoad (wTextID, szText) ;
  918. StringLoad (wTitleID, szCaption) ;
  919. return (MessageBox (hWndParent, szText, szCaption, uiStyle)) ;
  920. } // MessageBoxResource
  921. #define WndProcKey TEXT("OLDWNDPROC")
  922. FARPROC WindowSetWndProc (HWND hWnd,
  923. HANDLE hInstance,
  924. FARPROC lpfnNewWndProc)
  925. /*
  926. Effect: Replace the window procedure of hWnd with lpfnNewWndProc.
  927. Return the existing window procedure.
  928. Note: For proper subclassing, NewWndProc should pass all
  929. unhandled messages to the original wndproc.
  930. Called By: WindowSubclass, WindowUnsubclass.
  931. */
  932. { // WindowSetWndProc
  933. FARPROC lpfnNewProcInstance ;
  934. FARPROC lpfnOldProc ;
  935. lpfnOldProc = (FARPROC) GetWindowLong (hWnd, GWL_WNDPROC) ;
  936. lpfnNewProcInstance = MakeProcInstance (lpfnNewWndProc, hInstance) ;
  937. SetWindowLong (hWnd, GWL_WNDPROC, (long) lpfnNewProcInstance) ;
  938. return (lpfnOldProc) ;
  939. } // WindowSetWndProc
  940. WNDPROC WindowGetOriginalWndProc (HWND hWnd)
  941. /*
  942. Effect: Return a far pointer to the "original" wndproc for
  943. hWnd.
  944. Assert: WindowSetOriginalProc was already called on this hWnd.
  945. See Also: WindowSetOriginalWndProc.
  946. */
  947. { // WindowGetOriginalWndProc
  948. return (WNDPROC) GetProp (hWnd, WndProcKey) ;
  949. } // WindowGetOriginalWndProc
  950. void WindowSetOriginalWndProc (HWND hWnd,
  951. FARPROC lpfnWndProc)
  952. /*
  953. Effect: Save away a far pointer to the "original" wndproc for
  954. hWnd.
  955. See Also: WindowGetOriginalProc.
  956. */
  957. { // WindowSetOriginalProc
  958. SetProp (hWnd, WndProcKey, (LPSTR) lpfnWndProc) ;
  959. } // WindowSetOriginalProc
  960. void WindowSubclass (HWND hWnd,
  961. HANDLE hInstance,
  962. FARPROC lpfnNewWndProc)
  963. /*
  964. Effect: Replace the wndproc for hWnd with lpfnNewWndProc.
  965. Save away a pointer to the original procedure.
  966. See Also: WindowUnsubclass.
  967. */
  968. { // WindowSubclass
  969. FARPROC lpfnOldWndProc ;
  970. lpfnOldWndProc = WindowSetWndProc (hWnd, hInstance, lpfnNewWndProc) ;
  971. WindowSetOriginalWndProc (hWnd, lpfnOldWndProc) ;
  972. } // WindowSubclass
  973. LONG WindowCallOriginalWndProc (HWND hWnd,
  974. UINT msg,
  975. WPARAM wParam,
  976. LPARAM lParam)
  977. {
  978. WNDPROC lpfnOriginalWndProc ;
  979. lpfnOriginalWndProc = WindowGetOriginalWndProc (hWnd) ;
  980. if (lpfnOriginalWndProc)
  981. return ((LONG) CallWindowProc (lpfnOriginalWndProc,
  982. hWnd, msg, wParam, lParam)) ;
  983. else return (FALSE) ;
  984. }
  985. LRESULT APIENTRY FocusCtlWndProc (HWND hWnd,
  986. UINT wMsg,
  987. WPARAM wParam,
  988. LPARAM lParam)
  989. { // FocusCtlWndProc
  990. BOOL bCallDefProc ;
  991. LRESULT lReturnValue ;
  992. bCallDefProc = TRUE ;
  993. lReturnValue = 0L ;
  994. switch (wMsg)
  995. { // switch
  996. case WM_SETFOCUS:
  997. SendMessage (WindowParent (hWnd),
  998. WM_DLGSETFOCUS, WindowID (hWnd), 0) ;
  999. break ;
  1000. case WM_KILLFOCUS:
  1001. SendMessage (WindowParent (hWnd),
  1002. WM_DLGKILLFOCUS, WindowID (hWnd), 0) ;
  1003. break ;
  1004. default:
  1005. bCallDefProc = TRUE ;
  1006. } // switch
  1007. if (bCallDefProc)
  1008. lReturnValue = WindowCallOriginalWndProc (hWnd, wMsg, wParam, lParam) ;
  1009. return (lReturnValue);
  1010. } // FocusWndProc
  1011. BOOL DlgFocus (HDLG hDlg, WORD wControlID)
  1012. { // DlgFocus
  1013. HWND hWndControl ;
  1014. hWndControl = DialogControl (hDlg, wControlID) ;
  1015. if (!hWndControl)
  1016. return (FALSE) ;
  1017. WindowSubclass (hWndControl, hInstance, (FARPROC) FocusCtlWndProc) ;
  1018. return (TRUE) ;
  1019. } // DlgFocus
  1020. BOOL DeviceNumColors (HDC hDC)
  1021. { // DeviceNumColors
  1022. int nPlanes ;
  1023. int nBitsPixel ;
  1024. nPlanes = GetDeviceCaps (hDC, PLANES) ;
  1025. nBitsPixel = GetDeviceCaps (hDC, BITSPIXEL) ;
  1026. return (1 << (nPlanes * nBitsPixel)) ;
  1027. } // DeviceNumColors
  1028. void DrawBitmap (HDC hDC,
  1029. HBITMAP hBitmap,
  1030. int xPos,
  1031. int yPos,
  1032. LONG lROPCode)
  1033. { // DrawBitmap
  1034. BITMAP bm ;
  1035. HDC hDCMemory ;
  1036. hDCMemory = CreateCompatibleDC (hDC) ;
  1037. SelectObject (hDCMemory, hBitmap) ;
  1038. GetObject (hBitmap, sizeof (BITMAP), (LPSTR) &bm) ;
  1039. BitBlt (hDC, // DC for Destination surface
  1040. xPos, yPos, // location in destination surface
  1041. bm.bmWidth, bm.bmHeight, // dimension of bitmap
  1042. hDCMemory, // DC for Source surface
  1043. 0, 0, // location in source surface
  1044. lROPCode) ; // ROP code
  1045. DeleteDC (hDCMemory) ;
  1046. } // DrawBitmap
  1047. #endif // KEEP_UTIL
  1048. #ifdef PERFMON_DEBUG
  1049. #define MikeBufferSize 256
  1050. int _cdecl mike (TCHAR *szFormat, ...)
  1051. /*
  1052. Note: This function returns a value so that it can more easily
  1053. be used in conditional expressions.
  1054. */
  1055. { // mike
  1056. TCHAR szBuffer [MikeBufferSize] ;
  1057. va_list vaList ;
  1058. va_start (vaList, szFormat) ;
  1059. TSPRINTF (szBuffer, szFormat, va_arg(vaList, LPTSTR)) ;
  1060. va_end (vaList) ;
  1061. MessageBox (NULL, szBuffer, TEXT("Debug"), MB_OK | MB_TASKMODAL) ;
  1062. return (0) ;
  1063. } // mike
  1064. int _cdecl mike1 (TCHAR *szFormat, ...)
  1065. /*
  1066. Note: This function returns a value so that it can more easily
  1067. be used in conditional expressions.
  1068. */
  1069. { // mike1
  1070. TCHAR szBuffer [MikeBufferSize] ;
  1071. va_list vaList ;
  1072. HDC hDC ;
  1073. RECT rect ;
  1074. va_start (vaList, szFormat) ;
  1075. TSPRINTF (szBuffer, szFormat, va_arg(vaList, LPTSTR)) ;
  1076. va_end (vaList) ;
  1077. rect.left = 0 ;
  1078. rect.right = xScreenWidth ;
  1079. rect.top = 0 ;
  1080. rect.bottom = 20 ;
  1081. hDC = CreateScreenDC () ;
  1082. ExtTextOut (hDC, 0, 0, ETO_OPAQUE, &rect,
  1083. szBuffer, lstrlen (szBuffer), NULL) ;
  1084. DeleteDC (hDC) ;
  1085. return (0) ;
  1086. } // mike1
  1087. int _cdecl mike2 (TCHAR *szFormat, ...)
  1088. /*
  1089. Note: This function returns a value so that it can more easily
  1090. be used in conditional expressions.
  1091. */
  1092. { // mike2
  1093. TCHAR szBuffer [MikeBufferSize] ;
  1094. va_list vaList ;
  1095. va_start (vaList, szFormat) ;
  1096. TSPRINTF (szBuffer, szFormat, va_arg(vaList, LPTSTR)) ;
  1097. va_end (vaList) ;
  1098. OutputDebugString (szBuffer) ;
  1099. return (0) ;
  1100. } // mike2
  1101. #endif // PERFMON_DEBUG
  1102. #ifdef KEEP_UTIL
  1103. int inttok (LPSTR lpszText, LPSTR lpszDelimiters)
  1104. { // inttok
  1105. // Inttok only works with LPSTRs because of the atoi & strtok
  1106. LPSTR lpszToken ;
  1107. lpszToken = strtok (lpszText, lpszDelimiters) ;
  1108. if (lpszToken)
  1109. return (atoi (lpszToken)) ;
  1110. else
  1111. return (0) ;
  1112. } // inttok
  1113. void WindowPlacementToString (PWINDOWPLACEMENT pWP,
  1114. LPTSTR lpszText)
  1115. {
  1116. TSPRINTF (lpszText, TEXT("%d %d %d %d %d %d %d %d %d"),
  1117. pWP->showCmd,
  1118. pWP->ptMinPosition.x,
  1119. pWP->ptMinPosition.y,
  1120. pWP->ptMaxPosition.x,
  1121. pWP->ptMaxPosition.y,
  1122. pWP->rcNormalPosition.left,
  1123. pWP->rcNormalPosition.top,
  1124. pWP->rcNormalPosition.right,
  1125. pWP->rcNormalPosition.bottom) ;
  1126. }
  1127. void StringToWindowPlacement (LPTSTR lpszText,
  1128. PWINDOWPLACEMENT pWP)
  1129. { // StringToWindowPlacement
  1130. int iNumScanned ;
  1131. iNumScanned = swscanf (lpszText, TEXT("%d %d %d %d %d %d %d %d %d"),
  1132. &pWP->showCmd,
  1133. &pWP->ptMinPosition.x,
  1134. &pWP->ptMinPosition.y,
  1135. &pWP->ptMaxPosition.x,
  1136. &pWP->ptMaxPosition.y,
  1137. &pWP->rcNormalPosition.left,
  1138. &pWP->rcNormalPosition.top,
  1139. &pWP->rcNormalPosition.right,
  1140. &pWP->rcNormalPosition.bottom) ;
  1141. } // StringToWindowPlacement
  1142. #endif // KEEP_UTIL
  1143. int LogFontHeight (HDC hDC,
  1144. int iPointSize)
  1145. /*
  1146. Effect: Return the appropriate pixel height for the lfHeight
  1147. field of the LOGFONT structure for the requested point
  1148. size. This size depends on the number of pixels per
  1149. logical inch of the current display context, hDC.
  1150. Called By: Any function which wants to create a particular
  1151. point-height font.
  1152. */
  1153. { // LogFontHeight
  1154. return (-MulDiv (iPointSize, GetDeviceCaps (hDC, LOGPIXELSY), 72)) ;
  1155. } // LogFontHeight
  1156. // this routine converts the input menu id into help id.
  1157. DWORD MenuIDToHelpID (DWORD MenuID)
  1158. {
  1159. DWORD HelpID = 0 ;
  1160. if (MenuID >= IDM_FIRSTMENUID && MenuID <= IDM_LASTMENUID)
  1161. {
  1162. // only special cases...
  1163. if (MenuID >= IDM_OPTIONSREFRESHNOWCHART &&
  1164. MenuID <= IDM_OPTIONSREFRESHNOWREPORT)
  1165. {
  1166. HelpID = HC_PM_MENU_OPTIONSREFRESHNOW ;
  1167. }
  1168. else
  1169. {
  1170. HelpID = MenuID - MENUIDTOHELPID ;
  1171. }
  1172. #ifndef ADVANCED_PERFMON
  1173. // need to convert these 2 IDs for Perf. Meter
  1174. if (HelpID == HC_PM_MENU_HELPABOUT)
  1175. {
  1176. HelpID = HC_NTPM_MENU_HELPABOUT ;
  1177. }
  1178. else if (HelpID == HC_PM_MENU_FILEEXIT)
  1179. {
  1180. HelpID = HC_NTPM_MENU_FILEEXIT ;
  1181. }
  1182. #endif
  1183. }
  1184. return (HelpID) ;
  1185. }