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.

1330 lines
42 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. ctrsprop.cpp
  5. Abstract:
  6. Implementation of the counters general property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <strsafe.h>
  10. #include <pdh.h>
  11. #include <pdhmsg.h>
  12. #include "smlogs.h"
  13. #include "smcfgmsg.h"
  14. #include "smctrqry.h"
  15. #include "ctrsprop.h"
  16. #include "smlogres.h"
  17. #include <pdhp.h>
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. USE_HANDLE_MACROS("SMLOGCFG(ctrsprop.cpp)");
  24. static ULONG
  25. s_aulHelpIds[] =
  26. {
  27. IDC_CTRS_COUNTER_LIST, IDH_CTRS_COUNTER_LIST,
  28. IDC_CTRS_ADD_BTN, IDH_CTRS_ADD_BTN,
  29. IDC_CTRS_ADD_OBJ_BTN, IDH_CTRS_ADD_OBJ_BTN,
  30. IDC_CTRS_REMOVE_BTN, IDH_CTRS_REMOVE_BTN,
  31. IDC_CTRS_FILENAME_DISPLAY, IDH_CTRS_FILENAME_DISPLAY,
  32. IDC_CTRS_SAMPLE_SPIN, IDH_CTRS_SAMPLE_EDIT,
  33. IDC_CTRS_SAMPLE_EDIT, IDH_CTRS_SAMPLE_EDIT,
  34. IDC_CTRS_SAMPLE_UNITS_COMBO,IDH_CTRS_SAMPLE_UNITS_COMBO,
  35. IDC_RUNAS_EDIT, IDH_RUNAS_EDIT,
  36. IDC_SETPWD_BTN, IDH_SETPWD_BTN,
  37. 0,0
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CCountersProperty property page
  41. IMPLEMENT_DYNCREATE(CCountersProperty, CSmPropertyPage)
  42. CCountersProperty::CCountersProperty(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  43. : CSmPropertyPage ( CCountersProperty::IDD, hConsole )
  44. // lCookie is really the pointer to the Log Query object
  45. {
  46. //::OutputDebugStringA("\nCCountersProperty::CCountersProperty");
  47. // save pointers from arg list
  48. m_pCtrLogQuery = reinterpret_cast <CSmCounterLogQuery *>(mmcCookie);
  49. ASSERT ( m_pCtrLogQuery->CastToCounterLogQuery() );
  50. m_pQuery = dynamic_cast <CSmLogQuery*> (m_pCtrLogQuery);
  51. ZeroMemory ( &m_dlgConfig, sizeof(m_dlgConfig) );
  52. m_szCounterListBuffer = NULL;
  53. m_dwCounterListBufferSize = 0;
  54. m_lCounterListHasStars = 0;
  55. m_dwMaxHorizListExtent = 0;
  56. memset(&m_HashTable, 0, sizeof(m_HashTable));
  57. // EnableAutomation();
  58. //{{AFX_DATA_INIT(CCountersProperty)
  59. m_nSampleUnits = 0;
  60. //}}AFX_DATA_INIT
  61. }
  62. CCountersProperty::CCountersProperty() : CSmPropertyPage ( CCountersProperty::IDD )
  63. {
  64. ASSERT (FALSE); // the constructor w/ args should be used instead
  65. }
  66. CCountersProperty::~CCountersProperty()
  67. {
  68. // ::OutputDebugStringA("\nCCountersProperty::~CCountersProperty");
  69. if (m_szCounterListBuffer != NULL) {
  70. delete [] m_szCounterListBuffer;
  71. }
  72. ClearCountersHashTable();
  73. }
  74. void CCountersProperty::OnFinalRelease()
  75. {
  76. // When the last reference for an automation object is released
  77. // OnFinalRelease is called. The base class will automatically
  78. // deletes the object. Add additional cleanup required for your
  79. // object before calling the base class.
  80. CPropertyPage::OnFinalRelease();
  81. }
  82. void CCountersProperty::DoDataExchange(CDataExchange* pDX)
  83. {
  84. CString strTemp;
  85. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  86. CPropertyPage::DoDataExchange(pDX);
  87. //{{AFX_DATA_MAP(CCountersProperty)
  88. DDX_Text(pDX, IDC_CTRS_LOG_SCHED_TEXT, m_strStartDisplay);
  89. ValidateTextEdit(pDX, IDC_CTRS_SAMPLE_EDIT, 6, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  90. DDX_CBIndex(pDX, IDC_CTRS_SAMPLE_UNITS_COMBO, m_nSampleUnits);
  91. DDX_Text(pDX, IDC_RUNAS_EDIT, m_strUserDisplay );
  92. //}}AFX_DATA_MAP
  93. if ( pDX->m_bSaveAndValidate ) {
  94. m_SharedData.stiSampleTime.dwUnitType =
  95. (DWORD)((CComboBox *)GetDlgItem(IDC_CTRS_SAMPLE_UNITS_COMBO))->
  96. GetItemData(m_nSampleUnits);
  97. }
  98. }
  99. BEGIN_MESSAGE_MAP(CCountersProperty, CSmPropertyPage)
  100. //{{AFX_MSG_MAP(CCountersProperty)
  101. ON_BN_CLICKED(IDC_CTRS_ADD_BTN, OnCtrsAddBtn)
  102. ON_BN_CLICKED(IDC_CTRS_ADD_OBJ_BTN, OnCtrsAddObjBtn)
  103. ON_BN_CLICKED(IDC_CTRS_REMOVE_BTN, OnCtrsRemoveBtn)
  104. ON_LBN_DBLCLK(IDC_CTRS_COUNTER_LIST, OnDblclkCtrsCounterList)
  105. ON_EN_CHANGE(IDC_CTRS_SAMPLE_EDIT, OnKillfocusSchedSampleEdit)
  106. ON_EN_KILLFOCUS(IDC_CTRS_SAMPLE_EDIT, OnKillfocusSchedSampleEdit)
  107. ON_EN_CHANGE( IDC_RUNAS_EDIT, OnChangeUser )
  108. ON_NOTIFY(UDN_DELTAPOS, IDC_CTRS_SAMPLE_SPIN, OnDeltaposSchedSampleSpin)
  109. ON_CBN_SELENDOK(IDC_CTRS_SAMPLE_UNITS_COMBO, OnSelendokSampleUnitsCombo)
  110. ON_BN_CLICKED(IDC_SETPWD_BTN, OnPwdBtn)
  111. ON_WM_DESTROY()
  112. //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114. BEGIN_DISPATCH_MAP(CCountersProperty, CSmPropertyPage)
  115. //{{AFX_DISPATCH_MAP(CCountersProperty)
  116. // NOTE - the ClassWizard will add and remove mapping macros here.
  117. //}}AFX_DISPATCH_MAP
  118. END_DISPATCH_MAP()
  119. // Note: we add support for IID_ICountersProperty to support typesafe binding
  120. // from VBA. This IID must match the GUID that is attached to the
  121. // dispinterface in the .ODL file.
  122. // {65154EA9-BDBE-11D1-BF99-00C04F94A83A}
  123. static const IID IID_ICountersProperty =
  124. { 0x65154ea9, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  125. BEGIN_INTERFACE_MAP(CCountersProperty, CSmPropertyPage)
  126. INTERFACE_PART(CCountersProperty, IID_ICountersProperty, Dispatch)
  127. END_INTERFACE_MAP()
  128. ULONG
  129. CCountersProperty::HashCounter(
  130. LPWSTR szCounterName
  131. )
  132. {
  133. ULONG h = 0;
  134. ULONG a = 31415; //a, b, k are primes
  135. const ULONG k = 16381;
  136. const ULONG b = 27183;
  137. LPWSTR szThisChar;
  138. if (szCounterName) {
  139. for (szThisChar = szCounterName; * szThisChar; szThisChar ++) {
  140. h = (a * h + ((ULONG) (* szThisChar))) % k;
  141. a = a * b % (k - 1);
  142. }
  143. }
  144. return (h % eHashTableSize);
  145. }
  146. //++
  147. // Description:
  148. // Remove a counter path from hash table. One counter
  149. // path must exactly match the given one in order to be
  150. // removed, even it is one with wildcard
  151. //
  152. // Parameters:
  153. // pszCounterPath - Pointer to counter path to be removed
  154. //
  155. // Return:
  156. // Return TRUE if the counter path is removed, otherwis return FALSE
  157. //--
  158. BOOL
  159. CCountersProperty::RemoveCounterFromHashTable(
  160. LPWSTR szCounterName,
  161. PPDH_COUNTER_PATH_ELEMENTS pCounterPath
  162. )
  163. {
  164. ULONG lHashValue;
  165. PHASH_ENTRY pEntry = NULL;
  166. PHASH_ENTRY pPrev = NULL;
  167. BOOL bReturn = FALSE;
  168. SetLastError(ERROR_SUCCESS);
  169. if (szCounterName == NULL || pCounterPath == NULL) {
  170. SetLastError(ERROR_INVALID_PARAMETER);
  171. goto ErrorOut;
  172. }
  173. lHashValue = HashCounter(szCounterName);
  174. pEntry = m_HashTable[lHashValue];
  175. //
  176. // Check if there is a counter path which is exactly the same
  177. // as the given one
  178. //
  179. while (pEntry) {
  180. if (pEntry->pCounter == pCounterPath)
  181. break;
  182. pPrev = pEntry;
  183. pEntry = pEntry->pNext;
  184. }
  185. //
  186. // If we found it, remove it
  187. //
  188. if (pEntry) {
  189. if (pPrev == NULL) {
  190. m_HashTable[lHashValue] = pEntry->pNext;
  191. }
  192. else {
  193. pPrev->pNext = pEntry->pNext;
  194. }
  195. G_FREE(pEntry->pCounter);
  196. G_FREE(pEntry);
  197. bReturn = TRUE;
  198. }
  199. ErrorOut:
  200. return bReturn;
  201. }
  202. //++
  203. // Description:
  204. // Insert a counter path into hash table.
  205. //
  206. // Parameters:
  207. // pszCounterPath - Pointer to counter path to be inserted
  208. //
  209. // Return:
  210. // Return the pointer to new inserted PDH_COUNTER_PATH_ELEMENTS structure
  211. //--
  212. PPDH_COUNTER_PATH_ELEMENTS
  213. CCountersProperty::InsertCounterToHashTable(
  214. LPWSTR pszCounterPath
  215. )
  216. {
  217. ULONG lHashValue;
  218. PHASH_ENTRY pNewEntry = NULL;
  219. PPDH_COUNTER_PATH_ELEMENTS pCounter = NULL;
  220. PDH_STATUS pdhStatus;
  221. if (pszCounterPath == NULL) {
  222. SetLastError(ERROR_INVALID_PARAMETER);
  223. goto ErrorOut;
  224. }
  225. pdhStatus = AllocInitCounterPath ( pszCounterPath, &pCounter );
  226. if (pdhStatus != ERROR_SUCCESS) {
  227. SetLastError( pdhStatus );
  228. goto ErrorOut;
  229. }
  230. //
  231. // Insert at head of bucket list
  232. //
  233. lHashValue = HashCounter(pszCounterPath);
  234. pNewEntry = (PHASH_ENTRY) G_ALLOC(sizeof(HASH_ENTRY));
  235. if (pNewEntry == NULL) {
  236. SetLastError( ERROR_OUTOFMEMORY );
  237. goto ErrorOut;
  238. }
  239. pNewEntry->pCounter = pCounter;
  240. pNewEntry->pNext = m_HashTable[lHashValue];
  241. m_HashTable[lHashValue] = pNewEntry;
  242. return pCounter;
  243. ErrorOut:
  244. if (pCounter != NULL)
  245. G_FREE (pCounter);
  246. return NULL;
  247. }
  248. //++
  249. // Description:
  250. // Check if the new counter path overlaps with a existing
  251. // one in logical sense
  252. //
  253. // Parameters:
  254. // pCounter - Pointer to counter path to be inserted
  255. //
  256. // Return:
  257. // Return the relation between the new and existing counter
  258. // paths. Possible relation is as following:
  259. // ERROR_SUCCESS - The two counter paths are different
  260. // SMCFG_DUPL_FIRST_IS_WILD - The first counter path has wildcard name
  261. // SMCFG_DUPL_SECOND_IS_WILD - The second counter path has wildcard name
  262. // SMCFG_DUPL_SINGLE_PATH - The two counter paths are the same(may
  263. // contain wildcard)
  264. //--
  265. DWORD
  266. CCountersProperty::CheckDuplicate( PPDH_COUNTER_PATH_ELEMENTS pCounter)
  267. {
  268. ULONG lHashValue;
  269. PHASH_ENTRY pHead;
  270. PHASH_ENTRY pEntry;
  271. DWORD dwStatus = ERROR_SUCCESS;
  272. for (lHashValue = 0; lHashValue < eHashTableSize; lHashValue++) {
  273. pHead = m_HashTable[lHashValue];
  274. if (pHead == NULL)
  275. continue;
  276. pEntry = pHead;
  277. while (pEntry) {
  278. dwStatus = CheckDuplicateCounterPaths ( pEntry->pCounter, pCounter );
  279. if ( dwStatus != ERROR_SUCCESS ) {
  280. return dwStatus;
  281. }
  282. pEntry = pEntry->pNext;
  283. }
  284. }
  285. return dwStatus;
  286. }
  287. //++
  288. // Description:
  289. // The function clears all the entries in hash table
  290. // and set hash-table-not-set-up flag
  291. //
  292. // Parameters:
  293. // None
  294. //
  295. // Return:
  296. // None
  297. //--
  298. void
  299. CCountersProperty::ClearCountersHashTable( void )
  300. {
  301. ULONG i;
  302. PHASH_ENTRY pEntry;
  303. PHASH_ENTRY pNext;
  304. for (i = 0; i < eHashTableSize; i ++) {
  305. pNext = m_HashTable[i];
  306. while (pNext != NULL) {
  307. pEntry = pNext;
  308. pNext = pEntry->pNext;
  309. G_FREE(pEntry->pCounter);
  310. G_FREE(pEntry);
  311. pEntry = NULL;
  312. }
  313. }
  314. }
  315. static
  316. PDH_FUNCTION
  317. DialogCallBack(CCountersProperty *pDlg)
  318. {
  319. // add strings in buffer to list box
  320. LPWSTR szNewCounterName;
  321. INT iListIndex;
  322. INT iItemCnt;
  323. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  324. DWORD dwReturnStatus = ERROR_SUCCESS;
  325. CListBox *pCounterList;
  326. DWORD dwItemExtent;
  327. DWORD dwStatus = ERROR_SUCCESS;
  328. BOOL bAtLeastOneCounterRemoved = FALSE;
  329. BOOL bAtLeastOneCounterNotAdded = FALSE;
  330. LPWSTR szCounterPath = NULL;
  331. LONG lSize = 0;
  332. PPDH_COUNTER_PATH_ELEMENTS pPathInfoNew = NULL;
  333. CDC* pCDC = NULL;
  334. ResourceStateManager rsm;
  335. #define CTRBUFLIMIT (0x7fffffff)
  336. if ( PDH_MORE_DATA == pDlg->m_dlgConfig.CallBackStatus ) {
  337. if ( pDlg->m_dlgConfig.cchReturnPathLength < CTRBUFLIMIT ) {
  338. pDlg->m_dwCounterListBufferSize *= 2;
  339. delete [] pDlg->m_szCounterListBuffer;
  340. pDlg->m_szCounterListBuffer = NULL;
  341. try {
  342. pDlg->m_szCounterListBuffer = new WCHAR[pDlg->m_dwCounterListBufferSize];
  343. } catch ( ... ) {
  344. pDlg->m_dwCounterListBufferSize = 0;
  345. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  346. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  347. }
  348. if ( ERROR_SUCCESS == dwReturnStatus ) {
  349. // clear buffer
  350. memset (
  351. pDlg->m_szCounterListBuffer,
  352. 0,
  353. pDlg->m_dwCounterListBufferSize * sizeof(WCHAR) );
  354. pDlg->m_dlgConfig.szReturnPathBuffer = pDlg->m_szCounterListBuffer;
  355. pDlg->m_dlgConfig.cchReturnPathLength = pDlg->m_dwCounterListBufferSize;
  356. pDlg->m_dlgConfig.CallBackStatus = PDH_RETRY;
  357. dwReturnStatus = PDH_RETRY;
  358. }
  359. } else {
  360. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  361. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  362. }
  363. } else if ( ERROR_SUCCESS == pDlg->m_dlgConfig.CallBackStatus ) {
  364. pCounterList = (CListBox *)pDlg->GetDlgItem(IDC_CTRS_COUNTER_LIST);
  365. if ( NULL != pCounterList ) {
  366. pCDC = pCounterList->GetDC();
  367. }
  368. if ( NULL != pCDC ) {
  369. for (szNewCounterName = pDlg->m_szCounterListBuffer;
  370. *szNewCounterName != 0;
  371. szNewCounterName += (lstrlen(szNewCounterName) + 1)) {
  372. //
  373. // Parse new pathname
  374. //
  375. pdhStatus = pDlg->AllocInitCounterPath ( szNewCounterName, &pPathInfoNew );
  376. //
  377. // Check for duplicate
  378. //
  379. if (pdhStatus == ERROR_SUCCESS && NULL != pPathInfoNew ) {
  380. dwStatus = pDlg->CheckDuplicate( pPathInfoNew);
  381. if ( ERROR_SUCCESS != dwStatus ) {
  382. if ( SMCFG_DUPL_SINGLE_PATH == dwStatus
  383. || SMCFG_DUPL_FIRST_IS_WILD == dwStatus ) {
  384. // NOTE: This includes case where both first
  385. // and second are wild.
  386. bAtLeastOneCounterNotAdded = TRUE;
  387. } else {
  388. ASSERT( dwStatus == SMCFG_DUPL_SECOND_IS_WILD);
  389. }
  390. }
  391. }
  392. //
  393. // Check if there is a valid counter to add to the list
  394. //
  395. if ( ERROR_SUCCESS == pdhStatus && ( NULL != pPathInfoNew ) &&
  396. ( ERROR_SUCCESS == dwStatus || SMCFG_DUPL_SECOND_IS_WILD == dwStatus)) {
  397. if ( SMCFG_DUPL_SECOND_IS_WILD == dwStatus ) {
  398. //
  399. // Scan for the duplicated items in the list box and
  400. // remove them
  401. //
  402. iItemCnt = pCounterList->GetCount();
  403. szCounterPath = new WCHAR [MAX_PATH+1];
  404. if (szCounterPath == NULL) {
  405. return PDH_MEMORY_ALLOCATION_FAILURE;
  406. }
  407. lSize = MAX_PATH;
  408. for (iListIndex = iItemCnt-1; iListIndex >= 0; iListIndex--) {
  409. PPDH_COUNTER_PATH_ELEMENTS pPathInfoExist;
  410. if (pCounterList->GetTextLen(iListIndex) > lSize) {
  411. delete [] szCounterPath;
  412. lSize = max(pCounterList->GetTextLen(iListIndex) + 1, lSize*2);
  413. szCounterPath = new WCHAR [lSize];
  414. if (szCounterPath == NULL) {
  415. return PDH_MEMORY_ALLOCATION_FAILURE;
  416. }
  417. }
  418. if ( 0 < pCounterList->GetText( iListIndex, szCounterPath ) ) {
  419. pPathInfoExist = (PPDH_COUNTER_PATH_ELEMENTS)
  420. pCounterList->GetItemDataPtr(iListIndex);
  421. if (pPathInfoExist == NULL)
  422. continue;
  423. dwStatus = CheckDuplicateCounterPaths ( pPathInfoExist, pPathInfoNew );
  424. if (dwStatus != ERROR_SUCCESS ) {
  425. ASSERT( dwStatus == SMCFG_DUPL_SECOND_IS_WILD );
  426. pDlg->RemoveCounterFromHashTable(szCounterPath, pPathInfoExist);
  427. pCounterList->DeleteString(iListIndex);
  428. }
  429. }
  430. }
  431. if (szCounterPath) {
  432. delete [] szCounterPath;
  433. }
  434. bAtLeastOneCounterRemoved = TRUE;
  435. }
  436. //
  437. // Add new counter name and select the current entry in the list box
  438. //
  439. iListIndex = pCounterList->AddString(szNewCounterName);
  440. if (iListIndex != LB_ERR) {
  441. if (pDlg->m_lCounterListHasStars != PDLCNFIG_LISTBOX_STARS_YES) {
  442. // save a string compare if this value is already set
  443. if (wcsstr (szNewCounterName, L"*") == NULL) {
  444. pDlg->m_lCounterListHasStars = PDLCNFIG_LISTBOX_STARS_YES;
  445. }
  446. }
  447. if (! bAtLeastOneCounterRemoved) {
  448. // update list box extent
  449. if ( NULL != pCDC ) {
  450. dwItemExtent = (DWORD)(pCDC->GetTextExtent (szNewCounterName)).cx;
  451. if (dwItemExtent > pDlg->m_dwMaxHorizListExtent) {
  452. pDlg->m_dwMaxHorizListExtent = dwItemExtent;
  453. pCounterList->SetHorizontalExtent(dwItemExtent);
  454. }
  455. }
  456. }
  457. pCounterList->SetSel (-1, FALSE); // cancel existing selections
  458. pCounterList->SetSel (iListIndex);
  459. pCounterList->SetCaretIndex (iListIndex);
  460. pCounterList->SetItemDataPtr(iListIndex,
  461. (void*)pDlg->InsertCounterToHashTable(szNewCounterName));
  462. }
  463. }
  464. if ( ERROR_SUCCESS != pdhStatus ) {
  465. // Message box Pdh error message, go on to next
  466. CString strMsg;
  467. CString strPdhMessage;
  468. FormatSystemMessage ( pdhStatus, strPdhMessage );
  469. MFC_TRY
  470. strMsg.Format ( IDS_CTRS_PDH_ERROR, szNewCounterName );
  471. strMsg += strPdhMessage;
  472. MFC_CATCH_MINIMUM
  473. ::AfxMessageBox( strMsg, MB_OK|MB_ICONERROR, 0 );
  474. }
  475. // Go on to next path to add
  476. dwStatus = ERROR_SUCCESS;
  477. }
  478. } else {
  479. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  480. }
  481. if ( ERROR_SUCCESS == dwReturnStatus && bAtLeastOneCounterRemoved) {
  482. //
  483. // Clear the max extent and recalculate
  484. //
  485. pDlg->m_dwMaxHorizListExtent = 0;
  486. for ( iListIndex = 0; iListIndex < pCounterList->GetCount(); iListIndex++ ) {
  487. pCounterList->GetText(iListIndex, szCounterPath);
  488. if ( NULL != pCDC ) {
  489. dwItemExtent = (DWORD)(pCDC->GetTextExtent(szCounterPath)).cx;
  490. if (dwItemExtent > pDlg->m_dwMaxHorizListExtent) {
  491. pDlg->m_dwMaxHorizListExtent = dwItemExtent;
  492. }
  493. }
  494. }
  495. pCounterList->SetHorizontalExtent(pDlg->m_dwMaxHorizListExtent);
  496. }
  497. if ( NULL != pCDC ) {
  498. pCounterList->ReleaseDC(pCDC);
  499. pCDC = NULL;
  500. }
  501. // Message box re: duplicates not added, or duplicates were removed.
  502. if ( bAtLeastOneCounterRemoved ) {
  503. CString strMsg;
  504. strMsg.LoadString ( IDS_CTRS_DUPL_PATH_DELETED );
  505. ::AfxMessageBox ( strMsg, MB_OK | MB_ICONWARNING, 0);
  506. }
  507. if ( bAtLeastOneCounterNotAdded ) {
  508. CString strMsg;
  509. strMsg.LoadString ( IDS_CTRS_DUPL_PATH_NOT_ADDED );
  510. ::AfxMessageBox( strMsg, MB_OK|MB_ICONWARNING, 0 );
  511. }
  512. // clear buffer
  513. memset (pDlg->m_szCounterListBuffer, 0, pDlg->m_dwCounterListBufferSize);
  514. dwReturnStatus = ERROR_SUCCESS;
  515. } else {
  516. // Not successful
  517. dwReturnStatus = pDlg->m_dlgConfig.CallBackStatus;
  518. }
  519. return dwReturnStatus;
  520. }
  521. void CCountersProperty::OnPwdBtn()
  522. {
  523. CString strTempUser;
  524. UpdateData(TRUE);
  525. if (!m_bCanAccessRemoteWbem) {
  526. ConnectRemoteWbemFail(m_pCtrLogQuery, TRUE);
  527. return;
  528. }
  529. MFC_TRY
  530. strTempUser = m_strUserDisplay;
  531. m_strUserDisplay.TrimLeft();
  532. m_strUserDisplay.TrimRight();
  533. m_pCtrLogQuery->m_strUser = m_strUserDisplay;
  534. SetRunAs(m_pCtrLogQuery);
  535. m_strUserDisplay = m_pCtrLogQuery->m_strUser;
  536. if ( 0 != strTempUser.CompareNoCase ( m_strUserDisplay ) ) {
  537. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  538. }
  539. MFC_CATCH_MINIMUM;
  540. }
  541. BOOL
  542. CCountersProperty::IsValidLocalData()
  543. {
  544. BOOL bIsValid = TRUE;
  545. CListBox * pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  546. long lNumCounters;
  547. ResourceStateManager rsm;
  548. lNumCounters = pCounterList->GetCount();
  549. if ( 0 == lNumCounters ) {
  550. CString strMsg;
  551. bIsValid = FALSE;
  552. strMsg.LoadString ( IDS_CTRS_REQUIRED );
  553. MessageBox ( strMsg, m_pCtrLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  554. GetDlgItem ( IDC_CTRS_ADD_BTN )->SetFocus();
  555. }
  556. if (bIsValid) {
  557. // Validate sample interval value
  558. bIsValid = ValidateDWordInterval(IDC_CTRS_SAMPLE_EDIT,
  559. m_pCtrLogQuery->GetLogName(),
  560. (long) m_SharedData.stiSampleTime.dwValue,
  561. eMinSampleInterval,
  562. eMaxSampleInterval);
  563. }
  564. if (bIsValid) {
  565. // Validate sample interval value and unit type
  566. bIsValid = SampleIntervalIsInRange(
  567. m_SharedData.stiSampleTime,
  568. m_pCtrLogQuery->GetLogName() );
  569. if ( !bIsValid ) {
  570. GetDlgItem ( IDC_CTRS_SAMPLE_EDIT )->SetFocus();
  571. }
  572. }
  573. return bIsValid;
  574. }
  575. /////////////////////////////////////////////////////////////////////////////
  576. // CCountersProperty message handlers
  577. void
  578. CCountersProperty::OnChangeUser()
  579. {
  580. //
  581. // If you can not access remote WBEM, you can not modify RunAs info,
  582. // changing the user name is not allowed.
  583. //
  584. if (m_bCanAccessRemoteWbem) {
  585. //
  586. // When the user hits OK in the password dialog,
  587. // the user name might not have changed.
  588. //
  589. UpdateData ( TRUE );
  590. m_strUserDisplay.TrimLeft();
  591. m_strUserDisplay.TrimRight();
  592. if ( 0 != m_strUserSaved.Compare ( m_strUserDisplay ) ) {
  593. m_pCtrLogQuery->m_fDirtyPassword = PASSWORD_DIRTY;
  594. SetModifiedPage(TRUE);
  595. }
  596. else {
  597. m_pCtrLogQuery->m_fDirtyPassword &= ~PASSWORD_DIRTY;
  598. }
  599. //
  600. // If default user is typed, never need to set password
  601. //
  602. if (m_strUserDisplay.IsEmpty() || m_strUserDisplay.GetAt(0) == L'<') {
  603. if (m_bPwdButtonEnabled) {
  604. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  605. m_bPwdButtonEnabled = FALSE;
  606. }
  607. }
  608. else {
  609. if (!m_bPwdButtonEnabled) {
  610. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(TRUE);
  611. m_bPwdButtonEnabled = TRUE;
  612. }
  613. }
  614. }
  615. else {
  616. //
  617. // We can not modify the RunAs info, then display
  618. // an error message and retore the original user name in RunAs
  619. //
  620. UpdateData(TRUE);
  621. if (ConnectRemoteWbemFail(m_pCtrLogQuery, FALSE)) {
  622. GetDlgItem(IDC_RUNAS_EDIT)->SetWindowText(m_strUserSaved);
  623. }
  624. }
  625. }
  626. void
  627. CCountersProperty::OnCtrsAddBtn()
  628. {
  629. ImplementAdd( FALSE );
  630. }
  631. void
  632. CCountersProperty::OnCtrsAddObjBtn()
  633. {
  634. ImplementAdd( TRUE );
  635. }
  636. void CCountersProperty::OnCtrsRemoveBtn()
  637. {
  638. CListBox *pCounterList;
  639. LONG lThisItem;
  640. BOOL bDone;
  641. LONG lOrigCaret;
  642. LONG lItemStatus;
  643. LONG lItemCount;
  644. BOOL bChanged = FALSE;
  645. DWORD dwItemExtent;
  646. CString strItemText;
  647. PPDH_COUNTER_PATH_ELEMENTS pCounter;
  648. CDC* pCDC = NULL;
  649. pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  650. if ( NULL == pCounterList ) {
  651. return;
  652. }
  653. // delete all selected items in the list box and
  654. // set the cursor to the item above the original caret position
  655. // or the first or last if that is out of the new range
  656. lOrigCaret = pCounterList->GetCaretIndex();
  657. lThisItem = 0;
  658. bDone = FALSE;
  659. // clear the max extent
  660. m_dwMaxHorizListExtent = 0;
  661. // clear the value and see if any non deleted items have a star, if so
  662. // then set the flag back
  663. pCDC = pCounterList->GetDC();
  664. if ( NULL != pCDC ) {
  665. do {
  666. lItemStatus = pCounterList->GetSel(lThisItem);
  667. if (lItemStatus > 0) {
  668. // then it's selected so delete it
  669. pCounterList->GetText(lThisItem, strItemText);
  670. pCounter = (PPDH_COUNTER_PATH_ELEMENTS) pCounterList->GetItemDataPtr(lThisItem);
  671. if (RemoveCounterFromHashTable(strItemText.GetBuffer(1), pCounter) == FALSE) {
  672. ClearCountersHashTable ();
  673. }
  674. pCounterList->DeleteString(lThisItem);
  675. bChanged = TRUE;
  676. } else if (lItemStatus == 0) {
  677. // get the text length of this item since it will stay
  678. pCounterList->GetText(lThisItem, strItemText);
  679. if (m_lCounterListHasStars != PDLCNFIG_LISTBOX_STARS_YES) {
  680. // save a string compare if this value is already set
  681. if (wcsstr (strItemText, L"*") == NULL) {
  682. m_lCounterListHasStars = PDLCNFIG_LISTBOX_STARS_YES;
  683. }
  684. }
  685. dwItemExtent = (DWORD)(pCDC->GetTextExtent(strItemText)).cx;
  686. if (dwItemExtent > m_dwMaxHorizListExtent) {
  687. m_dwMaxHorizListExtent = dwItemExtent;
  688. }
  689. // then it's not selected so go to the next one
  690. lThisItem++;
  691. } else {
  692. // we've run out so exit
  693. bDone = TRUE;
  694. }
  695. } while (!bDone);
  696. }
  697. if ( NULL != pCDC ) {
  698. pCounterList->ReleaseDC(pCDC);
  699. pCDC = NULL;
  700. }
  701. if ( bDone ) {
  702. // update the text extent of the list box
  703. pCounterList->SetHorizontalExtent(m_dwMaxHorizListExtent);
  704. }
  705. // see how many entries are left and update the
  706. // caret position and the remove button state
  707. lItemCount = pCounterList->GetCount();
  708. if (lItemCount > 0) {
  709. // the update the caret
  710. if (lOrigCaret >= lItemCount) {
  711. lOrigCaret = lItemCount-1;
  712. } else {
  713. // caret should be within the list
  714. }
  715. pCounterList->SetSel(lOrigCaret);
  716. pCounterList->SetCaretIndex(lOrigCaret);
  717. } else {
  718. // the list is empty so remove caret, selection
  719. // disable the remove button and activate the
  720. // add button
  721. pCounterList->SetSel(-1);
  722. }
  723. SetButtonState();
  724. SetModifiedPage(bChanged);
  725. }
  726. void CCountersProperty::OnDblclkCtrsCounterList()
  727. {
  728. ImplementAdd( FALSE );
  729. }
  730. BOOL CCountersProperty::OnSetActive()
  731. {
  732. BOOL bReturn;
  733. bReturn = CSmPropertyPage::OnSetActive();
  734. if (bReturn) {
  735. ResourceStateManager rsm;
  736. m_pCtrLogQuery->GetPropPageSharedData ( &m_SharedData );
  737. UpdateFileNameString();
  738. UpdateLogStartString();
  739. m_strUserDisplay = m_pCtrLogQuery->m_strUser;
  740. UpdateData(FALSE); //to load the edit & combo box
  741. }
  742. return bReturn;
  743. }
  744. BOOL CCountersProperty::OnKillActive()
  745. {
  746. BOOL bContinue = TRUE;
  747. ResourceStateManager rsm;
  748. bContinue = CPropertyPage::OnKillActive();
  749. if ( bContinue ) {
  750. m_pCtrLogQuery->m_strUser = m_strUserDisplay;
  751. bContinue = IsValidData(m_pCtrLogQuery, VALIDATE_FOCUS);
  752. if ( bContinue ) {
  753. m_pCtrLogQuery->SetPropPageSharedData ( &m_SharedData );
  754. SetIsActive ( FALSE );
  755. }
  756. }
  757. return bContinue;
  758. }
  759. void
  760. CCountersProperty::OnCancel()
  761. {
  762. m_pCtrLogQuery->SyncPropPageSharedData(); // clear memory shared between property pages.
  763. }
  764. BOOL
  765. CCountersProperty::OnApply()
  766. {
  767. CListBox * pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  768. long lThisCounter;
  769. BOOL bContinue = TRUE;
  770. LPWSTR szCounterPath = NULL;
  771. LONG lSize = 0;
  772. ResourceStateManager rsm;
  773. bContinue = UpdateData(TRUE);
  774. if ( bContinue ) {
  775. bContinue = IsValidData(m_pCtrLogQuery, VALIDATE_APPLY );
  776. }
  777. if ( bContinue ) {
  778. bContinue = SampleTimeIsLessThanSessionTime ( m_pCtrLogQuery );
  779. if ( !bContinue ) {
  780. SetFocusAnyPage ( IDC_CTRS_SAMPLE_EDIT );
  781. }
  782. }
  783. // Write data to the query object.
  784. if ( bContinue ) {
  785. ASSERT ( 0 < pCounterList->GetCount() );
  786. // update the counter MSZ string using the counters from the list box
  787. m_pCtrLogQuery->ResetCounterList(); // clear the old counter list
  788. szCounterPath = new WCHAR [MAX_PATH+1];
  789. if (szCounterPath == NULL) {
  790. return FALSE;
  791. }
  792. lSize = MAX_PATH;
  793. for ( lThisCounter = 0; lThisCounter < pCounterList->GetCount(); lThisCounter++ ) {
  794. if (pCounterList->GetTextLen(lThisCounter) > lSize) {
  795. delete [] szCounterPath;
  796. lSize = max(pCounterList->GetTextLen(lThisCounter) + 1, lSize*2);
  797. szCounterPath = new WCHAR [lSize];
  798. if (szCounterPath == NULL) {
  799. bContinue = FALSE;
  800. break;
  801. }
  802. }
  803. pCounterList->GetText(lThisCounter, szCounterPath);
  804. m_pCtrLogQuery->AddCounter(szCounterPath);
  805. }
  806. if (szCounterPath != NULL)
  807. delete [] szCounterPath;
  808. if ( bContinue ) {
  809. // Sample interval
  810. ASSERT ( SLQ_TT_TTYPE_SAMPLE == m_SharedData.stiSampleTime.wTimeType );
  811. ASSERT ( SLQ_TT_DTYPE_UNITS == m_SharedData.stiSampleTime.wDataType );
  812. bContinue = m_pCtrLogQuery->SetLogTime (&m_SharedData.stiSampleTime, (DWORD)m_SharedData.stiSampleTime.wTimeType);
  813. // Save property page shared data.
  814. m_pCtrLogQuery->UpdatePropPageSharedData();
  815. if ( bContinue ) {
  816. // ApplyRunAs must be called before UpdateService
  817. bContinue = ApplyRunAs(m_pCtrLogQuery);
  818. }
  819. if ( bContinue ) {
  820. bContinue = UpdateService( m_pCtrLogQuery, TRUE );
  821. }
  822. }
  823. }
  824. if ( bContinue ){
  825. bContinue = CSmPropertyPage::OnApply();
  826. }
  827. return bContinue;
  828. }
  829. void
  830. CCountersProperty::UpdateLogStartString ()
  831. {
  832. eStartType eCurrentStartType;
  833. int nResId = 0;
  834. ResourceStateManager rsm;
  835. eCurrentStartType = DetermineCurrentStartType();
  836. if ( eStartManually == eCurrentStartType ) {
  837. nResId = IDS_LOG_START_MANUALLY;
  838. } else if ( eStartImmediately == eCurrentStartType ) {
  839. nResId = IDS_LOG_START_IMMED;
  840. } else if ( eStartSched == eCurrentStartType ) {
  841. nResId = IDS_LOG_START_SCHED;
  842. }
  843. if ( 0 != nResId ) {
  844. m_strStartDisplay.LoadString(nResId);
  845. } else {
  846. m_strStartDisplay.Empty();
  847. }
  848. return;
  849. }
  850. void CCountersProperty::UpdateFileNameString ()
  851. {
  852. m_strFileNameDisplay.Empty();
  853. // Todo: Handle failure status
  854. // Todo: Check pointers
  855. CreateSampleFileName (
  856. m_pCtrLogQuery->GetLogName(),
  857. m_pCtrLogQuery->GetLogService()->GetMachineName(),
  858. m_SharedData.strFolderName,
  859. m_SharedData.strFileBaseName,
  860. m_SharedData.strSqlName,
  861. m_SharedData.dwSuffix,
  862. m_SharedData.dwLogFileType,
  863. m_SharedData.dwSerialNumber,
  864. m_strFileNameDisplay );
  865. SetDlgItemText( IDC_CTRS_FILENAME_DISPLAY, m_strFileNameDisplay );
  866. // Clear the selection
  867. ((CEdit*)GetDlgItem( IDC_CTRS_FILENAME_DISPLAY ))->SetSel ( -1, FALSE );
  868. return;
  869. }
  870. BOOL CCountersProperty::OnInitDialog()
  871. {
  872. LPWSTR szCounterName;
  873. CListBox * pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  874. CComboBox *pCombo;
  875. int nIndex;
  876. CString strComboBoxString;
  877. int nResult;
  878. DWORD dwItemExtent;
  879. PPDH_COUNTER_PATH_ELEMENTS pCounterPath;
  880. CDC* pCDC = NULL;
  881. ResourceStateManager rsm;
  882. //
  883. // Here m_pCtrLogQuery should not be NULL, if it is,
  884. // There must be something wrong.
  885. //
  886. if ( NULL == m_pCtrLogQuery ) {
  887. return TRUE;
  888. }
  889. m_pCtrLogQuery->TranslateCounterListToLocale();
  890. m_bCanAccessRemoteWbem = m_pCtrLogQuery->GetLogService()->CanAccessWbemRemote();
  891. MFC_TRY
  892. m_pCtrLogQuery->SetActivePropertyPage( this );
  893. //load counter list box from string in counter list
  894. pCounterList->ResetContent();
  895. ClearCountersHashTable();
  896. szCounterName = (LPWSTR)m_pCtrLogQuery->GetFirstCounter();
  897. pCDC = pCounterList->GetDC();
  898. while (szCounterName != NULL) {
  899. nIndex = pCounterList->AddString(szCounterName);
  900. if (nIndex < 0)
  901. continue;
  902. //
  903. // Insert counter path into hash table
  904. //
  905. pCounterPath = InsertCounterToHashTable(szCounterName);
  906. if (pCounterPath == NULL) {
  907. pCounterList->DeleteString(nIndex);
  908. continue;
  909. }
  910. pCounterList->SetItemDataPtr(nIndex, (void*)pCounterPath);
  911. // update list box extent
  912. if ( NULL != pCDC ) {
  913. dwItemExtent = (DWORD)(pCDC->GetTextExtent (szCounterName)).cx;
  914. if (dwItemExtent > m_dwMaxHorizListExtent) {
  915. m_dwMaxHorizListExtent = dwItemExtent;
  916. }
  917. }
  918. szCounterName = (LPWSTR)m_pCtrLogQuery->GetNextCounter();
  919. }
  920. if ( NULL != pCDC ) {
  921. pCounterList->ReleaseDC(pCDC);
  922. pCDC = NULL;
  923. }
  924. if (m_dwMaxHorizListExtent != 0) {
  925. pCounterList->SetHorizontalExtent(m_dwMaxHorizListExtent);
  926. }
  927. if (pCounterList->GetCount() > 0) {
  928. // select first entry
  929. pCounterList->SetSel (0, TRUE);
  930. pCounterList->SetCaretIndex (0, TRUE);
  931. }
  932. // Load the shared data to get the sample unit type selection.
  933. m_pCtrLogQuery->GetPropPageSharedData ( &m_SharedData );
  934. // load combo boxes
  935. pCombo = (CComboBox *)(GetDlgItem(IDC_CTRS_SAMPLE_UNITS_COMBO));
  936. pCombo->ResetContent();
  937. for (nIndex = 0; nIndex < (int)dwTimeUnitComboEntries; nIndex++) {
  938. strComboBoxString.LoadString( TimeUnitCombo[nIndex].nResId );
  939. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  940. ASSERT (nResult != CB_ERR);
  941. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  942. ASSERT (nResult != CB_ERR);
  943. // set selected in combo box here
  944. if ( m_SharedData.stiSampleTime.dwUnitType == (DWORD)(TimeUnitCombo[nIndex].nData)) {
  945. m_nSampleUnits = nIndex;
  946. nResult = pCombo->SetCurSel(nIndex);
  947. ASSERT (nResult != CB_ERR);
  948. }
  949. }
  950. CSmPropertyPage::OnInitDialog();
  951. Initialize( m_pCtrLogQuery );
  952. m_strUserDisplay = m_pCtrLogQuery->m_strUser;
  953. m_strUserSaved = m_strUserDisplay;
  954. if (m_pCtrLogQuery->GetLogService()->TargetOs() == OS_WIN2K) {
  955. GetDlgItem(IDC_RUNAS_STATIC)->EnableWindow(FALSE);
  956. GetDlgItem(IDC_RUNAS_EDIT)->EnableWindow(FALSE);
  957. }
  958. if ( m_pCtrLogQuery->GetLogService()->TargetOs() == OS_WIN2K ||
  959. m_strUserDisplay.IsEmpty() ||
  960. m_strUserDisplay.GetAt(0) == L'<') {
  961. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  962. m_bPwdButtonEnabled = FALSE;
  963. }
  964. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  965. SetButtonState();
  966. MFC_CATCH_MINIMUM;
  967. return TRUE; // return TRUE unless you set the focus to a control
  968. // EXCEPTION: OCX Property Pages should return FALSE
  969. }
  970. void
  971. CCountersProperty::OnDeltaposSchedSampleSpin(NMHDR* pNMHDR, LRESULT* pResult)
  972. {
  973. OnDeltaposSpin(pNMHDR, pResult, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  974. }
  975. void
  976. CCountersProperty::OnSelendokSampleUnitsCombo()
  977. {
  978. int nSel;
  979. nSel = ((CComboBox *)GetDlgItem(IDC_CTRS_SAMPLE_UNITS_COMBO))->GetCurSel();
  980. if ((nSel != LB_ERR) && (nSel != m_nSampleUnits)) {
  981. UpdateData ( TRUE );
  982. SetModifiedPage ( TRUE );
  983. }
  984. }
  985. void
  986. CCountersProperty::OnKillfocusSchedSampleEdit()
  987. {
  988. DWORD dwOldValue;
  989. dwOldValue = m_SharedData.stiSampleTime.dwValue;
  990. UpdateData ( TRUE );
  991. if (dwOldValue != m_SharedData.stiSampleTime.dwValue ) {
  992. SetModifiedPage(TRUE);
  993. }
  994. }
  995. void CCountersProperty::PostNcDestroy()
  996. {
  997. // delete this;
  998. if ( NULL != m_pCtrLogQuery ) {
  999. m_pCtrLogQuery->SetActivePropertyPage( NULL );
  1000. }
  1001. CPropertyPage::PostNcDestroy();
  1002. }
  1003. //
  1004. // Helper functions.
  1005. //
  1006. void
  1007. CCountersProperty::ImplementAdd( BOOL bShowObjects )
  1008. {
  1009. CListBox *pCounterList;
  1010. LONG lBeforeCount;
  1011. LONG lAfterCount;
  1012. CString strBrowseTitle;
  1013. ResourceStateManager rsm;
  1014. static DWORD sdwDefaultBufferListSize = 0x4000;
  1015. if (m_szCounterListBuffer == NULL) {
  1016. CString strDefaultPath;
  1017. CString strObjCounter;
  1018. try {
  1019. strObjCounter.LoadString ( IDS_DEFAULT_PATH_OBJ_CTR );
  1020. m_dwCounterListBufferSize = sdwDefaultBufferListSize;
  1021. m_szCounterListBuffer = new WCHAR[m_dwCounterListBufferSize];
  1022. if ( ((CSmLogService*)m_pCtrLogQuery->GetLogService())->IsLocalMachine() ) {
  1023. strDefaultPath = L"\\";
  1024. } else {
  1025. strDefaultPath = L"\\\\";
  1026. strDefaultPath += ((CSmLogService*)m_pCtrLogQuery->GetLogService())->GetMachineName();
  1027. }
  1028. strDefaultPath += strObjCounter;
  1029. StringCchCopy ( m_szCounterListBuffer, m_dwCounterListBufferSize, strDefaultPath );
  1030. } catch ( ... ) {
  1031. m_dwCounterListBufferSize = 0;
  1032. return;
  1033. }
  1034. }
  1035. m_dlgConfig.bIncludeInstanceIndex = 1;
  1036. m_dlgConfig.bSingleCounterPerAdd = 0;
  1037. m_dlgConfig.bSingleCounterPerDialog = 0;
  1038. m_dlgConfig.bLocalCountersOnly = 0;
  1039. // allow wild cards.
  1040. // the log service should expand them if necessary.
  1041. m_dlgConfig.bWildCardInstances = 1;
  1042. m_dlgConfig.bHideDetailBox = 1;
  1043. m_dlgConfig.bInitializePath = 1;
  1044. m_dlgConfig.bDisableMachineSelection = 0;
  1045. m_dlgConfig.bIncludeCostlyObjects = 0;
  1046. m_dlgConfig.bReserved = 0;
  1047. m_dlgConfig.hWndOwner = this->m_hWnd;
  1048. m_dlgConfig.szDataSource = NULL;
  1049. m_dlgConfig.szReturnPathBuffer = m_szCounterListBuffer;
  1050. m_dlgConfig.cchReturnPathLength = m_dwCounterListBufferSize;
  1051. m_dlgConfig.pCallBack = (CounterPathCallBack)DialogCallBack;
  1052. m_dlgConfig.dwDefaultDetailLevel = PERF_DETAIL_WIZARD;
  1053. m_dlgConfig.dwCallBackArg = (UINT_PTR)this;
  1054. m_dlgConfig.CallBackStatus = ERROR_SUCCESS;
  1055. m_dlgConfig.bShowObjectBrowser = (bShowObjects ? 1 : 0);
  1056. strBrowseTitle.LoadString (bShowObjects ? IDS_ADD_OBJECTS
  1057. : IDS_ADD_COUNTERS);
  1058. m_dlgConfig.szDialogBoxCaption = strBrowseTitle.GetBuffer( strBrowseTitle.GetLength() );
  1059. pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  1060. // get count of items in the list box before calling the browser
  1061. lBeforeCount = pCounterList->GetCount();
  1062. PdhBrowseCounters (&m_dlgConfig);
  1063. strBrowseTitle.ReleaseBuffer();
  1064. // get count of items in the list box After calling the browser
  1065. // to see if the Apply button should enabled
  1066. lAfterCount = pCounterList->GetCount();
  1067. if (lAfterCount > lBeforeCount)
  1068. SetModifiedPage(TRUE);
  1069. // see if the remove button should be enabled
  1070. SetButtonState();
  1071. delete [] m_szCounterListBuffer;
  1072. m_szCounterListBuffer = NULL;
  1073. m_dwCounterListBufferSize = 0;
  1074. }
  1075. void
  1076. CCountersProperty::SetButtonState ()
  1077. {
  1078. BOOL bCountersExist;
  1079. CListBox *pCounterList;
  1080. pCounterList = (CListBox *)GetDlgItem(IDC_CTRS_COUNTER_LIST);
  1081. bCountersExist = ( 0 < pCounterList->GetCount()) ? TRUE : FALSE;
  1082. GetDlgItem(IDC_CTRS_SAMPLE_CAPTION)->EnableWindow(bCountersExist);
  1083. GetDlgItem(IDC_CTRS_SAMPLE_INTERVAL_CAPTION)->EnableWindow(bCountersExist);
  1084. GetDlgItem(IDC_CTRS_SAMPLE_EDIT)->EnableWindow(bCountersExist);
  1085. GetDlgItem(IDC_CTRS_SAMPLE_SPIN)->EnableWindow(bCountersExist);
  1086. GetDlgItem(IDC_CTRS_SAMPLE_UNITS_CAPTION)->EnableWindow(bCountersExist);
  1087. GetDlgItem(IDC_CTRS_SAMPLE_UNITS_COMBO)->EnableWindow(bCountersExist);
  1088. GetDlgItem(IDC_CTRS_REMOVE_BTN)->EnableWindow(bCountersExist);
  1089. if ( bCountersExist ) {
  1090. GetDlgItem(IDC_CTRS_ADD_BTN)->SetFocus();
  1091. }
  1092. }