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.

1874 lines
55 KiB

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