Leaked source code of windows server 2003
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.

975 lines
24 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: DCntPage.cpp
  8. // author: DMihai
  9. // created: 11/1/00
  10. //
  11. // Description:
  12. //
  13. #include "stdafx.h"
  14. #include "verifier.h"
  15. #include "DCntPage.h"
  16. #include "VrfUtil.h"
  17. #include "VGlobal.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. //
  24. // Timer ID
  25. //
  26. #define REFRESH_TIMER_ID 0x1234
  27. //
  28. // Help IDs
  29. //
  30. static DWORD MyHelpIds[] =
  31. {
  32. IDC_PERDRVC_DRIVER_COMBO, IDH_DV_Counters_DriverList,
  33. IDC_PERDRVC_LIST, IDH_DV_DriverCounters,
  34. 0, 0
  35. };
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CDriverCountersPage property page
  38. IMPLEMENT_DYNCREATE(CDriverCountersPage, CVerifierPropertyPage)
  39. CDriverCountersPage::CDriverCountersPage() : CVerifierPropertyPage(CDriverCountersPage::IDD)
  40. {
  41. //{{AFX_DATA_INIT(CDriverCountersPage)
  42. //}}AFX_DATA_INIT
  43. m_nSortColumnIndex = 0;
  44. m_bAscendSortName = FALSE;
  45. m_bAscendSortValue = FALSE;
  46. m_uTimerHandler = 0;
  47. m_pParentSheet = NULL;
  48. }
  49. CDriverCountersPage::~CDriverCountersPage()
  50. {
  51. }
  52. void CDriverCountersPage::DoDataExchange(CDataExchange* pDX)
  53. {
  54. if( ! pDX->m_bSaveAndValidate )
  55. {
  56. //
  57. // Query the kernel
  58. //
  59. VrfGetRuntimeVerifierData( &m_RuntimeVerifierData );
  60. }
  61. CVerifierPropertyPage::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CDriverCountersPage)
  63. DDX_Control(pDX, IDC_PERDRVC_DRIVER_COMBO, m_DriversCombo);
  64. DDX_Control(pDX, IDC_PERDRVC_NEXT_DESCR_STATIC, m_NextDescription);
  65. DDX_Control(pDX, IDC_PERDRVC_LIST, m_CountersList);
  66. //}}AFX_DATA_MAP
  67. }
  68. BEGIN_MESSAGE_MAP(CDriverCountersPage, CVerifierPropertyPage)
  69. //{{AFX_MSG_MAP(CDriverCountersPage)
  70. ON_WM_TIMER()
  71. ON_CBN_SELENDOK(IDC_PERDRVC_DRIVER_COMBO, OnSelendokDriverCombo)
  72. ON_NOTIFY(LVN_COLUMNCLICK, IDC_PERDRVC_LIST, OnColumnclickPerdrvcList)
  73. ON_WM_CONTEXTMENU()
  74. ON_MESSAGE( WM_HELP, OnHelp )
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////
  78. VOID CDriverCountersPage::SetupListHeader()
  79. {
  80. LVCOLUMN lvColumn;
  81. CRect rectWnd;
  82. CString strCounter, strValue;
  83. VERIFY( strCounter.LoadString( IDS_COUNTER ) );
  84. VERIFY( strValue.LoadString( IDS_VALUE ) );
  85. //
  86. // List's regtangle
  87. //
  88. m_CountersList.GetClientRect( &rectWnd );
  89. //
  90. // Column 0 - counter
  91. //
  92. ZeroMemory( &lvColumn, sizeof( lvColumn ) );
  93. lvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
  94. lvColumn.fmt = LVCFMT_LEFT;
  95. lvColumn.iSubItem = 0;
  96. lvColumn.cx = (int)( rectWnd.Width() * 0.50 );
  97. lvColumn.pszText = strCounter.GetBuffer( strCounter.GetLength() + 1 );
  98. if (NULL != lvColumn.pszText)
  99. {
  100. VERIFY( m_CountersList.InsertColumn( 0, &lvColumn ) != -1 );
  101. strCounter.ReleaseBuffer();
  102. }
  103. else
  104. {
  105. lvColumn.pszText = g_szVoidText;
  106. VERIFY( m_CountersList.InsertColumn( 0, &lvColumn ) != -1 );
  107. }
  108. //
  109. // Column 1
  110. //
  111. lvColumn.iSubItem = 1;
  112. lvColumn.cx = (int)( rectWnd.Width() * 0.47 );
  113. lvColumn.pszText = strValue.GetBuffer( strValue.GetLength() + 1 );
  114. if (NULL != lvColumn.pszText)
  115. {
  116. VERIFY( m_CountersList.InsertColumn( 1, &lvColumn ) != -1 );
  117. strValue.ReleaseBuffer();
  118. }
  119. else
  120. {
  121. lvColumn.pszText = g_szVoidText;
  122. VERIFY( m_CountersList.InsertColumn( 1, &lvColumn ) != -1 );
  123. }
  124. }
  125. /////////////////////////////////////////////////////////////
  126. VOID CDriverCountersPage::FillTheList()
  127. {
  128. CRuntimeDriverData *pRuntimeDriverData;
  129. pRuntimeDriverData = GetCurrentDrvRuntimeData();
  130. AddAllListItems( pRuntimeDriverData );
  131. }
  132. /////////////////////////////////////////////////////////////
  133. VOID CDriverCountersPage::AddAllListItems( CRuntimeDriverData *pRuntimeDriverData )
  134. {
  135. if( NULL != pRuntimeDriverData )
  136. {
  137. ASSERT_VALID( pRuntimeDriverData );
  138. //
  139. // N.B.
  140. //
  141. // If you change this order then you need to change GetCounterValue as well
  142. //
  143. AddCounterInList( 0, IDS_CURRENTPAGEDPOOLALLOCATIONS_LIST, pRuntimeDriverData->CurrentPagedPoolAllocations );
  144. AddCounterInList( 1, IDS_PEAKPAGEDPOOLALLOCATIONS_LIST, pRuntimeDriverData->PeakPagedPoolAllocations );
  145. AddCounterInList( 2, IDS_PAGEDPOOLUSAGEINBYTES_LIST, pRuntimeDriverData->PagedPoolUsageInBytes );
  146. AddCounterInList( 3, IDS_PEAKPAGEDPOOLUSAGEINBYTES_LIST, pRuntimeDriverData->PeakPagedPoolUsageInBytes );
  147. AddCounterInList( 4, IDS_CURRENTNONPAGEDPOOLALLOCATIONS_LIST, pRuntimeDriverData->CurrentNonPagedPoolAllocations );
  148. AddCounterInList( 5, IDS_PEAKNONPAGEDPOOLALLOCATIONS_LIST, pRuntimeDriverData->PeakNonPagedPoolAllocations );
  149. AddCounterInList( 6, IDS_NONPAGEDPOOLUSAGEINBYTES_LIST, pRuntimeDriverData->NonPagedPoolUsageInBytes );
  150. AddCounterInList( 7, IDS_PEAKNONPAGEDPOOLUSAGEINBYTES_LIST, pRuntimeDriverData->PeakNonPagedPoolUsageInBytes );
  151. }
  152. else
  153. {
  154. //
  155. // N.B.
  156. //
  157. // If you change this order then you need to change GetCounterValue as well
  158. //
  159. AddCounterInList( 0, IDS_CURRENTPAGEDPOOLALLOCATIONS_LIST );
  160. AddCounterInList( 1, IDS_PEAKPAGEDPOOLALLOCATIONS_LIST );
  161. AddCounterInList( 2, IDS_PAGEDPOOLUSAGEINBYTES_LIST );
  162. AddCounterInList( 3, IDS_PEAKPAGEDPOOLUSAGEINBYTES_LIST );
  163. AddCounterInList( 4, IDS_CURRENTNONPAGEDPOOLALLOCATIONS_LIST );
  164. AddCounterInList( 5, IDS_PEAKNONPAGEDPOOLALLOCATIONS_LIST );
  165. AddCounterInList( 6, IDS_NONPAGEDPOOLUSAGEINBYTES_LIST );
  166. AddCounterInList( 7, IDS_PEAKNONPAGEDPOOLUSAGEINBYTES_LIST );
  167. }
  168. }
  169. /////////////////////////////////////////////////////////////
  170. VOID CDriverCountersPage::RefreshTheList()
  171. {
  172. INT nListItems;
  173. INT nCrtListItem;
  174. INT_PTR nCrtCounterIndex;
  175. SIZE_T sizeValue;
  176. CRuntimeDriverData *pRuntimeDriverData;
  177. pRuntimeDriverData = GetCurrentDrvRuntimeData();
  178. nListItems = m_CountersList.GetItemCount();
  179. if( NULL != pRuntimeDriverData )
  180. {
  181. for( nCrtListItem = 0; nCrtListItem < nListItems; nCrtListItem += 1 )
  182. {
  183. nCrtCounterIndex = m_CountersList.GetItemData( nCrtListItem );
  184. sizeValue = GetCounterValue( nCrtCounterIndex, pRuntimeDriverData );
  185. UpdateCounterValueInList( nCrtListItem, sizeValue );
  186. }
  187. }
  188. else
  189. {
  190. //
  191. // N.B.
  192. //
  193. // If you change this order then you need to
  194. // change AddAllListItems as well
  195. //
  196. for( nCrtListItem = 0; nCrtListItem < nListItems; nCrtListItem += 1 )
  197. {
  198. UpdateCounterValueInList( nCrtListItem, g_szVoidText );
  199. }
  200. }
  201. SortTheList();
  202. }
  203. /////////////////////////////////////////////////////////////
  204. INT CDriverCountersPage::AddCounterInList( INT nItemData,
  205. ULONG uIdResourceString )
  206. {
  207. INT nActualIndex;
  208. LVITEM lvItem;
  209. CString strName;
  210. nActualIndex = -1;
  211. VERIFY( strName.LoadString( uIdResourceString ) );
  212. ZeroMemory( &lvItem, sizeof( lvItem ) );
  213. //
  214. // LVITEM's member pszText is not a const pointer
  215. // so we need to GetBuffer here :-(
  216. //
  217. //
  218. // Sub-item 0 - counter's name
  219. //
  220. lvItem.pszText = strName.GetBuffer( strName.GetLength() + 1 );
  221. if( NULL == lvItem.pszText )
  222. {
  223. goto Done;
  224. }
  225. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  226. lvItem.lParam = nItemData;
  227. lvItem.iItem = m_CountersList.GetItemCount();
  228. nActualIndex = m_CountersList.InsertItem( &lvItem );
  229. if( nActualIndex < 0 )
  230. {
  231. //
  232. // Could not add an item in the list - give up
  233. //
  234. goto Done;
  235. }
  236. Done:
  237. //
  238. // All done
  239. //
  240. return nActualIndex;
  241. }
  242. /////////////////////////////////////////////////////////////
  243. VOID CDriverCountersPage::AddCounterInList( INT nItemData,
  244. ULONG uIdResourceString,
  245. SIZE_T sizeValue )
  246. {
  247. INT nActualIndex;
  248. nActualIndex = AddCounterInList( nItemData, uIdResourceString );
  249. if( nActualIndex < 0 )
  250. {
  251. //
  252. // Could not add an item in the list - give up
  253. //
  254. goto Done;
  255. }
  256. //
  257. // Sub-item 1 - counter's value
  258. //
  259. UpdateCounterValueInList( nActualIndex,
  260. sizeValue );
  261. Done:
  262. //
  263. // All done
  264. //
  265. NOTHING;
  266. }
  267. /////////////////////////////////////////////////////////////
  268. SIZE_T CDriverCountersPage::GetCounterValue( INT_PTR nCounterIndex, CRuntimeDriverData *pRuntimeDriverData /*= NULL*/ )
  269. {
  270. SIZE_T sizeValue;
  271. if( NULL == pRuntimeDriverData )
  272. {
  273. pRuntimeDriverData = GetCurrentDrvRuntimeData();
  274. }
  275. if( NULL == pRuntimeDriverData )
  276. {
  277. //
  278. // No driver is curently selected in the combo
  279. //
  280. return 0;
  281. }
  282. //
  283. // N.B.
  284. //
  285. // If you change this switch statement you need to change AddAllListItems as well
  286. //
  287. switch( nCounterIndex )
  288. {
  289. case 0:
  290. sizeValue = pRuntimeDriverData->CurrentPagedPoolAllocations;
  291. break;
  292. case 1:
  293. sizeValue = pRuntimeDriverData->PeakPagedPoolAllocations;
  294. break;
  295. case 2:
  296. sizeValue = pRuntimeDriverData->PagedPoolUsageInBytes;
  297. break;
  298. case 3:
  299. sizeValue = pRuntimeDriverData->PeakPagedPoolUsageInBytes;
  300. break;
  301. case 4:
  302. sizeValue = pRuntimeDriverData->CurrentNonPagedPoolAllocations;
  303. break;
  304. case 5:
  305. sizeValue = pRuntimeDriverData->PeakNonPagedPoolAllocations;
  306. break;
  307. case 6:
  308. sizeValue = pRuntimeDriverData->NonPagedPoolUsageInBytes;
  309. break;
  310. case 7:
  311. sizeValue = pRuntimeDriverData->PeakNonPagedPoolUsageInBytes;
  312. break;
  313. default:
  314. //
  315. // Oops, how did we get here ?!?
  316. //
  317. ASSERT( FALSE );
  318. sizeValue = 0;
  319. break;
  320. }
  321. return sizeValue;
  322. }
  323. /////////////////////////////////////////////////////////////
  324. BOOL CDriverCountersPage::GetCounterName( LPARAM lItemData,
  325. TCHAR *szCounterName,
  326. ULONG uCounterNameBufferLen )
  327. {
  328. INT nItemIndex;
  329. BOOL bResult;
  330. LVFINDINFO FindInfo;
  331. LVITEM lvItem;
  332. bResult = FALSE;
  333. ZeroMemory( &FindInfo, sizeof( FindInfo ) );
  334. FindInfo.flags = LVFI_PARAM;
  335. FindInfo.lParam = lItemData;
  336. nItemIndex = m_CountersList.FindItem( &FindInfo );
  337. if( nItemIndex < 0 || nItemIndex > 7 )
  338. {
  339. ASSERT( FALSE );
  340. }
  341. else
  342. {
  343. //
  344. // Found our item - get the name
  345. //
  346. ZeroMemory( &lvItem, sizeof( lvItem ) );
  347. lvItem.mask = LVIF_TEXT;
  348. lvItem.iItem = nItemIndex;
  349. lvItem.iSubItem = 0;
  350. lvItem.pszText = szCounterName;
  351. lvItem.cchTextMax = uCounterNameBufferLen;
  352. bResult = m_CountersList.GetItem( &lvItem );
  353. if( bResult == FALSE )
  354. {
  355. //
  356. // Could not get the current item's attributes?!?
  357. //
  358. ASSERT( FALSE );
  359. }
  360. }
  361. return bResult;
  362. }
  363. /////////////////////////////////////////////////////////////
  364. VOID CDriverCountersPage::UpdateCounterValueInList( INT nItemIndex,
  365. LPTSTR szValue )
  366. {
  367. LVITEM lvItem;
  368. //
  369. // Update the list item
  370. //
  371. ZeroMemory( &lvItem, sizeof( lvItem ) );
  372. lvItem.mask = LVIF_TEXT;
  373. lvItem.iItem = nItemIndex;
  374. lvItem.iSubItem = 1;
  375. lvItem.pszText = szValue;
  376. VERIFY( m_CountersList.SetItem( &lvItem ) );
  377. }
  378. /////////////////////////////////////////////////////////////
  379. VOID CDriverCountersPage::UpdateCounterValueInList( INT nItemIndex,
  380. SIZE_T sizeValue )
  381. {
  382. TCHAR szValue[ 32 ];
  383. #ifndef _WIN64
  384. //
  385. // 32 bit SIZE_T
  386. //
  387. _sntprintf( szValue,
  388. ARRAY_LENGTH( szValue ),
  389. _T( "%u" ),
  390. sizeValue );
  391. #else
  392. //
  393. // 64 bit SIZE_T
  394. //
  395. _sntprintf( szValue,
  396. ARRAY_LENGTH( szValue ),
  397. _T( "%I64u" ),
  398. sizeValue );
  399. #endif
  400. szValue[ ARRAY_LENGTH( szValue ) - 1 ] = 0;
  401. UpdateCounterValueInList( nItemIndex,
  402. szValue );
  403. }
  404. /////////////////////////////////////////////////////////////
  405. VOID CDriverCountersPage::RefreshCombo()
  406. {
  407. BOOL *pbAlreadyInCombo;
  408. CRuntimeDriverData *pRuntimeDriverData;
  409. INT_PTR nDrivers;
  410. INT_PTR nCrtDriver;
  411. INT nCrtSelectedItem;
  412. INT nCrtItemIndex;
  413. INT nComboItemCount;
  414. INT nActualIndex;
  415. CString strCurrentDriverName;
  416. CString strDriverName;
  417. nDrivers = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize();
  418. if( 0 >= nDrivers )
  419. {
  420. //
  421. // No drivers are currently verified - delete the combo-box content
  422. //
  423. m_DriversCombo.ResetContent();
  424. m_DriversCombo.SetCurSel( CB_ERR );
  425. m_DriversCombo.EnableWindow( FALSE );
  426. OnSelendokDriverCombo();
  427. }
  428. else
  429. {
  430. nCrtSelectedItem = 0;
  431. nComboItemCount = m_DriversCombo.GetCount();
  432. //
  433. // Note the currently selected driver name
  434. //
  435. GetCurrentSelDriverName( strCurrentDriverName );
  436. //
  437. // Allocate an array of BOOL values, one for each driver in
  438. // our runtime data array
  439. //
  440. pbAlreadyInCombo = new BOOL[ nDrivers ];
  441. if( NULL == pbAlreadyInCombo )
  442. {
  443. goto Done;
  444. }
  445. for( nCrtDriver = 0; nCrtDriver < nDrivers; nCrtDriver++ )
  446. {
  447. pbAlreadyInCombo[ nCrtDriver ] = FALSE;
  448. }
  449. //
  450. // Parse all the items currently in the combo-box
  451. //
  452. for( nCrtItemIndex = 0; nCrtItemIndex < nComboItemCount; nCrtItemIndex++ )
  453. {
  454. m_DriversCombo.GetLBText( nCrtItemIndex, strDriverName );
  455. //
  456. // Parse all the currently verified drivers
  457. //
  458. for( nCrtDriver = 0; nCrtDriver < nDrivers; nCrtDriver++ )
  459. {
  460. pRuntimeDriverData = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtDriver );
  461. ASSERT_VALID( pRuntimeDriverData );
  462. if( strDriverName.CompareNoCase( pRuntimeDriverData->m_strName ) == 0 )
  463. {
  464. pbAlreadyInCombo[ nCrtDriver ] = TRUE;
  465. break;
  466. }
  467. }
  468. if( nCrtDriver >= nDrivers )
  469. {
  470. //
  471. // We need to delete the current combo item because
  472. // the corresponfing driver is no longer verified
  473. //
  474. m_DriversCombo.DeleteString( nCrtItemIndex );
  475. nCrtItemIndex--;
  476. nComboItemCount--;
  477. }
  478. }
  479. //
  480. // Add the new items in the combo
  481. //
  482. for( nCrtDriver = 0; nCrtDriver < nDrivers; nCrtDriver++ )
  483. {
  484. if( FALSE == pbAlreadyInCombo[ nCrtDriver ] )
  485. {
  486. pRuntimeDriverData = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtDriver );
  487. ASSERT_VALID( pRuntimeDriverData );
  488. nActualIndex = m_DriversCombo.AddString( pRuntimeDriverData->m_strName );
  489. if( nActualIndex != CB_ERR )
  490. {
  491. m_DriversCombo.SetItemData( nActualIndex, nCrtDriver );
  492. }
  493. }
  494. }
  495. delete [] pbAlreadyInCombo;
  496. //
  497. // Restore the old current selection in the combo
  498. //
  499. nComboItemCount = m_DriversCombo.GetCount();
  500. for( nCrtItemIndex = 0; nCrtItemIndex < nComboItemCount; nCrtItemIndex++ )
  501. {
  502. m_DriversCombo.GetLBText( nCrtItemIndex, strDriverName );
  503. if( strDriverName.CompareNoCase( strCurrentDriverName ) == 0 )
  504. {
  505. nCrtSelectedItem = nCrtItemIndex;
  506. break;
  507. }
  508. }
  509. m_DriversCombo.SetCurSel( nCrtSelectedItem );
  510. OnSelendokDriverCombo();
  511. }
  512. Done:
  513. NOTHING;
  514. }
  515. /////////////////////////////////////////////////////////////
  516. VOID CDriverCountersPage::RefreshInfo()
  517. {
  518. if( UpdateData( FALSE ) )
  519. {
  520. //
  521. // Refresh the combo content - this will also
  522. // refresh the counters list
  523. //
  524. RefreshCombo();
  525. }
  526. }
  527. /////////////////////////////////////////////////////////////
  528. VOID CDriverCountersPage::GetCurrentSelDriverName( CString &strName )
  529. {
  530. INT nCrtSel;
  531. nCrtSel = m_DriversCombo.GetCurSel();
  532. if( CB_ERR != nCrtSel )
  533. {
  534. m_DriversCombo.GetLBText( nCrtSel, strName );
  535. }
  536. else
  537. {
  538. strName.Empty();
  539. }
  540. }
  541. /////////////////////////////////////////////////////////////
  542. CRuntimeDriverData *CDriverCountersPage::GetCurrentDrvRuntimeData()
  543. {
  544. INT nCrtComboSelection;
  545. INT_PTR nCrtDriverIndex;
  546. CRuntimeDriverData *pRuntimeDriverData;
  547. pRuntimeDriverData = NULL;
  548. nCrtDriverIndex = -1;
  549. nCrtComboSelection = m_DriversCombo.GetCurSel();
  550. if( nCrtComboSelection != CB_ERR )
  551. {
  552. nCrtDriverIndex = m_DriversCombo.GetItemData( nCrtComboSelection );
  553. if( nCrtDriverIndex >= 0 && nCrtDriverIndex < m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetSize() )
  554. {
  555. pRuntimeDriverData = m_RuntimeVerifierData.m_RuntimeDriverDataArray.GetAt( nCrtDriverIndex );
  556. ASSERT_VALID( pRuntimeDriverData );
  557. }
  558. }
  559. return pRuntimeDriverData;
  560. }
  561. /////////////////////////////////////////////////////////////
  562. VOID CDriverCountersPage::SortTheList()
  563. {
  564. if( 0 != m_nSortColumnIndex )
  565. {
  566. //
  567. // Sort by counter value - this is probably not very useful
  568. // but we are providing it to be consistent with all
  569. // the lists being sortable by any column
  570. //
  571. m_CountersList.SortItems( CounterValueCmpFunc, (LPARAM)this );
  572. }
  573. else
  574. {
  575. //
  576. // Sort by driver name
  577. //
  578. m_CountersList.SortItems( CounterNameCmpFunc, (LPARAM)this );
  579. }
  580. }
  581. /////////////////////////////////////////////////////////////
  582. int CALLBACK CDriverCountersPage::CounterValueCmpFunc( LPARAM lParam1,
  583. LPARAM lParam2,
  584. LPARAM lParamSort)
  585. {
  586. SIZE_T size1;
  587. SIZE_T size2;
  588. int nCmpRez = 0;
  589. CDriverCountersPage *pThis = (CDriverCountersPage *)lParamSort;
  590. ASSERT_VALID( pThis );
  591. size1 = pThis->GetCounterValue( (INT) lParam1 );
  592. size2 = pThis->GetCounterValue( (INT) lParam2 );
  593. if( size1 > size2 )
  594. {
  595. nCmpRez = 1;
  596. }
  597. else
  598. {
  599. if( size1 < size2 )
  600. {
  601. nCmpRez = -1;
  602. }
  603. }
  604. if( FALSE != pThis->m_bAscendSortValue )
  605. {
  606. nCmpRez *= -1;
  607. }
  608. return nCmpRez;
  609. }
  610. /////////////////////////////////////////////////////////////
  611. int CALLBACK CDriverCountersPage::CounterNameCmpFunc( LPARAM lParam1,
  612. LPARAM lParam2,
  613. LPARAM lParamSort)
  614. {
  615. int nCmpRez = 0;
  616. BOOL bSuccess;
  617. TCHAR szCounterName1[ _MAX_PATH ];
  618. TCHAR szCounterName2[ _MAX_PATH ];
  619. CDriverCountersPage *pThis = (CDriverCountersPage *)lParamSort;
  620. ASSERT_VALID( pThis );
  621. //
  622. // Get the first counter name
  623. //
  624. bSuccess = pThis->GetCounterName( lParam1,
  625. szCounterName1,
  626. ARRAY_LENGTH( szCounterName1 ) );
  627. if( FALSE == bSuccess )
  628. {
  629. goto Done;
  630. }
  631. //
  632. // Get the second counter name
  633. //
  634. bSuccess = pThis->GetCounterName( lParam2,
  635. szCounterName2,
  636. ARRAY_LENGTH( szCounterName2 ) );
  637. if( FALSE == bSuccess )
  638. {
  639. goto Done;
  640. }
  641. //
  642. // Compare the names
  643. //
  644. nCmpRez = _tcsicmp( szCounterName1, szCounterName2 );
  645. if( FALSE != pThis->m_bAscendSortName )
  646. {
  647. nCmpRez *= -1;
  648. }
  649. Done:
  650. return nCmpRez;
  651. }
  652. /////////////////////////////////////////////////////////////
  653. // CDriverCountersPage message handlers
  654. BOOL CDriverCountersPage::OnInitDialog()
  655. {
  656. CPropertyPage::OnInitDialog();
  657. //
  658. // Setup the settings bits list
  659. //
  660. m_CountersList.SetExtendedStyle(
  661. LVS_EX_FULLROWSELECT | m_CountersList.GetExtendedStyle() );
  662. m_CountersList.SetBkColor( ::GetSysColor( COLOR_3DFACE ) );
  663. m_CountersList.SetTextBkColor( ::GetSysColor( COLOR_3DFACE ) );
  664. SetupListHeader();
  665. FillTheList();
  666. SortTheList();
  667. RefreshCombo();
  668. VrfSetWindowText( m_NextDescription, IDS_DCNT_PAGE_NEXT_DESCR );
  669. VERIFY( m_uTimerHandler = SetTimer( REFRESH_TIMER_ID,
  670. 5000,
  671. NULL ) );
  672. return TRUE; // return TRUE unless you set the focus to a control
  673. // EXCEPTION: OCX Property Pages should return FALSE
  674. }
  675. /////////////////////////////////////////////////////////////
  676. VOID CDriverCountersPage::OnTimer(UINT nIDEvent)
  677. {
  678. if( nIDEvent == REFRESH_TIMER_ID )
  679. {
  680. ASSERT_VALID( m_pParentSheet );
  681. if( m_pParentSheet->GetActivePage() == this )
  682. {
  683. //
  684. // Refresh the displayed data
  685. //
  686. RefreshInfo();
  687. }
  688. }
  689. CPropertyPage::OnTimer(nIDEvent);
  690. }
  691. /////////////////////////////////////////////////////////////////////////////
  692. BOOL CDriverCountersPage::OnSetActive()
  693. {
  694. ASSERT_VALID( m_pParentSheet );
  695. m_pParentSheet->SetWizardButtons( PSWIZB_BACK |
  696. PSWIZB_FINISH );
  697. return CVerifierPropertyPage::OnSetActive();
  698. }
  699. /////////////////////////////////////////////////////////////
  700. void CDriverCountersPage::OnSelendokDriverCombo()
  701. {
  702. RefreshTheList();
  703. }
  704. /////////////////////////////////////////////////////////////
  705. void CDriverCountersPage::OnColumnclickPerdrvcList(NMHDR* pNMHDR, LRESULT* pResult)
  706. {
  707. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  708. if( 0 != pNMListView->iSubItem )
  709. {
  710. //
  711. // Clicked on the counter value column
  712. //
  713. if( m_nSortColumnIndex == pNMListView->iSubItem )
  714. {
  715. //
  716. // Change the current ascend/descend order for this column
  717. //
  718. m_bAscendSortValue = !m_bAscendSortValue;
  719. }
  720. }
  721. else
  722. {
  723. //
  724. // Clicked on the counter name column
  725. //
  726. if( m_nSortColumnIndex == pNMListView->iSubItem )
  727. {
  728. //
  729. // Change the current ascend/descend order for this column
  730. //
  731. m_bAscendSortName = !m_bAscendSortName;
  732. }
  733. }
  734. m_nSortColumnIndex = pNMListView->iSubItem;
  735. SortTheList();
  736. *pResult = 0;
  737. }
  738. /////////////////////////////////////////////////////////////
  739. LONG CDriverCountersPage::OnHelp( WPARAM wParam, LPARAM lParam )
  740. {
  741. LONG lResult = 0;
  742. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  743. ::WinHelp(
  744. (HWND) lpHelpInfo->hItemHandle,
  745. g_szVerifierHelpFile,
  746. HELP_WM_HELP,
  747. (DWORD_PTR) MyHelpIds );
  748. return lResult;
  749. }
  750. /////////////////////////////////////////////////////////////////////////////
  751. void CDriverCountersPage::OnContextMenu(CWnd* pWnd, CPoint point)
  752. {
  753. ::WinHelp(
  754. pWnd->m_hWnd,
  755. g_szVerifierHelpFile,
  756. HELP_CONTEXTMENU,
  757. (DWORD_PTR) MyHelpIds );
  758. }