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.

2183 lines
61 KiB

  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include "perfmon.h"
  7. #include "addline.h"
  8. #include "alert.h" // for AlertInsertLine, AlertDeleteLine
  9. #include "grafdata.h" // for ChartInsertLine, ChartDeleteLine
  10. #include "graph.h" // for SizeGraphComponents
  11. #include "legend.h" // for LegendAddItem
  12. #include "line.h" // for LineAllocate, LineFree.
  13. #include "pmemory.h" // for MemoryXXX (mallloc-type) routines
  14. #include "perfdata.h" // for QueryPerformanceData
  15. #include "perfmops.h" // for dlg_error_box
  16. #include "playback.h" // for PlaybackLines
  17. #include "report.h" // for ReportInsertLine, ReportDeleteLine
  18. #include "system.h" // for SystemGet
  19. #include "utils.h"
  20. #include "playback.h" // for PlayingBackLog
  21. #include "counters.h"
  22. #include "pmhelpid.h" // Help IDs
  23. //==========================================================================//
  24. // Constants //
  25. //==========================================================================//
  26. #ifdef ADVANCED_PERFMON
  27. #define ADDLINEDETAILLEVEL PERF_DETAIL_WIZARD
  28. #else
  29. #define ADDLINEDETAILLEVEL PERF_DETAIL_NOVICE
  30. #endif
  31. #define iInitialExplainLen 256
  32. // defines used in owner-drawn items
  33. #define OWNER_DRAWN_ITEM 2
  34. #define OWNER_DRAW_FOCUS 1
  35. //==========================================================================//
  36. // Local Data //
  37. //==========================================================================//
  38. // defined in PerfData.c
  39. extern WCHAR NULL_NAME[] ;
  40. COLORREF argbColors[] =
  41. {
  42. RGB (0xff, 0x00, 0x00),
  43. RGB (0x00, 0x80, 0x00),
  44. RGB (0x00, 0x00, 0xff),
  45. RGB (0xff, 0xff, 0x00),
  46. RGB (0xff, 0x00, 0xff),
  47. RGB (0x00, 0xff, 0xff),
  48. RGB (0x80, 0x00, 0x00),
  49. RGB (0x40, 0x40, 0x40),
  50. RGB (0x00, 0x00, 0x80),
  51. RGB (0x80, 0x80, 0x00),
  52. RGB (0x80, 0x00, 0x80),
  53. RGB (0x00, 0x80, 0x80),
  54. RGB (0x40, 0x00, 0x00),
  55. RGB (0x00, 0x40, 0x00),
  56. RGB (0x00, 0x00, 0x40),
  57. RGB (0x00, 0x00, 0x00)
  58. } ;
  59. TCHAR *apszScaleFmt[] =
  60. {
  61. TEXT("%7.7f"),
  62. TEXT("%6.6f"),
  63. TEXT("%5.5f"),
  64. TEXT("%4.4f"),
  65. TEXT("%3.3f"),
  66. TEXT("%2.2f"),
  67. TEXT("%1.1f"),
  68. TEXT("%2.1f"),
  69. TEXT("%3.1f"),
  70. TEXT("%4.1f"),
  71. TEXT("%5.1f"),
  72. TEXT("%6.1f"),
  73. TEXT("%7.1f")
  74. } ;
  75. #define DEFAULT_SCALE 0
  76. #define NUMBER_OF_SCALE sizeof(apszScaleFmt)/sizeof(apszScaleFmt[0])
  77. int iLineType ;
  78. static PPERFDATA pPerfData ;
  79. PPERFSYSTEM pSystem ;
  80. PLINESTRUCT pLineEdit ;
  81. PPERFSYSTEM *ppSystemFirst ;
  82. PLINEVISUAL pVisual ;
  83. #define bEditLine (pLineEdit != NULL)
  84. BOOL ComputerChange ;
  85. LPTSTR pCurrentSystem ;
  86. //=============================//
  87. // Alert-related locals //
  88. //=============================//
  89. BOOL bAlertOver ; // over or under?
  90. FLOAT eAlertValue ; // value to compare
  91. BOOL bEveryTime ; // run every time or once?
  92. // program to run;
  93. LPTSTR pszAlertProgram ;
  94. //==========================================================================//
  95. // Macros //
  96. //==========================================================================//
  97. #define InChartAdd() \
  98. (iLineType == LineTypeChart)
  99. #define InAlertAdd() \
  100. (iLineType == LineTypeAlert)
  101. #define InReportAdd() \
  102. (iLineType == LineTypeReport)
  103. #define NumColorIndexes() \
  104. (sizeof (argbColors) / sizeof (argbColors[0]))
  105. #define NumWidthIndexes() 5
  106. #define NumStyleIndexes() 4
  107. //==========================================================================//
  108. // Forward Declarations //
  109. //==========================================================================//
  110. BOOL /*static*/ OnObjectChanged (HDLG hDlg) ;
  111. //==========================================================================//
  112. // Local Functions //
  113. //==========================================================================//
  114. PPERFINSTANCEDEF
  115. ParentInstance (
  116. PPERFINSTANCEDEF pInstance
  117. )
  118. {
  119. PPERFOBJECT parent_obj ;
  120. PPERFINSTANCEDEF parent_instance ;
  121. PERF_COUNTER_BLOCK *counter_blk;
  122. LONG i ;
  123. parent_obj =
  124. GetObjectDefByTitleIndex (pPerfData,
  125. pInstance->ParentObjectTitleIndex) ;
  126. if (!parent_obj)
  127. return (NULL) ;
  128. // Then get the parent instance.
  129. // NOTE: can use unique ID field to match here instead
  130. // of name compare.
  131. for (i = 0,
  132. parent_instance = (PPERFINSTANCEDEF ) ( (PBYTE)parent_obj
  133. + parent_obj->DefinitionLength);
  134. i < parent_obj->NumInstances;
  135. i++, parent_instance = (PPERFINSTANCEDEF ) ( (PBYTE)counter_blk
  136. + counter_blk->ByteLength))
  137. { // for
  138. counter_blk = (PERF_COUNTER_BLOCK *) ( (PBYTE)parent_instance
  139. + parent_instance->ByteLength);
  140. if ((DWORD)i == pInstance->ParentObjectInstance)
  141. return (parent_instance) ;
  142. }
  143. return (NULL) ;
  144. }
  145. PPERFOBJECT
  146. SelectedObject (
  147. HWND hWndObjects,
  148. LPTSTR lpszObjectName
  149. )
  150. /*
  151. Effect: Return the pObject associated with the currently selected
  152. combo-box item of hWndObjects. Set lpszObjectName to
  153. the object's name.
  154. If no item is selected in the combobox, return NULL.
  155. Assert: The pObject for each CB item was added when the string
  156. was added to the CB, by CBLoadObjects.
  157. See Also: LoadObjects.
  158. */
  159. {
  160. INT_PTR iIndex ;
  161. iIndex = CBSelection (hWndObjects) ;
  162. if (iIndex == CB_ERR)
  163. return (NULL) ;
  164. if (lpszObjectName)
  165. CBString (hWndObjects, iIndex, lpszObjectName) ;
  166. return ((PPERFOBJECT) CBData (hWndObjects, iIndex)) ;
  167. }
  168. PPERFCOUNTERDEF
  169. SelectedCounter (
  170. HWND hWndCounters,
  171. LPTSTR lpszCounterName
  172. )
  173. /*
  174. Effect: Return the pCounter associated with the currently selected
  175. LB item of hWndCounters. Set lpszCounterName to
  176. the Counter's name.
  177. If no item is selected in the listbox, return NULL.
  178. Assert: The pCounter for each LB item was added when the string
  179. was added to the LB, by LoadCounters.
  180. See Also: LoadCounters.
  181. */
  182. {
  183. INT_PTR iIndex ;
  184. iIndex = LBSelection (hWndCounters) ;
  185. if (iIndex == LB_ERR)
  186. return (NULL) ;
  187. if (lpszCounterName)
  188. LBString (hWndCounters, iIndex, lpszCounterName) ;
  189. return ((PPERFCOUNTERDEF) LBData (hWndCounters, iIndex)) ;
  190. }
  191. void
  192. VisualIncrement (
  193. PLINEVISUAL pVisual
  194. )
  195. /*
  196. Effect: Cycle through the combinations of color, width, and
  197. style to distinguish between lines. The color attributes
  198. are like a number:
  199. <style> <width> <color>
  200. Since color is the LSB, it is always incremented. The
  201. others are incremented whenever the color rolls over.
  202. If a current index is -1, that means don't increment
  203. that visual attribute.
  204. */
  205. {
  206. pVisual->iColorIndex =
  207. (pVisual->iColorIndex + 1) % NumColorIndexes () ;
  208. if (pVisual->iColorIndex)
  209. return ;
  210. if (pVisual->iWidthIndex == -1)
  211. return ;
  212. pVisual->iWidthIndex =
  213. (pVisual->iWidthIndex + 1) % NumWidthIndexes () ;
  214. if (pVisual->iWidthIndex)
  215. return ;
  216. if (pVisual->iStyleIndex == -1)
  217. return ;
  218. pVisual->iStyleIndex =
  219. (pVisual->iStyleIndex + 1) % NumStyleIndexes () ;
  220. }
  221. COLORREF
  222. LineColor (
  223. int iColorIndex
  224. )
  225. {
  226. return (argbColors [iColorIndex]) ;
  227. }
  228. int
  229. LineWidth (
  230. int iWidthIndex
  231. )
  232. {
  233. switch (iWidthIndex)
  234. { // switch
  235. case 0:
  236. return (1) ;
  237. break ;
  238. case 1:
  239. return (3) ;
  240. break ;
  241. case 2:
  242. return (5) ;
  243. break ;
  244. case 3:
  245. return (7) ;
  246. break ;
  247. case 4:
  248. return (9) ;
  249. break ;
  250. default:
  251. return (1) ;
  252. break ;
  253. } // switch
  254. }
  255. int
  256. LineStyle (
  257. int iStyleIndex
  258. )
  259. {
  260. return (iStyleIndex) ;
  261. }
  262. BOOL
  263. /*static*/
  264. LoadInstances (
  265. HDLG hDlg
  266. )
  267. {
  268. PPERFOBJECT pObject ;
  269. PPERFINSTANCEDEF pInstance, pInstanceParent ;
  270. TCHAR szInstance [256], szInstanceParent [256] ;
  271. TCHAR szCompositeName [256 * 2] ;
  272. TCHAR szInstCompositeName [256 * 2] ;
  273. LONG iInstance ;
  274. INT_PTR iIndex ;
  275. int xTextExtent = 0 ;
  276. int currentTextExtent ;
  277. HFONT hFont ;
  278. HDC hDC = 0 ;
  279. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  280. HWND hWndInstances = DialogControl (hDlg, IDD_ADDLINEINSTANCE);
  281. // turn off horiz. scrollbar
  282. LBSetHorzExtent (hWndInstances, 0) ;
  283. LBReset (hWndInstances) ;
  284. pObject = SelectedObject (hWndObjects, NULL) ;
  285. if (!pObject)
  286. return (FALSE) ;
  287. if (pObject->NumInstances <= 0)
  288. {
  289. MLBSetSelection (hWndInstances, 0, TRUE) ;
  290. return (FALSE) ;
  291. }
  292. // turn off Listbox redraw
  293. LBSetRedraw (hWndInstances, FALSE) ;
  294. memset(szInstance, 0, sizeof(TCHAR) * 256);
  295. memset(szInstanceParent, 0, sizeof(TCHAR) * 256);
  296. szCompositeName[0] = szInstCompositeName[0] = 0;
  297. if (bEditLine)
  298. {
  299. if (pLineEdit->lnObject.NumInstances > 0)
  300. {
  301. if (pLineEdit->lnInstanceDef.ParentObjectTitleIndex)
  302. {
  303. // Get the Parent Object Instance Name.
  304. // and prefix it to the Instance Name, to make
  305. // the string we want to display.
  306. TSPRINTF (szInstCompositeName,
  307. TEXT("%s ==> %s"),
  308. pLineEdit->lnPINName,
  309. pLineEdit->lnInstanceName) ;
  310. }
  311. else
  312. {
  313. lstrcpy (szInstCompositeName, pLineEdit->lnInstanceName) ;
  314. }
  315. }
  316. else
  317. {
  318. szInstCompositeName[0] = TEXT('\0');
  319. }
  320. }
  321. if (!bEditLine && (hDC = GetDC (hWndInstances)))
  322. {
  323. hFont = (HFONT)SendMessage(hWndInstances, WM_GETFONT, 0, 0L);
  324. if (hFont)
  325. SelectObject(hDC, hFont);
  326. }
  327. for (iInstance = 0, pInstance = FirstInstance (pObject) ;
  328. iInstance < pObject->NumInstances;
  329. iInstance++, pInstance = NextInstance (pInstance))
  330. { // for
  331. strclr(szInstance);
  332. GetInstanceNameStr (pInstance, szInstance, pObject->CodePage) ;
  333. pInstanceParent = ParentInstance (pInstance) ;
  334. if (pInstanceParent)
  335. {
  336. strclr(szInstanceParent);
  337. GetInstanceNameStr (pInstanceParent, szInstanceParent, pObject->CodePage);
  338. TSPRINTF (szCompositeName, TEXT("%s ==> %s"),
  339. szInstanceParent, szInstance) ;
  340. }
  341. else
  342. lstrcpy (szCompositeName, szInstance) ;
  343. iIndex = LBAdd (hWndInstances, szCompositeName) ;
  344. if (iIndex != LB_ERR)
  345. {
  346. LBSetData (hWndInstances, iIndex, (LPARAM) pInstance) ;
  347. }
  348. // get the biggest text width
  349. if (hDC)
  350. {
  351. currentTextExtent = TextWidth (hDC, szCompositeName) + xScrollWidth / 2 ;
  352. if (currentTextExtent > xTextExtent)
  353. {
  354. xTextExtent = currentTextExtent ;
  355. }
  356. }
  357. } // for
  358. if (hDC)
  359. {
  360. // turn on horiz. scrollbar if necessary...
  361. LBSetHorzExtent (hWndInstances, xTextExtent) ;
  362. ReleaseDC (hWndInstances, hDC) ;
  363. }
  364. if (!bEditLine || szInstCompositeName[0] == TEXT('\0'))
  365. {
  366. MLBSetSelection (hWndInstances, 0, TRUE) ;
  367. }
  368. else
  369. {
  370. BOOL bSetSelection = TRUE ;
  371. iIndex = LBFind (hWndInstances, szInstCompositeName) ;
  372. if (iIndex == LB_ERR)
  373. {
  374. if (bEditLine)
  375. {
  376. bSetSelection = FALSE ;
  377. }
  378. iIndex = 0 ;
  379. }
  380. if (bSetSelection)
  381. {
  382. MLBSetSelection (hWndInstances, iIndex, TRUE) ;
  383. }
  384. LBSetVisible (hWndInstances, iIndex) ;
  385. }
  386. // turn on Listbox redraw
  387. LBSetRedraw (hWndInstances, TRUE) ;
  388. return TRUE;
  389. }
  390. BOOL
  391. OnCounterChanged (
  392. HDLG hDlg
  393. )
  394. /*
  395. Effect: Perform any actions necessary when the counter has changed.
  396. In particular, display the explanation for the counter
  397. that has the focus rectangle.
  398. */
  399. {
  400. LPTSTR lpszText ;
  401. PPERFCOUNTERDEF pCounter ;
  402. int iStatus ;
  403. INT_PTR iFocusIndex ;
  404. HWND hWndCounters = DialogControl (hDlg, IDD_ADDLINECOUNTER);
  405. HWND hWndScales = DialogControl (hDlg, IDD_ADDLINESCALE) ;
  406. iFocusIndex = LBFocus (hWndCounters) ;
  407. if (iFocusIndex == LB_ERR)
  408. return (FALSE) ;
  409. if (PlayingBackLog())
  410. {
  411. DialogEnable (hDlg, IDD_ADDLINEEXPANDEXPLAIN, FALSE) ;
  412. return (TRUE) ;
  413. }
  414. pCounter = (PPERFCOUNTERDEF) LBData (hWndCounters, iFocusIndex) ;
  415. if ((!pCounter) || (pCounter == (PPERFCOUNTERDEF)LB_ERR))
  416. return (FALSE) ;
  417. // no need to get help text before the button is clicked
  418. if (!bExplainTextButtonHit)
  419. return (FALSE) ;
  420. // Create initial string
  421. lpszText = MemoryAllocate (iInitialExplainLen * sizeof (TCHAR)) ;
  422. if (!lpszText)
  423. return (FALSE) ;
  424. while (TRUE)
  425. {
  426. lpszText[0] = TEXT('\0') ;
  427. #ifdef UNICODE
  428. iStatus = QueryPerformanceName (pSystem,
  429. pCounter->CounterHelpTitleIndex,
  430. iLanguage,
  431. MemorySize (lpszText) / sizeof(TCHAR),
  432. lpszText,
  433. TRUE) ;
  434. #else
  435. iStatus = QueryPerformanceNameW (pSystem,
  436. pCounter->CounterHelpTitleIndex,
  437. iLanguage,
  438. MemorySize (lpszText),
  439. lpszText,
  440. TRUE) ;
  441. #endif
  442. if (iStatus == ERROR_SUCCESS)
  443. break ;
  444. if (iStatus == ERROR_MORE_DATA)
  445. lpszText =
  446. MemoryResize (lpszText,
  447. MemorySize (lpszText) + iInitialExplainLen) ;
  448. else
  449. break ;
  450. } // while
  451. // Don't use my DialogSetString, it won't handle such large strings.
  452. SetDlgItemText (hDlg, IDD_ADDLINEEXPLAIN, lpszText) ;
  453. MemoryFree (lpszText) ;
  454. return (TRUE) ;
  455. }
  456. BOOL
  457. LoadCounters (
  458. HDLG hDlg,
  459. UINT iSelectCounterDefn
  460. )
  461. {
  462. PPERFOBJECT pObject ;
  463. TCHAR szCounterName [256] ;
  464. TCHAR szDefaultCounterName [256] ;
  465. PPERFCOUNTERDEF pCounter ;
  466. UINT i ;
  467. INT_PTR iIndex ;
  468. int xTextExtent = 0 ;
  469. int currentTextExtent ;
  470. HFONT hFont ;
  471. HDC hDC = 0 ;
  472. BOOL bSetSelection = TRUE ;
  473. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  474. HWND hWndCounters = DialogControl (hDlg, IDD_ADDLINECOUNTER);
  475. strclr (szDefaultCounterName) ;
  476. // turn off horiz. scrollbar
  477. LBSetHorzExtent (hWndCounters, 0) ;
  478. LBReset (hWndCounters) ;
  479. pObject = SelectedObject (hWndObjects, NULL) ;
  480. if (!pObject)
  481. return (FALSE) ;
  482. if (!bEditLine && (hDC = GetDC (hWndCounters)))
  483. {
  484. hFont = (HFONT)SendMessage(hWndCounters, WM_GETFONT, 0, 0L);
  485. if (hFont)
  486. SelectObject(hDC, hFont);
  487. }
  488. memset(szCounterName, 0, sizeof(TCHAR) * 256);
  489. memset(szDefaultCounterName, 0, sizeof(TCHAR) * 256);
  490. // turn off Listbox redraw
  491. LBSetRedraw (hWndCounters, FALSE) ;
  492. for (i = 0, pCounter = FirstCounter (pObject) ;
  493. i < pObject->NumCounters ;
  494. i++, pCounter = NextCounter (pCounter))
  495. { // for
  496. if (IsCounterSupported(pCounter->CounterType))
  497. { // if
  498. szCounterName[0] = TEXT('\0') ;
  499. QueryPerformanceName (pSystem,
  500. pCounter->CounterNameTitleIndex,
  501. 0, sizeof (szCounterName) / sizeof(TCHAR),
  502. szCounterName,
  503. FALSE) ;
  504. // if szCounterName is not empty, add it to the listbox
  505. if (!strsame(szCounterName, NULL_NAME))
  506. {
  507. iIndex = LBAdd (hWndCounters, szCounterName) ;
  508. LBSetData (hWndCounters, iIndex, (DWORD_PTR) pCounter) ;
  509. // get the biggest text width
  510. if (hDC)
  511. {
  512. currentTextExtent = TextWidth (hDC, szCounterName) + xScrollWidth / 2 ;
  513. if (currentTextExtent > xTextExtent)
  514. {
  515. xTextExtent = currentTextExtent ;
  516. }
  517. }
  518. if (iSelectCounterDefn == i)
  519. lstrcpy (szDefaultCounterName, szCounterName) ;
  520. } // if szCounterName is not empty
  521. } // if
  522. } // for
  523. if (bEditLine)
  524. lstrcpy (szDefaultCounterName, pLineEdit->lnCounterName) ;
  525. iIndex = LBFind (hWndCounters, szDefaultCounterName) ;
  526. if (iIndex == LB_ERR)
  527. {
  528. if (bEditLine)
  529. {
  530. bSetSelection = FALSE ;
  531. }
  532. iIndex = 0 ;
  533. }
  534. if (bSetSelection)
  535. {
  536. MLBSetSelection (hWndCounters, iIndex, TRUE) ;
  537. }
  538. LBSetVisible (hWndCounters, iIndex) ;
  539. if (hDC)
  540. {
  541. // turn on horiz. scrollbar if necessary...
  542. LBSetHorzExtent (hWndCounters, xTextExtent) ;
  543. ReleaseDC (hWndCounters, hDC) ;
  544. }
  545. // turn on Listbox redraw
  546. LBSetRedraw (hWndCounters, TRUE) ;
  547. OnCounterChanged (hDlg) ;
  548. return TRUE;
  549. } // LoadCounters
  550. void
  551. LoadObjects (
  552. HDLG hDlg,
  553. PPERFDATA pPerfData
  554. )
  555. /*
  556. Effect: Load into the object CB the objects for the current
  557. pPerfData.
  558. */
  559. {
  560. LPTSTR lpszObject ;
  561. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  562. lpszObject = bEditLine ? pLineEdit->lnObjectName : NULL ;
  563. CBLoadObjects (hWndObjects,
  564. pPerfData,
  565. pSystem,
  566. ADDLINEDETAILLEVEL,
  567. lpszObject,
  568. FALSE) ;
  569. OnObjectChanged (hDlg) ;
  570. // UpdateWindow (hDlg) ;
  571. }
  572. void
  573. OnComputerChanged (
  574. HDLG hDlg
  575. )
  576. {
  577. PPERFSYSTEM pLocalSystem;
  578. PPERFDATA pLocalPerfData;
  579. pLocalPerfData = pPerfData;
  580. pLocalSystem = GetComputer (hDlg,
  581. IDD_ADDLINECOMPUTER,
  582. TRUE,
  583. &pLocalPerfData,
  584. ppSystemFirst) ;
  585. if (pLocalSystem && pLocalPerfData)
  586. {
  587. pSystem = pLocalSystem;
  588. pPerfData = pLocalPerfData;
  589. LoadObjects (hDlg, pPerfData) ;
  590. ComputerChange = FALSE ;
  591. }
  592. SetArrowCursor();
  593. }
  594. BOOL
  595. AddOneChartLine (
  596. HWND hDlg,
  597. PPERFCOUNTERDEF pCounter,
  598. LPTSTR lpszCounter,
  599. PPERFINSTANCEDEF pInstance,
  600. BOOL bInsertObject
  601. )
  602. {
  603. TCHAR szComputer [MAX_SYSTEM_NAME_LENGTH] ;
  604. PPERFOBJECT pObject ;
  605. TCHAR szObject [PerfObjectLen] ;
  606. TCHAR szInstance [256] ;
  607. PLINE pLine ;
  608. // int i ;
  609. int iCounterIndex ;
  610. int j ;
  611. PPERFINSTANCEDEF pInstanceParent ;
  612. PERF_COUNTER_BLOCK *pCounterBlock ;
  613. TCHAR szInstanceParent [256] ;
  614. TCHAR szObjectParent [256] ;
  615. HWND hWndColors = DialogControl (hDlg, IDD_ADDLINECOLOR) ;
  616. HWND hWndWidths = DialogControl (hDlg, IDD_ADDLINEWIDTH) ;
  617. HWND hWndStyles = DialogControl (hDlg, IDD_ADDLINESTYLE) ;
  618. HWND hWndScales = DialogControl (hDlg, IDD_ADDLINESCALE) ;
  619. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  620. BOOL bFail;
  621. //=============================//
  622. // Get selected data values //
  623. //=============================//
  624. memset(szInstance, 0, sizeof(TCHAR) * 256);
  625. DialogText (hDlg, IDD_ADDLINECOMPUTER, szComputer) ;
  626. pObject = SelectedObject (hWndObjects, szObject) ;
  627. if (!pObject)
  628. return (FALSE) ;
  629. if (pInstance)
  630. GetInstanceNameStr (pInstance, szInstance, pObject->CodePage);
  631. //=============================//
  632. // Allocate the line //
  633. //=============================//
  634. bFail = FALSE;
  635. pLine = LineAllocate () ;
  636. if (pLine) {
  637. //=============================//
  638. // Set line's data values //
  639. //=============================//
  640. pLine->iLineType = iLineType ;
  641. pLine->lnSystemName = StringAllocate (szComputer) ;
  642. if (pLine->lnSystemName == NULL)
  643. bFail = TRUE;
  644. pLine->lnObject = *pObject ;
  645. pLine->lnObjectName = StringAllocate (szObject) ;
  646. if (pLine->lnObjectName == NULL) {
  647. bFail = TRUE;
  648. MemoryFree(pLine->lnSystemName);
  649. }
  650. pLine->lnCounterDef = *pCounter ;
  651. pLine->lnCounterName = StringAllocate (lpszCounter) ;
  652. if (pLine->lnCounterName == NULL) {
  653. bFail = TRUE;
  654. MemoryFree(pLine->lnSystemName);
  655. MemoryFree(pLine->lnObjectName);
  656. }
  657. }
  658. if (!pLine || bFail)
  659. {
  660. DlgErrorBox (hDlg, ERR_NO_MEMORY);
  661. return (FALSE) ;
  662. }
  663. if (pObject->NumInstances > 0 && pInstance)
  664. {
  665. pLine->lnInstanceDef = *pInstance ;
  666. pLine->lnInstanceName = StringAllocate (szInstance) ;
  667. pLine->lnUniqueID = pInstance->UniqueID ;
  668. pLine->dwInstanceIndex = 0;
  669. if (pInstance->ParentObjectTitleIndex)
  670. {
  671. szObjectParent[0] = (TCHAR)'\0';
  672. QueryPerformanceName (pSystem,
  673. pInstance->ParentObjectTitleIndex,
  674. 0, PerfObjectLen, szObjectParent, FALSE) ;
  675. pLine->lnParentObjName = StringAllocate (szObjectParent) ;
  676. }
  677. pInstanceParent = ParentInstance (pInstance) ;
  678. if (pInstanceParent)
  679. {
  680. GetInstanceNameStr (pInstanceParent, szInstanceParent,
  681. pObject->CodePage);
  682. if (pInstance->ParentObjectTitleIndex)
  683. {
  684. pLine->lnPINName = StringAllocate (szInstanceParent) ;
  685. }
  686. }
  687. } // if
  688. pLine->lnCounterType = pCounter->CounterType;
  689. pLine->lnCounterLength = pCounter->CounterSize;
  690. pLine->lnOldTime = pPerfData->PerfTime ;
  691. pLine->lnNewTime = pPerfData->PerfTime ;
  692. for (j = 0 ; j < 2 ; j++)
  693. {
  694. pLine->lnaCounterValue[j].LowPart = 0 ;
  695. pLine->lnaCounterValue[j].HighPart = 0 ;
  696. }
  697. //=============================//
  698. // Chart-related Values //
  699. //=============================//
  700. pLine->iScaleIndex = (int)CBSelection (hWndScales) ;
  701. if (pLine->iScaleIndex == 0)
  702. {
  703. // use the default scale
  704. pLine->eScale = (FLOAT) pow ((double)10.0,
  705. (double)pCounter->DefaultScale) ;
  706. }
  707. else
  708. {
  709. pLine->eScale = DialogFloat (hDlg, IDD_ADDLINESCALE, NULL) ;
  710. }
  711. if (pObject->NumInstances > 0 && pInstance)
  712. {
  713. pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pInstance +
  714. pInstance->ByteLength);
  715. }
  716. else
  717. {
  718. pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pObject +
  719. pObject->DefinitionLength);
  720. }
  721. if (pLine->lnCounterLength <= 4)
  722. pLine->lnaOldCounterValue[0].LowPart =
  723. * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  724. pCounter[0].CounterOffset));
  725. else
  726. {
  727. pLine->lnaOldCounterValue[0] =
  728. * ( (LARGE_INTEGER UNALIGNED *) ( (PBYTE)pCounterBlock +
  729. pCounter[0].CounterOffset));
  730. }
  731. // Get second counter, only if we are not at
  732. // the end of the counters; some computations
  733. // require a second counter
  734. iCounterIndex = CounterIndex (pCounter, (PPERFOBJECT) pObject) ;
  735. if ((UINT) iCounterIndex < pObject->NumCounters - 1 &&
  736. iCounterIndex != -1)
  737. {
  738. if (pLine->lnCounterLength <= 4)
  739. pLine->lnaOldCounterValue[1].LowPart =
  740. * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  741. pCounter[1].CounterOffset));
  742. else
  743. pLine->lnaOldCounterValue[1] =
  744. * ( (LARGE_INTEGER UNALIGNED *) ( (PBYTE)pCounterBlock +
  745. pCounter[1].CounterOffset));
  746. }
  747. pLine->lnaOldCounterValue[0] = pLine->lnaCounterValue[0];
  748. pLine->lnaOldCounterValue[1] = pLine->lnaCounterValue[1];
  749. //=============================//
  750. // Visual Values //
  751. //=============================//
  752. pLine->Visual.iColorIndex = (int)CBSelection (hWndColors) ;
  753. pLine->Visual.crColor = LineColor (pLine->Visual.iColorIndex) ;
  754. pLine->Visual.iWidthIndex = (int)CBSelection (hWndWidths) ;
  755. pLine->Visual.iWidth = LineWidth (pLine->Visual.iWidthIndex) ;
  756. pLine->Visual.iStyleIndex = (int)CBSelection (hWndStyles) ;
  757. pLine->Visual.iStyle = LineStyle (pLine->Visual.iStyleIndex) ;
  758. *pVisual = pLine->Visual ;
  759. if (!bEditLine)
  760. VisualIncrement (pVisual) ;
  761. CBSetSelection (hWndColors, pVisual->iColorIndex) ;
  762. CBSetSelection (hWndWidths, pVisual->iWidthIndex) ;
  763. CBSetSelection (hWndStyles, pVisual->iStyleIndex) ;
  764. if (iLineType == LineTypeChart)
  765. {
  766. pLine->hPen = LineCreatePen (NULL, &(pLine->Visual), FALSE) ;
  767. }
  768. //=============================//
  769. // Alert Related Values //
  770. //=============================//
  771. if (iLineType == LineTypeAlert)
  772. {
  773. pLine->bAlertOver = bAlertOver ;
  774. pLine->eAlertValue = eAlertValue ;
  775. pLine->bEveryTime =
  776. IsDlgButtonChecked (hDlg, IDD_ADDLINEPROGRAMEVERYTIME) ;
  777. pLine->bAlerted = FALSE ;
  778. pLine->hBrush = CreateSolidBrush (pLine->Visual.crColor) ;
  779. if (!PlayingBackLog ())
  780. {
  781. pLine->lpszAlertProgram = StringAllocate (pszAlertProgram) ;
  782. }
  783. else
  784. {
  785. pLine->lpszAlertProgram = NULL ;
  786. }
  787. }
  788. //=============================//
  789. // Insert the line! //
  790. //=============================//
  791. if (InsertLine (pLine) == FALSE)
  792. {
  793. // no inert occurred due to either line already existed
  794. // or error detected.
  795. LineFree (pLine) ;
  796. }
  797. else
  798. {
  799. if (pSystem->lpszValue && pSystem->FailureTime == 0)
  800. {
  801. if (bInsertObject) {
  802. if (strsame(pSystem->lpszValue, TEXT("Global")))
  803. {
  804. // take out the "Global" string
  805. *(pSystem->lpszValue) = 0 ;
  806. }
  807. AppendObjectToValueList (
  808. pLine->lnObject.ObjectNameTitleIndex,
  809. pSystem->lpszValue) ;
  810. }
  811. }
  812. }
  813. return TRUE;
  814. }
  815. BOOL AddCounter (HWND hDlg,
  816. PPERFCOUNTERDEF pCounter,
  817. LPTSTR lpszCounter)
  818. {
  819. int iInstanceIndex ;
  820. int iInstanceNum ;
  821. PPERFINSTANCEDEF pInstance ;
  822. PPERFOBJECT pObject;
  823. HWND hWndInstances = DialogControl (hDlg, IDD_ADDLINEINSTANCE);
  824. HWND hWndObjects;
  825. BOOL bInsertObject = TRUE;
  826. int nResult;
  827. // NOTE: for now, we don't check for duplicate lines
  828. if (!IsCounterSupported (pCounter->CounterType))
  829. {
  830. DlgErrorBox (hDlg, ERR_COUNTER_NOT_IMP);
  831. return (FALSE) ;
  832. }
  833. if ((iInstanceNum = LBNumItems (hWndInstances)) && iInstanceNum != LB_ERR)
  834. {
  835. if (iInstanceNum > 1)
  836. {
  837. // delay some of the insert actions for performacne improvement
  838. bDelayAddAction = TRUE ;
  839. if (InChartAdd())
  840. {
  841. LegendSetRedraw (hWndGraphLegend, FALSE) ;
  842. }
  843. else if (InAlertAdd())
  844. {
  845. LegendSetRedraw (hWndAlertLegend, FALSE) ;
  846. }
  847. }
  848. for (iInstanceIndex = 0 ;
  849. iInstanceIndex < iInstanceNum ;
  850. iInstanceIndex++)
  851. { // for
  852. nResult = LBSelected (hWndInstances, iInstanceIndex);
  853. if ((nResult != LB_ERR) && (nResult != 0))
  854. { // if
  855. pInstance = (PPERFINSTANCEDEF) LBData (hWndInstances, iInstanceIndex) ;
  856. if (pInstance == (PPERFINSTANCEDEF) LB_ERR)
  857. {
  858. pInstance = NULL;
  859. }
  860. AddOneChartLine (hDlg, pCounter, lpszCounter, pInstance, bInsertObject) ;
  861. bInsertObject = FALSE; // for all subsequent calls
  862. } // if
  863. } // for
  864. if (bDelayAddAction)
  865. {
  866. // now do the post add-line actions
  867. bDelayAddAction = FALSE ;
  868. if (InReportAdd())
  869. {
  870. PREPORT pReport ;
  871. pReport = ReportData (hWndReport) ;
  872. ReportAddAction (pReport);
  873. }
  874. else if (InChartAdd())
  875. {
  876. GraphAddAction () ;
  877. LegendSetRedraw (hWndGraphLegend, TRUE) ;
  878. }
  879. else if (InAlertAdd())
  880. {
  881. AlertAddAction () ;
  882. LegendSetRedraw (hWndAlertLegend, TRUE) ;
  883. }
  884. }
  885. }
  886. else
  887. {
  888. // the list box could be empty for 2 reasons:
  889. // there are no instances and could be or
  890. // there is one and only one instance. Find out which
  891. hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  892. pObject = SelectedObject (hWndObjects, NULL) ;
  893. if (!pObject)
  894. return (FALSE) ;
  895. if (pObject->NumInstances == PERF_NO_INSTANCES)
  896. {
  897. // then there is one and only one, so add it
  898. pInstance = NULL;
  899. AddOneChartLine (hDlg, pCounter, lpszCounter, pInstance, bInsertObject) ;
  900. }
  901. else
  902. {
  903. // there are no instances of this object so don't add anything
  904. return (FALSE);
  905. }
  906. }
  907. return (TRUE) ;
  908. }
  909. //==========================================================================//
  910. // Message Handlers //
  911. //==========================================================================//
  912. BOOL
  913. /*static*/
  914. OnInitDialog (
  915. HWND hDlg
  916. )
  917. {
  918. int i ;
  919. FLOAT ScaleFactor ;
  920. TCHAR tempBuff[ShortTextLen] ;
  921. TCHAR szCaption [WindowCaptionLen] ;
  922. TCHAR szRemoteComputerName[MAX_PATH + 3] ;
  923. HWND hWndComputer = DialogControl (hDlg, IDD_ADDLINECOMPUTER);
  924. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  925. HWND hWndInstances = DialogControl (hDlg, IDD_ADDLINEINSTANCE);
  926. HWND hWndCounters = DialogControl (hDlg, IDD_ADDLINECOUNTER);
  927. HWND hWndColors = DialogControl (hDlg, IDD_ADDLINECOLOR) ;
  928. HWND hWndWidths = DialogControl (hDlg, IDD_ADDLINEWIDTH) ;
  929. HWND hWndStyles = DialogControl (hDlg, IDD_ADDLINESTYLE) ;
  930. HWND hWndScales = DialogControl (hDlg, IDD_ADDLINESCALE) ;
  931. // this is used to tell UPdateLines not to mark any
  932. // system as not used
  933. bAddLineInProgress = TRUE ;
  934. // turn this off until the Explain text button is clicked
  935. bExplainTextButtonHit = FALSE ;
  936. if (InAlertAdd())
  937. {
  938. pszAlertProgram = (LPTSTR) MemoryAllocate (FilePathLen * sizeof (TCHAR)) ;
  939. }
  940. if (!PlayingBackLog ())
  941. pPerfData = MemoryAllocate (STARTING_SYSINFO_SIZE) ;
  942. pSystem = NULL ;
  943. if (!bEditLine && PlayingBackLog())
  944. {
  945. pPerfData = DataFromIndexPosition (&(PlaybackLog.StartIndexPos), NULL) ;
  946. GetPerfComputerName(pPerfData, szRemoteComputerName);
  947. DialogSetString (hDlg, IDD_ADDLINECOMPUTER, szRemoteComputerName);
  948. }
  949. else
  950. {
  951. if (bEditLine)
  952. {
  953. DialogSetString (hDlg, IDD_ADDLINECOMPUTER,
  954. pLineEdit->lnSystemName) ;
  955. }
  956. else
  957. {
  958. //Try to use current system (if any), otherwise computer specified on commandline (if any),
  959. //otherwise local computer
  960. DialogSetString (hDlg, IDD_ADDLINECOMPUTER,
  961. pCurrentSystem ?
  962. pCurrentSystem :
  963. (( CmdLineComputerName[0] ) ?
  964. CmdLineComputerName :
  965. LocalComputerName )) ;
  966. }
  967. }
  968. OnComputerChanged (hDlg) ;
  969. //=============================//
  970. // Set default line values //
  971. //=============================//
  972. bAlertOver = bEditLine ? pLineEdit->bAlertOver : TRUE ;
  973. bEveryTime = bEditLine ? pLineEdit->bEveryTime : TRUE ;
  974. //=============================//
  975. // Fill line attribute CBs //
  976. //=============================//
  977. // Load the colors combobox, select the default color.
  978. for (i = 0 ; i < NumColorIndexes () ; i++)
  979. CBAdd (hWndColors, IntToPtr(i)) ;
  980. CBSetSelection (hWndColors, pVisual->iColorIndex) ;
  981. // Load the widths combobox, select the default width.
  982. for (i = 0 ; i < NumWidthIndexes () ; i++)
  983. CBAdd (hWndWidths, IntToPtr(i)) ;
  984. CBSetSelection (hWndWidths, pVisual->iWidthIndex) ;
  985. // Load the styles combobox, select the default style.
  986. for (i = 0 ; i < NumStyleIndexes () ; i++)
  987. CBAdd (hWndStyles, IntToPtr(i)) ;
  988. CBSetSelection (hWndStyles, pVisual->iStyleIndex) ;
  989. #if (!WIDESTYLES)
  990. DialogEnable (hDlg, IDD_ADDLINESTYLE, pVisual->iWidthIndex == 0) ;
  991. DialogEnable (hDlg, IDD_ADDLINESTYLETEXT, pVisual->iWidthIndex == 0) ;
  992. if (pVisual->iWidthIndex == 0 && pVisual->iStyleIndex > 0)
  993. {
  994. DialogEnable (hDlg, IDD_ADDLINEWIDTHTEXT, FALSE) ;
  995. DialogEnable (hDlg, IDD_ADDLINEWIDTH, FALSE) ;
  996. }
  997. #endif
  998. // Init the scale combo box.
  999. StringLoad (IDS_DEFAULT, tempBuff) ;
  1000. CBAdd (hWndScales, tempBuff) ;
  1001. // we are formatting the scale factors during run-time so
  1002. // the c-runtime library will pick up the default locale
  1003. // decimal "charatcer".
  1004. ScaleFactor = (FLOAT)0.0000001 ;
  1005. for (i = 0 ; i < NUMBER_OF_SCALE ; i++)
  1006. {
  1007. TSPRINTF(tempBuff, apszScaleFmt[i], ScaleFactor) ;
  1008. ConvertDecimalPoint (tempBuff) ;
  1009. ScaleFactor *= (FLOAT) 10.0 ;
  1010. CBAdd (hWndScales, tempBuff) ;
  1011. }
  1012. CBSetSelection (hWndScales, bEditLine ? pLineEdit->iScaleIndex : DEFAULT_SCALE) ;
  1013. CheckRadioButton (hDlg, IDD_ADDLINEIFOVER, IDD_ADDLINEIFUNDER,
  1014. bAlertOver ? IDD_ADDLINEIFOVER: IDD_ADDLINEIFUNDER) ;
  1015. CheckRadioButton (hDlg, IDD_ADDLINEPROGRAMFIRSTTIME, IDD_ADDLINEPROGRAMEVERYTIME,
  1016. bEveryTime ? IDD_ADDLINEPROGRAMEVERYTIME: IDD_ADDLINEPROGRAMFIRSTTIME) ;
  1017. if (bEditLine)
  1018. {
  1019. DialogSetText (hDlg, IDD_ADDLINEADD, IDS_OK) ;
  1020. DialogSetFloat (hDlg, IDD_ADDLINEIFVALUE, pLineEdit->eAlertValue) ;
  1021. if (pLineEdit->lpszAlertProgram)
  1022. DialogSetString (hDlg, IDD_ADDLINEPROGRAM,
  1023. pLineEdit->lpszAlertProgram) ;
  1024. DialogEnable (hDlg, IDD_ADDLINECOMPUTERTEXT, FALSE) ;
  1025. DialogEnable (hDlg, IDD_ADDLINECOMPUTER, FALSE) ;
  1026. DialogEnable (hDlg, IDD_ADDLINEELLIPSES, FALSE) ;
  1027. DialogEnable (hDlg, IDD_ADDLINEOBJECTTEXT, FALSE) ;
  1028. DialogEnable (hDlg, IDD_ADDLINEOBJECT, FALSE) ;
  1029. DialogEnable (hDlg, IDD_ADDLINECOUNTERTEXT, FALSE) ;
  1030. DialogEnable (hDlg, IDD_ADDLINECOUNTER, FALSE) ;
  1031. DialogEnable (hDlg, IDD_ADDLINEINSTANCE, FALSE) ;
  1032. DialogEnable (hDlg, IDD_ADDLINEINSTANCETEXT, FALSE) ;
  1033. }
  1034. else
  1035. {
  1036. // set the scroll limit on the edit box
  1037. EditSetLimit (GetDlgItem(hDlg, IDD_CHOOSECOMPUTERNAME),
  1038. MAX_SYSTEM_NAME_LENGTH-1) ;
  1039. }
  1040. if (PlayingBackLog())
  1041. {
  1042. DialogEnable (hDlg, IDD_ADDLINEEXPANDEXPLAIN, FALSE) ;
  1043. }
  1044. //=============================//
  1045. // LineType specific init //
  1046. //=============================//
  1047. switch (iLineType)
  1048. {
  1049. case LineTypeChart:
  1050. dwCurrentDlgID = bEditLine ?
  1051. HC_PM_idDlgEditChartLine : HC_PM_idDlgEditAddToChart ;
  1052. StringLoad (bEditLine ?
  1053. IDS_EDITCHART : IDS_ADDTOCHART, szCaption) ;
  1054. DialogShow (hDlg, IDD_ADDLINEIFGROUP, FALSE) ;
  1055. DialogShow (hDlg, IDD_ADDLINEIFVALUE, FALSE) ;
  1056. DialogShow (hDlg, IDD_ADDLINEIFUNDER, FALSE) ;
  1057. DialogShow (hDlg, IDD_ADDLINEIFOVER, FALSE) ;
  1058. DialogShow (hDlg, IDD_ADDLINEPROGRAMGROUP, FALSE) ;
  1059. DialogShow (hDlg, IDD_ADDLINEPROGRAM, FALSE) ;
  1060. DialogShow (hDlg, IDD_ADDLINEPROGRAMFIRSTTIME, FALSE) ;
  1061. DialogShow (hDlg, IDD_ADDLINEPROGRAMEVERYTIME, FALSE) ;
  1062. break ;
  1063. case LineTypeAlert:
  1064. dwCurrentDlgID = bEditLine ?
  1065. HC_PM_idDlgEditAlertEntry : HC_PM_idDlgEditAddToAlert ;
  1066. StringLoad (bEditLine ?
  1067. IDS_EDITALERT : IDS_ADDTOALERT, szCaption) ;
  1068. DialogShow (hDlg, IDD_ADDLINESCALE, FALSE) ;
  1069. DialogShow (hDlg, IDD_ADDLINESCALETEXT, FALSE) ;
  1070. DialogShow (hDlg, IDD_ADDLINEWIDTH, FALSE) ;
  1071. DialogShow (hDlg, IDD_ADDLINEWIDTHTEXT, FALSE) ;
  1072. DialogShow (hDlg, IDD_ADDLINESTYLE, FALSE) ;
  1073. DialogShow (hDlg, IDD_ADDLINESTYLETEXT, FALSE) ;
  1074. if (PlayingBackLog ())
  1075. {
  1076. DialogEnable (hDlg, IDD_ADDLINEPROGRAM, FALSE) ;
  1077. DialogEnable (hDlg, IDD_ADDLINEPROGRAMGROUP, FALSE) ;
  1078. DialogEnable (hDlg, IDD_ADDLINEPROGRAMEVERYTIME, FALSE) ;
  1079. DialogEnable (hDlg, IDD_ADDLINEPROGRAMFIRSTTIME, FALSE) ;
  1080. }
  1081. // set the scroll limit on the edit boxes
  1082. EditSetLimit (GetDlgItem(hDlg, IDD_ADDLINEIFVALUE), ShortTextLen) ;
  1083. EditSetLimit (GetDlgItem(hDlg, IDD_ADDLINEPROGRAM), FilePathLen-1) ;
  1084. break ;
  1085. case LineTypeReport:
  1086. dwCurrentDlgID = HC_PM_idDlgEditAddToReport ;
  1087. StringLoad (bEditLine ?
  1088. IDS_EDITREPORT : IDS_ADDTOREPORT, szCaption) ;
  1089. DialogShow (hDlg, IDD_ADDLINEIFGROUP, FALSE) ;
  1090. DialogShow (hDlg, IDD_ADDLINEIFVALUE, FALSE) ;
  1091. DialogShow (hDlg, IDD_ADDLINEIFUNDER, FALSE) ;
  1092. DialogShow (hDlg, IDD_ADDLINEIFOVER, FALSE) ;
  1093. DialogShow (hDlg, IDD_ADDLINEPROGRAMGROUP, FALSE) ;
  1094. DialogShow (hDlg, IDD_ADDLINEPROGRAM, FALSE) ;
  1095. DialogShow (hDlg, IDD_ADDLINEPROGRAMFIRSTTIME, FALSE) ;
  1096. DialogShow (hDlg, IDD_ADDLINEPROGRAMEVERYTIME, FALSE) ;
  1097. DialogShow (hDlg, IDD_ADDLINECOLOR, FALSE) ;
  1098. DialogShow (hDlg, IDD_ADDLINECOLORTEXT, FALSE) ;
  1099. DialogShow (hDlg, IDD_ADDLINESCALE, FALSE) ;
  1100. DialogShow (hDlg, IDD_ADDLINESCALETEXT, FALSE) ;
  1101. DialogShow (hDlg, IDD_ADDLINEWIDTH, FALSE) ;
  1102. DialogShow (hDlg, IDD_ADDLINEWIDTHTEXT, FALSE) ;
  1103. DialogShow (hDlg, IDD_ADDLINESTYLE, FALSE) ;
  1104. DialogShow (hDlg, IDD_ADDLINESTYLETEXT, FALSE) ;
  1105. break ;
  1106. } // switch
  1107. SetWindowText (hDlg, szCaption) ;
  1108. SendDlgItemMessage (hDlg,
  1109. IDD_ADDLINEEXPLAIN, WM_SETFONT,
  1110. (WPARAM) hFontScales, (LPARAM) FALSE) ;
  1111. WindowCenter (hDlg) ;
  1112. return (TRUE) ;
  1113. }
  1114. BOOL
  1115. /*static*/
  1116. OnObjectChanged (
  1117. HDLG hDlg
  1118. )
  1119. /*
  1120. Effect: Perform any actions necessary when the user has selected
  1121. a new object category from the object CB, or when a default
  1122. object is first selected into the dialog. In particular,
  1123. find and load the counters, instances, etc., for this
  1124. object.
  1125. Called by: OnInitDialog, AddLineDlgProc (in response to an
  1126. IDM_ADDLINEOBJECT notification).
  1127. */
  1128. {
  1129. PPERFOBJECT pObject ;
  1130. HWND hWndInstances = DialogControl (hDlg, IDD_ADDLINEINSTANCE);
  1131. HWND hWndCounters = DialogControl (hDlg, IDD_ADDLINECOUNTER);
  1132. HWND hWndObjects = DialogControl (hDlg, IDD_ADDLINEOBJECT);
  1133. LBReset (hWndInstances) ;
  1134. LBReset (hWndCounters) ;
  1135. pObject = SelectedObject (hWndObjects, NULL) ;
  1136. if (!pObject)
  1137. return (FALSE) ;
  1138. LoadCounters (hDlg, (UINT)pObject->DefaultCounter) ;
  1139. LoadInstances (hDlg) ;
  1140. return TRUE;
  1141. }
  1142. void
  1143. /*static*/
  1144. OnEllipses (
  1145. HWND hDlg
  1146. )
  1147. {
  1148. TCHAR szComputer [256] ;
  1149. memset(szComputer, 0, sizeof(TCHAR) * 256);
  1150. DialogText (hDlg, IDD_ADDLINECOMPUTER, szComputer) ;
  1151. if (ChooseComputer (hDlg, szComputer))
  1152. {
  1153. SetHourglassCursor() ;
  1154. DialogSetString (hDlg, IDD_ADDLINECOMPUTER, szComputer) ;
  1155. OnComputerChanged (hDlg) ;
  1156. }
  1157. }
  1158. BOOL
  1159. LineModifyAttributes (
  1160. HWND hDlg,
  1161. PLINE pLineToModify
  1162. )
  1163. {
  1164. LINEVISUAL LineVisual ;
  1165. HPEN hLinePen ;
  1166. int iScaleIndex = 0 ; // chart attribute
  1167. FLOAT eScale = 1.0f; // chart attribute
  1168. BOOL bLocalAlertOver = FALSE; // alert attribute - over or under?
  1169. FLOAT eLocalAlertValue = 0.0f; // alert attribute - value to compare
  1170. LPTSTR lpLocalszAlertProgram = NULL; // alert attribute - program to run
  1171. BOOL bLocalEveryTime = FALSE; // alert attribute - run every time or once?
  1172. BOOL bLocalAlerted ; // alert attribute - alert happened on line?
  1173. HPEN hTempPen ;
  1174. LPTSTR lpTempAlertProgram ;
  1175. HWND hWndColors = DialogControl (hDlg, IDD_ADDLINECOLOR) ;
  1176. HWND hWndWidths = DialogControl (hDlg, IDD_ADDLINEWIDTH) ;
  1177. HWND hWndStyles = DialogControl (hDlg, IDD_ADDLINESTYLE) ;
  1178. HWND hWndScales = DialogControl (hDlg, IDD_ADDLINESCALE) ;
  1179. //=============================//
  1180. // Visual Values //
  1181. //=============================//
  1182. LineVisual.iColorIndex = (int)CBSelection (hWndColors) ;
  1183. LineVisual.crColor = LineColor (LineVisual.iColorIndex) ;
  1184. LineVisual.iWidthIndex = (int)CBSelection (hWndWidths) ;
  1185. LineVisual.iWidth = LineWidth (LineVisual.iWidthIndex) ;
  1186. LineVisual.iStyleIndex = (int)CBSelection (hWndStyles) ;
  1187. LineVisual.iStyle = LineStyle (LineVisual.iStyleIndex) ;
  1188. hLinePen = LineCreatePen (NULL, &(LineVisual), FALSE) ;
  1189. //=============================//
  1190. // Chart-related Values //
  1191. //=============================//
  1192. if (InChartAdd())
  1193. {
  1194. iScaleIndex = (int)CBSelection (hWndScales) ;
  1195. if (iScaleIndex == 0)
  1196. {
  1197. // use the default scale
  1198. eScale = (FLOAT) pow ((double)10.0,
  1199. (double)pLineToModify->lnCounterDef.DefaultScale) ;
  1200. }
  1201. else
  1202. {
  1203. eScale = DialogFloat (hDlg, IDD_ADDLINESCALE, NULL) ;
  1204. }
  1205. }
  1206. //=============================//
  1207. // Alert Related Values //
  1208. //=============================//
  1209. if (InAlertAdd())
  1210. {
  1211. bLocalAlertOver = bAlertOver ;
  1212. eLocalAlertValue = eAlertValue ;
  1213. bLocalEveryTime =
  1214. IsDlgButtonChecked (hDlg, IDD_ADDLINEPROGRAMEVERYTIME) ;
  1215. bLocalAlerted = FALSE ;
  1216. lpLocalszAlertProgram = StringAllocate (pszAlertProgram) ;
  1217. }
  1218. // Just do it..
  1219. pLineToModify->Visual = LineVisual ;
  1220. if (pLineToModify->hPen)
  1221. {
  1222. hTempPen = pLineToModify->hPen ;
  1223. pLineToModify->hPen = hLinePen ;
  1224. DeletePen (hTempPen) ;
  1225. }
  1226. if (InChartAdd())
  1227. {
  1228. pLineToModify->iScaleIndex = iScaleIndex ;
  1229. pLineToModify->eScale = eScale ;
  1230. }
  1231. if (InAlertAdd())
  1232. {
  1233. HBRUSH hOldBrush;
  1234. pLineToModify->bAlertOver = bLocalAlertOver ;
  1235. pLineToModify->eAlertValue = eLocalAlertValue ;
  1236. pLineToModify->bEveryTime = bLocalEveryTime ;
  1237. pLineToModify->bAlerted = FALSE ;
  1238. hOldBrush = pLineToModify->hBrush ;
  1239. pLineToModify->hBrush = CreateSolidBrush (pLineToModify->Visual.crColor) ;
  1240. DeleteBrush (hOldBrush);
  1241. lpTempAlertProgram = pLineToModify->lpszAlertProgram ;
  1242. pLineToModify->lpszAlertProgram = lpLocalszAlertProgram ;
  1243. if (lpTempAlertProgram)
  1244. {
  1245. MemoryFree (lpTempAlertProgram) ;
  1246. }
  1247. }
  1248. return (TRUE) ;
  1249. }
  1250. BOOL OnAddLines (HWND hDlg)
  1251. {
  1252. PPERFCOUNTERDEF pCounter ;
  1253. TCHAR szCounter [256] ;
  1254. BOOL bOK ;
  1255. int iCounter ;
  1256. int iCounterNum ;
  1257. HWND hWndCounters = DialogControl (hDlg, IDD_ADDLINECOUNTER);
  1258. memset(szCounter, 0, sizeof(TCHAR) * 256);
  1259. if (ComputerChange)
  1260. {
  1261. // if computer has changed, don't want to continue
  1262. // because the perfdata may have changed
  1263. OnComputerChanged (hDlg) ;
  1264. return (TRUE) ;
  1265. }
  1266. //=============================//
  1267. // Dialog Values Acceptable? //
  1268. //=============================//
  1269. if (InAlertAdd ())
  1270. {
  1271. eAlertValue = DialogFloat (hDlg, IDD_ADDLINEIFVALUE, &bOK) ;
  1272. if (!bOK)
  1273. {
  1274. DlgErrorBox (hDlg, ERR_NEEDALERTVALUE);
  1275. SetFocus (DialogControl (hDlg, IDD_ADDLINEIFVALUE)) ;
  1276. return (FALSE) ;
  1277. } // if
  1278. } // if
  1279. if (bEditLine)
  1280. {
  1281. LineModifyAttributes (hDlg, pLineEdit) ;
  1282. EndDialog (hDlg, TRUE) ;
  1283. }
  1284. // If the user changed the textbox for computer name and pressed enter,
  1285. // the OnAddLines function would be called without a check of the
  1286. // computer name. This solves that problem.
  1287. else
  1288. {
  1289. iCounterNum = LBNumItems (hWndCounters) ;
  1290. for (iCounter = 0 ;
  1291. iCounter < iCounterNum ;
  1292. iCounter++)
  1293. { // for
  1294. // NOTE: for now, we don't check for duplicate lines
  1295. if (LBSelected (hWndCounters, iCounter))
  1296. {
  1297. pCounter = (PPERFCOUNTERDEF) LBData (hWndCounters, iCounter) ;
  1298. LBString (hWndCounters, iCounter, szCounter) ;
  1299. if (!IsCounterSupported (pCounter->CounterType))
  1300. {
  1301. DlgErrorBox (hDlg, ERR_COUNTER_NOT_IMP);
  1302. }
  1303. else
  1304. {
  1305. AddCounter (hDlg, pCounter, szCounter);
  1306. }
  1307. }
  1308. } // for
  1309. DialogSetText (hDlg, IDCANCEL, IDS_DONE) ;
  1310. } // else (not bEditLine)
  1311. if (InChartAdd ())
  1312. SizeGraphComponents (hWndGraph) ;
  1313. if (InAlertAdd ())
  1314. SizeAlertComponents (hWndAlert) ;
  1315. if (InReportAdd())
  1316. UpdateReportData (hWndReport);
  1317. WindowInvalidate (PerfmonViewWindow ()) ;
  1318. return TRUE;
  1319. }
  1320. void OnExpandExplain (HWND hDlg)
  1321. /*
  1322. Effect: Perform actions needed when user clicks on the Explain...
  1323. button. In particular, expand the dialog size to
  1324. uncover the explain edit box, and gray out the button.
  1325. */
  1326. {
  1327. RECT rectWindow ;
  1328. // Disable button first
  1329. DialogEnable (hDlg, IDD_ADDLINEEXPANDEXPLAIN, FALSE) ;
  1330. // go get the help text
  1331. bExplainTextButtonHit = TRUE ;
  1332. OnCounterChanged (hDlg) ;
  1333. GetWindowRect (hDlg, &rectWindow) ;
  1334. MoveWindow (hDlg,
  1335. rectWindow.left,
  1336. rectWindow.top,
  1337. rectWindow.right - rectWindow.left,
  1338. rectWindow.bottom - rectWindow.top +
  1339. DialogHeight (hDlg, IDD_ADDLINEEXPLAINGROUP) +
  1340. yScrollHeight,
  1341. TRUE) ;
  1342. }
  1343. BOOL
  1344. /*static*/
  1345. OnCommand (
  1346. HWND hDlg,
  1347. WPARAM wParam,
  1348. LPARAM lParam
  1349. )
  1350. {
  1351. int iWidthIndex ;
  1352. int iStyleIndex ;
  1353. HWND hWndWidths = DialogControl (hDlg, IDD_ADDLINEWIDTH) ;
  1354. HWND hWndStyles = DialogControl (hDlg, IDD_ADDLINESTYLE) ;
  1355. switch (LOWORD (wParam))
  1356. {
  1357. case IDD_ADDLINEIFVALUE:
  1358. // We don't get the value when the user types it. We get it when
  1359. // the user attempts to add the line.
  1360. break ;
  1361. case IDD_ADDLINEPROGRAM:
  1362. GetDlgItemText (hDlg,
  1363. IDD_ADDLINEPROGRAM,
  1364. pszAlertProgram,
  1365. FilePathLen - 1) ;
  1366. break ;
  1367. case IDD_ADDLINEIFOVER:
  1368. case IDD_ADDLINEIFUNDER:
  1369. bAlertOver = (LOWORD (wParam) == IDD_ADDLINEIFOVER) ;
  1370. CheckRadioButton (hDlg, IDD_ADDLINEIFOVER, IDD_ADDLINEIFUNDER,
  1371. bAlertOver ? IDD_ADDLINEIFOVER: IDD_ADDLINEIFUNDER) ;
  1372. break ;
  1373. case IDD_ADDLINEPROGRAMFIRSTTIME:
  1374. case IDD_ADDLINEPROGRAMEVERYTIME:
  1375. bEveryTime = (LOWORD (wParam) == IDD_ADDLINEPROGRAMEVERYTIME) ;
  1376. CheckRadioButton (hDlg, IDD_ADDLINEPROGRAMFIRSTTIME, IDD_ADDLINEPROGRAMEVERYTIME,
  1377. bEveryTime ? IDD_ADDLINEPROGRAMEVERYTIME: IDD_ADDLINEPROGRAMFIRSTTIME) ;
  1378. break ;
  1379. case IDD_ADDLINEWIDTH:
  1380. iWidthIndex = (int)CBSelection (hWndWidths) ;
  1381. #if (!WIDESTYLES)
  1382. DialogEnable (hDlg, IDD_ADDLINESTYLETEXT,
  1383. iWidthIndex == 0 || iWidthIndex == CB_ERR) ;
  1384. DialogEnable (hDlg, IDD_ADDLINESTYLE,
  1385. iWidthIndex == 0 || iWidthIndex == CB_ERR) ;
  1386. #endif
  1387. break ;
  1388. case IDD_ADDLINESTYLE:
  1389. iStyleIndex = (int)CBSelection (hWndStyles) ;
  1390. #if (!WIDESTYLES)
  1391. DialogEnable (hDlg, IDD_ADDLINEWIDTHTEXT,
  1392. iStyleIndex == 0 || iStyleIndex == CB_ERR) ;
  1393. DialogEnable (hDlg, IDD_ADDLINEWIDTH,
  1394. iStyleIndex == 0 || iStyleIndex == CB_ERR) ;
  1395. #endif
  1396. break ;
  1397. case IDCANCEL:
  1398. EndDialog (hDlg, 0);
  1399. return (TRUE);
  1400. break ;
  1401. case IDD_ADDLINEADD :
  1402. if (ComputerChange)
  1403. {
  1404. SetHourglassCursor() ;
  1405. OnComputerChanged (hDlg) ;
  1406. }
  1407. else
  1408. {
  1409. SetHourglassCursor() ;
  1410. OnAddLines (hDlg) ;
  1411. SetArrowCursor() ;
  1412. }
  1413. break;
  1414. case IDD_ADDLINEEXPANDEXPLAIN :
  1415. if (ComputerChange)
  1416. {
  1417. SetHourglassCursor() ;
  1418. OnComputerChanged (hDlg) ;
  1419. }
  1420. else
  1421. {
  1422. OnExpandExplain (hDlg) ;
  1423. }
  1424. break;
  1425. case IDD_ADDLINEELLIPSES:
  1426. SetHourglassCursor() ;
  1427. OnEllipses (hDlg) ;
  1428. SetArrowCursor() ;
  1429. break ;
  1430. case IDD_ADDLINECOUNTER:
  1431. if (ComputerChange)
  1432. {
  1433. SetHourglassCursor() ;
  1434. OnComputerChanged (hDlg) ;
  1435. }
  1436. else if (HIWORD (wParam) == LBN_SELCHANGE)
  1437. OnCounterChanged (hDlg) ;
  1438. break ;
  1439. case IDD_ADDLINEOBJECT:
  1440. if (ComputerChange)
  1441. {
  1442. SetHourglassCursor() ;
  1443. OnComputerChanged (hDlg) ;
  1444. }
  1445. else if (HIWORD (wParam) == CBN_SELCHANGE)
  1446. OnObjectChanged (hDlg) ;
  1447. break ;
  1448. case IDD_ADDLINEINSTANCE:
  1449. if (ComputerChange)
  1450. {
  1451. SetHourglassCursor() ;
  1452. OnComputerChanged (hDlg) ;
  1453. }
  1454. break ;
  1455. case IDD_ADDLINECOMPUTER:
  1456. if (HIWORD (wParam) == EN_UPDATE)
  1457. {
  1458. ComputerChange = TRUE ;
  1459. }
  1460. break ;
  1461. case IDD_ADDLINEHELP:
  1462. CallWinHelp (dwCurrentDlgID, hDlg) ;
  1463. break ;
  1464. default:
  1465. break;
  1466. } // switch
  1467. return (FALSE) ;
  1468. } // OnCommand
  1469. void
  1470. /*static*/
  1471. OnMeasureItem (
  1472. HWND hDlg,
  1473. PMEASUREITEMSTRUCT pMI
  1474. )
  1475. {
  1476. pMI->CtlType = ODT_COMBOBOX ;
  1477. pMI->CtlID = IDD_ADDLINECOLOR ;
  1478. pMI->itemData = 0 ;
  1479. pMI->itemWidth = 0 ;
  1480. // need 14 in order to draw the thickest line width
  1481. pMI->itemHeight = 14 ;
  1482. // pMI->itemHeight = 12 ;
  1483. }
  1484. //***************************************************************************
  1485. // *
  1486. // FUNCTION : HandleSelectionState(LPDRAWITEMSTRUCT) *
  1487. // *
  1488. // PURPOSE : Handles a change in an item selection state. If an item is *
  1489. // selected, a black rectangular frame is drawn around that *
  1490. // item; if an item is de-selected, the frame is removed. *
  1491. // *
  1492. // COMMENT : The black selection frame is slightly larger than the gray *
  1493. // focus frame so they won't paint over each other. *
  1494. // *
  1495. //***************************************************************************
  1496. void
  1497. static
  1498. HandleSelectionState (
  1499. LPDRAWITEMSTRUCT lpdis
  1500. )
  1501. {
  1502. HBRUSH hbr ;
  1503. if (lpdis->itemState & ODS_SELECTED)
  1504. {
  1505. // selecting item -- paint a black frame
  1506. hbr = GetStockObject(BLACK_BRUSH) ;
  1507. }
  1508. else
  1509. {
  1510. // de-selecting item -- remove frame
  1511. hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW)) ;
  1512. }
  1513. if (hbr) {
  1514. FrameRect(lpdis->hDC, (LPRECT)&lpdis->rcItem, hbr) ;
  1515. DeleteObject (hbr) ;
  1516. }
  1517. }
  1518. //***************************************************************************
  1519. // *
  1520. // FUNCTION : HandleFocusState(LPDRAWITEMSTRUCT) *
  1521. // *
  1522. // PURPOSE : Handle a change in item focus state. If an item gains the *
  1523. // input focus, a gray rectangular frame is drawn around that *
  1524. // item; if an item loses the input focus, the gray frame is *
  1525. // removed. *
  1526. // *
  1527. // COMMENT : The gray focus frame is slightly smaller than the black *
  1528. // selection frame so they won't paint over each other. *
  1529. // *
  1530. //***************************************************************************
  1531. void
  1532. static
  1533. HandleFocusState (
  1534. LPDRAWITEMSTRUCT lpdis
  1535. )
  1536. {
  1537. RECT rc ;
  1538. HBRUSH hbr ;
  1539. // Resize rectangle to place focus frame between the selection
  1540. // frame and the item.
  1541. CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem) ;
  1542. InflateRect ((LPRECT)&rc, -OWNER_DRAW_FOCUS, -OWNER_DRAW_FOCUS) ;
  1543. if (lpdis->itemState & ODS_FOCUS)
  1544. {
  1545. // gaining input focus -- paint a gray frame
  1546. hbr = GetStockObject(GRAY_BRUSH) ;
  1547. }
  1548. else
  1549. {
  1550. // losing input focus -- remove (paint over) frame
  1551. hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW)) ;
  1552. }
  1553. if (hbr) {
  1554. FrameRect(lpdis->hDC, (LPRECT)&rc, hbr) ;
  1555. DeleteObject (hbr) ;
  1556. }
  1557. }
  1558. void
  1559. /*static*/
  1560. OnDrawItem (
  1561. HWND hDlg,
  1562. PDRAWITEMSTRUCT pDI
  1563. )
  1564. {
  1565. HDC hDC ;
  1566. PRECT prect ;
  1567. INT itemID,
  1568. CtlID,
  1569. itemAction ;
  1570. LOGBRUSH logBrush ;
  1571. HANDLE hBrush,
  1572. hOldBrush,
  1573. hPen,
  1574. hOldPen ;
  1575. INT x1, y1, x2, y2, cy ;
  1576. POINT point ;
  1577. INT iPenWidth ;
  1578. COLORREF BackgroundColor ;
  1579. hDC = pDI-> hDC ;
  1580. CtlID = pDI->CtlID ;
  1581. prect = &pDI->rcItem ;
  1582. itemID = pDI->itemID ;
  1583. itemAction = pDI->itemAction ;
  1584. if (itemID == -1)
  1585. {
  1586. // invalid ID, can't go on
  1587. HandleFocusState (pDI) ;
  1588. }
  1589. else if (itemAction == ODA_SELECT)
  1590. {
  1591. HandleSelectionState(pDI);
  1592. }
  1593. else if (itemAction == ODA_FOCUS)
  1594. {
  1595. HandleFocusState (pDI) ;
  1596. }
  1597. else
  1598. {
  1599. // draw the entire item
  1600. InflateRect (prect, -OWNER_DRAWN_ITEM, -OWNER_DRAWN_ITEM) ;
  1601. switch (CtlID)
  1602. { // switch
  1603. case IDD_ADDLINECOLOR:
  1604. // Draw a color rectangle into the control area
  1605. logBrush.lbStyle = BS_SOLID ;
  1606. logBrush.lbColor = (COLORREF) argbColors[itemID] ;
  1607. logBrush.lbHatch = 0 ;
  1608. hBrush = CreateBrushIndirect (&logBrush) ;
  1609. if (!hBrush)
  1610. break;
  1611. hOldBrush = SelectObject (hDC, hBrush) ;
  1612. hPen = GetStockObject (NULL_PEN) ;
  1613. hOldPen = SelectObject (hDC, hPen) ;
  1614. x1 = prect->left ;
  1615. y1 = prect->top ;
  1616. x2 = prect->right ;
  1617. y2 = prect->bottom ;
  1618. Rectangle (hDC, x1, y1, x2, y2) ;
  1619. SelectObject (hDC, hOldBrush) ;
  1620. DeleteObject (hBrush) ;
  1621. InflateRect (prect, OWNER_DRAWN_ITEM, OWNER_DRAWN_ITEM) ;
  1622. HandleSelectionState (pDI) ;
  1623. HandleFocusState (pDI) ;
  1624. break ;
  1625. case IDD_ADDLINEWIDTH:
  1626. case IDD_ADDLINESTYLE:
  1627. // First draw a rectangle, white interior, null border
  1628. hBrush = GetStockObject (WHITE_BRUSH) ;
  1629. hOldBrush = SelectObject (hDC, hBrush) ;
  1630. // we need to set the bk color in order to draw
  1631. // the dash lines coorectly during focus. Otherwise,
  1632. // the COLOR_WINDOW background will make all dash lines
  1633. // look like solid line...
  1634. BackgroundColor = SetBkColor (hDC, crWhite) ;
  1635. hPen = GetStockObject (NULL_PEN) ;
  1636. hOldPen = SelectObject (hDC, hPen) ;
  1637. x1 = prect->left ;
  1638. y1 = prect->top ;
  1639. x2 = prect->right ;
  1640. y2 = prect->bottom ;
  1641. Rectangle (hDC, x1, y1, x2, y2) ;
  1642. SelectObject (hDC, hOldPen) ;
  1643. // Draw a line of the itemID width in the middle
  1644. // of the control area.
  1645. if (CtlID == IDD_ADDLINEWIDTH)
  1646. {
  1647. iPenWidth = LineWidth (itemID) ;
  1648. hPen = CreatePen (PS_SOLID, iPenWidth, RGB (0, 0, 0)) ;
  1649. }
  1650. else
  1651. {
  1652. hPen = CreatePen (itemID, 1, RGB (0, 0, 0)) ;
  1653. }
  1654. if (!hPen)
  1655. break;
  1656. hOldPen = SelectObject (hDC, hPen) ;
  1657. x1 = prect->left + 8 ;
  1658. cy = prect->bottom - prect->top ;
  1659. y1 = prect->top + (cy / 2) - 1 ;
  1660. x2 = prect->right - 8 ;
  1661. MoveToEx (hDC, x1, y1, &point) ;
  1662. LineTo (hDC, x2, y1) ;
  1663. SelectObject (hDC, hOldPen) ;
  1664. DeleteObject (hPen) ;
  1665. SelectObject (hDC, hOldBrush) ;
  1666. BackgroundColor = SetBkColor (hDC, BackgroundColor) ;
  1667. InflateRect (prect, OWNER_DRAWN_ITEM, OWNER_DRAWN_ITEM) ;
  1668. HandleSelectionState (pDI) ;
  1669. HandleFocusState (pDI) ;
  1670. break ;
  1671. } // switch
  1672. } // draw entire item
  1673. }
  1674. void
  1675. /*static*/
  1676. OnDestroy (HDLG hDlg)
  1677. {
  1678. if (!PlayingBackLog ())
  1679. MemoryFree ((LPMEMORY)pPerfData) ;
  1680. if (pszAlertProgram)
  1681. {
  1682. MemoryFree (pszAlertProgram) ;
  1683. pszAlertProgram = NULL ;
  1684. }
  1685. pLineEdit = NULL ;
  1686. bAddLineInProgress = FALSE ;
  1687. dwCurrentDlgID = 0 ;
  1688. bExplainTextButtonHit = FALSE ;
  1689. }
  1690. //==========================================================================//
  1691. // Exported Functions //
  1692. //==========================================================================//
  1693. INT_PTR
  1694. FAR
  1695. PASCAL
  1696. AddLineDlgProc (
  1697. HWND hDlg,
  1698. UINT msg,
  1699. WPARAM wParam,
  1700. LPARAM lParam
  1701. )
  1702. {
  1703. BOOL Status;
  1704. switch (msg) {
  1705. case WM_COMMAND:
  1706. OnCommand (hDlg, wParam, lParam) ;
  1707. return (FALSE) ;
  1708. break ;
  1709. case WM_INITDIALOG:
  1710. SetHourglassCursor() ;
  1711. Status = OnInitDialog (hDlg) ;
  1712. SetArrowCursor() ;
  1713. // set focus on the "Add" button instead of the "Computer"
  1714. SetFocus (DialogControl (hDlg, IDD_ADDLINEADD)) ;
  1715. return FALSE ;
  1716. break ;
  1717. case WM_MEASUREITEM:
  1718. OnMeasureItem (hDlg, (PMEASUREITEMSTRUCT) lParam) ;
  1719. return (TRUE) ;
  1720. break ;
  1721. case WM_DRAWITEM:
  1722. OnDrawItem (hDlg, (PDRAWITEMSTRUCT) lParam) ;
  1723. return (TRUE) ;
  1724. break ;
  1725. case WM_DESTROY:
  1726. OnDestroy (hDlg) ;
  1727. break ;
  1728. default:
  1729. break;
  1730. }
  1731. return (FALSE) ;
  1732. }
  1733. BOOL
  1734. AddLine (
  1735. HWND hWndParent,
  1736. PPERFSYSTEM *ppSystemFirstView,
  1737. PLINEVISUAL pLineVisual,
  1738. LPTSTR pInCurrentSystem,
  1739. int iLineTypeToAdd
  1740. )
  1741. /*
  1742. Effect: Display the add line dialog box, allowing the user
  1743. to specify the computer, object, counter, instance,
  1744. and scale for a line. The user can also select the
  1745. visual aspects of color, width and line style.
  1746. */
  1747. {
  1748. pLineEdit = NULL ;
  1749. ppSystemFirst = ppSystemFirstView ;
  1750. iLineType = iLineTypeToAdd ;
  1751. pVisual = pLineVisual ;
  1752. pCurrentSystem = pInCurrentSystem ;
  1753. return (DialogBox (hInstance, idDlgAddLine, hWndParent, AddLineDlgProc) ? TRUE : FALSE) ;
  1754. }
  1755. BOOL
  1756. EditLine (
  1757. HWND hWndParent,
  1758. PPERFSYSTEM *ppSystemFirstView,
  1759. PLINE pLineToEdit,
  1760. int iLineTypeToEdit
  1761. )
  1762. {
  1763. if (!pLineToEdit)
  1764. {
  1765. return (FALSE) ;
  1766. }
  1767. pLineEdit = pLineToEdit ;
  1768. ppSystemFirst = ppSystemFirstView ;
  1769. iLineType = iLineTypeToEdit ;
  1770. pVisual = &(pLineToEdit->Visual) ;
  1771. return (DialogBox (hInstance, idDlgAddLine, hWndParent, AddLineDlgProc) ? TRUE : FALSE) ;
  1772. }