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.

1658 lines
42 KiB

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