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.

1397 lines
44 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. alrtgenp.cpp
  5. Abstract:
  6. Implementation of the alerts general property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <assert.h>
  10. #include <math.h>
  11. #include <limits.h>
  12. #include <float.h>
  13. #include <pdh.h>
  14. #include <pdhmsg.h>
  15. #include <common.h>
  16. #include "smcfgmsg.h"
  17. #include "dialogs.h"
  18. #include "smlogs.h"
  19. #include "smalrtq.h"
  20. #include "AlrtGenP.h"
  21. #include <pdhp.h>
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. USE_HANDLE_MACROS("SMLOGCFG(alrtgenp.cpp)");
  28. static const COMBO_BOX_DATA_MAP OverUnderCombo[] =
  29. {
  30. {OU_OVER, IDS_OVER},
  31. {OU_UNDER, IDS_UNDER}
  32. };
  33. static const DWORD dwOverUnderComboEntries = sizeof(OverUnderCombo)/sizeof(OverUnderCombo[0]);
  34. static ULONG
  35. s_aulHelpIds[] =
  36. {
  37. IDC_ALRTS_COUNTER_LIST, IDH_ALRTS_COUNTER_LIST,
  38. IDC_ALRTS_ADD_BTN, IDH_ALRTS_ADD_BTN,
  39. IDC_ALRTS_REMOVE_BTN, IDH_ALRTS_REMOVE_BTN,
  40. IDC_ALRTS_OVER_UNDER, IDH_ALRTS_OVER_UNDER,
  41. IDC_ALRTS_VALUE_EDIT, IDH_ALRTS_VALUE_EDIT,
  42. IDC_ALRTS_COMMENT_EDIT, IDH_ALRTS_COMMENT_EDIT,
  43. IDC_ALRTS_SAMPLE_EDIT, IDH_ALRTS_SAMPLE_EDIT,
  44. IDC_ALRTS_SAMPLE_SPIN, IDH_ALRTS_SAMPLE_EDIT,
  45. IDC_ALRTS_SAMPLE_UNITS_COMBO, IDH_ALRTS_SAMPLE_UNITS_COMBO,
  46. IDC_RUNAS_EDIT, IDH_RUNAS_EDIT,
  47. 0,0
  48. };
  49. ULONG
  50. CAlertGenProp::HashCounter(
  51. LPTSTR szCounterName,
  52. ULONG lHashSize)
  53. {
  54. ULONG h = 0;
  55. ULONG a = 31415; //a, b, k are primes
  56. const ULONG k = 16381;
  57. const ULONG b = 27183;
  58. LPTSTR szThisChar;
  59. TCHAR Char;
  60. if (szCounterName) {
  61. for (szThisChar = szCounterName; * szThisChar; szThisChar ++) {
  62. Char = * szThisChar;
  63. if (_istupper(Char) ) {
  64. Char = _tolower(Char);
  65. }
  66. h = (a * h + ((ULONG) Char)) % k;
  67. a = a * b % (k - 1);
  68. }
  69. }
  70. return (h % lHashSize);
  71. }
  72. BOOL
  73. CAlertGenProp::InsertAlertToHashTable(
  74. PALERT_INFO_BLOCK paibInfo )
  75. {
  76. ULONG lHashValue;
  77. PHASH_ENTRY pEntry;
  78. PHASH_ENTRY pNewEntry = NULL;
  79. BOOLEAN bInsert = TRUE;
  80. PPDH_COUNTER_PATH_ELEMENTS pCounter = NULL;
  81. PDH_STATUS pdhStatus;
  82. // Todo: validate pointers
  83. lHashValue = HashCounter(paibInfo->szCounterPath, eHashTableSize);
  84. pEntry = m_HashTable[lHashValue];
  85. pdhStatus = AllocInitCounterPath ( paibInfo->szCounterPath, &pCounter );
  86. if (pdhStatus == ERROR_SUCCESS) {
  87. while (pEntry) {
  88. if ( ( AIBF_OVER & pEntry->dwFlags ) == ( AIBF_OVER & paibInfo->dwFlags )
  89. && pEntry->dLimit == paibInfo->dLimit
  90. && ERROR_SUCCESS != CheckDuplicateCounterPaths(pCounter, pEntry->pCounter ) )
  91. {
  92. bInsert = FALSE;
  93. break;
  94. }
  95. pEntry = pEntry->pNext;
  96. }
  97. if (bInsert) {
  98. // Insert at head of bucket list
  99. pNewEntry = (PHASH_ENTRY) G_ALLOC(sizeof(HASH_ENTRY));
  100. if (pNewEntry) {
  101. pNewEntry->pCounter = pCounter;
  102. pNewEntry->dwFlags = paibInfo->dwFlags;
  103. pNewEntry->dLimit = paibInfo->dLimit;
  104. pNewEntry->pNext = m_HashTable[lHashValue];
  105. m_HashTable[lHashValue] = pNewEntry;
  106. } else {
  107. pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  108. bInsert = FALSE;
  109. }
  110. }
  111. } else {
  112. if ( NULL != pCounter ) {
  113. delete pCounter;
  114. }
  115. bInsert = FALSE;
  116. }
  117. if ( !bInsert ) {
  118. // Set status on error // Todo: Only set status if pdhStatus != 0.
  119. // Will need to pass pdhStatus as a parameter in order to do this.
  120. SetLastError(pdhStatus);
  121. }
  122. return (bInsert);
  123. }
  124. void
  125. CAlertGenProp::InitAlertHashTable( void )
  126. {
  127. memset(&m_HashTable, 0, sizeof(m_HashTable));
  128. }
  129. void
  130. CAlertGenProp::ClearAlertHashTable( void )
  131. {
  132. ULONG i;
  133. PHASH_ENTRY pEntry;
  134. PHASH_ENTRY pNext;
  135. for (i = 0; i < eHashTableSize; i ++) {
  136. pNext = m_HashTable[i];
  137. while (pNext != NULL) {
  138. pEntry = pNext;
  139. pNext = pEntry->pNext;
  140. G_FREE(pEntry->pCounter);
  141. G_FREE(pEntry);
  142. }
  143. }
  144. }
  145. //
  146. // browse counters callback function
  147. //
  148. static
  149. PDH_FUNCTION
  150. DialogCallBack(CAlertGenProp *pDlg)
  151. {
  152. // add strings in buffer to list box
  153. LPTSTR NewCounterName;
  154. INT iListIndex;
  155. LONG lFirstNewIndex = LB_ERR;
  156. DWORD dwItemExtent;
  157. CListBox *pCounterList;
  158. PALERT_INFO_BLOCK paibInfo = NULL;
  159. DWORD dwIbSize;
  160. DWORD dwReturnStatus = ERROR_SUCCESS;
  161. CDC* pCDC = NULL;
  162. ResourceStateManager rsm;
  163. #define CTRBUFLIMIT (0x7fffffff)
  164. if ( PDH_MORE_DATA == pDlg->m_dlgConfig.CallBackStatus ) {
  165. if ( pDlg->m_dlgConfig.cchReturnPathLength < CTRBUFLIMIT ) {
  166. pDlg->m_dwCounterListBufferSize *= 2;
  167. delete pDlg->m_szCounterListBuffer;
  168. pDlg->m_szCounterListBuffer = NULL;
  169. try {
  170. pDlg->m_szCounterListBuffer = new WCHAR[pDlg->m_dwCounterListBufferSize];
  171. } catch ( ... ) {
  172. pDlg->m_dwCounterListBufferSize = 0;
  173. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  174. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  175. }
  176. if ( ERROR_SUCCESS == dwReturnStatus ) {
  177. // clear buffer
  178. memset (pDlg->m_szCounterListBuffer, 0, pDlg->m_dwCounterListBufferSize);
  179. pDlg->m_dlgConfig.szReturnPathBuffer = pDlg->m_szCounterListBuffer;
  180. pDlg->m_dlgConfig.cchReturnPathLength = pDlg->m_dwCounterListBufferSize;
  181. pDlg->m_dlgConfig.CallBackStatus = PDH_RETRY;
  182. dwReturnStatus = PDH_RETRY;
  183. }
  184. } else {
  185. pDlg->m_dlgConfig.CallBackStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  186. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  187. }
  188. } else if ( ERROR_SUCCESS == pDlg->m_dlgConfig.CallBackStatus ) {
  189. pCounterList = (CListBox *)pDlg->GetDlgItem(IDC_ALRTS_COUNTER_LIST);
  190. pCDC = pCounterList->GetDC();
  191. for (NewCounterName = pDlg->m_szCounterListBuffer;
  192. *NewCounterName != 0;
  193. NewCounterName += (lstrlen(NewCounterName) + 1)) {
  194. // Allocate a buffer to hold the alert info and
  195. // add to list box
  196. dwIbSize = sizeof(ALERT_INFO_BLOCK) +
  197. ((lstrlen(NewCounterName) + 1) * sizeof(WCHAR));
  198. MFC_TRY
  199. paibInfo = (PALERT_INFO_BLOCK) new UCHAR[dwIbSize];
  200. MFC_CATCH_MINIMUM;
  201. if (paibInfo != NULL) {
  202. // load the fields
  203. paibInfo->dwSize = dwIbSize;
  204. paibInfo->szCounterPath = (LPTSTR)&paibInfo[1];
  205. paibInfo->dwFlags = AIBF_OVER; // clear all the flags, setting default to "Over"
  206. paibInfo->dLimit = CAlertGenProp::eInvalidLimit;
  207. lstrcpyW (paibInfo->szCounterPath, NewCounterName);
  208. // Insert the new string at the end of the list box.
  209. iListIndex = pCounterList->InsertString (-1, NewCounterName );
  210. if (iListIndex != LB_ERR) {
  211. pCounterList->SetItemDataPtr (iListIndex, (LPVOID)paibInfo);
  212. if ( LB_ERR == lFirstNewIndex )
  213. lFirstNewIndex = iListIndex;
  214. // update list box extent
  215. if ( NULL != pCDC ) {
  216. dwItemExtent = (DWORD)(pCDC->GetTextExtent(NewCounterName)).cx;
  217. if (dwItemExtent > pDlg->m_dwMaxHorizListExtent) {
  218. pDlg->m_dwMaxHorizListExtent = dwItemExtent;
  219. pCounterList->SetHorizontalExtent(dwItemExtent);
  220. }
  221. }
  222. } else {
  223. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  224. delete paibInfo;
  225. }
  226. } else {
  227. dwReturnStatus = PDH_MEMORY_ALLOCATION_FAILURE;
  228. }
  229. }
  230. if ( NULL != pCDC ) {
  231. pDlg->m_CounterList.ReleaseDC(pCDC);
  232. pCDC = NULL;
  233. }
  234. // select the first new entry in the list box.
  235. if (lFirstNewIndex != LB_ERR) {
  236. pCounterList->SetCurSel (lFirstNewIndex);
  237. pDlg->PublicOnSelchangeCounterList();
  238. pDlg->SetModifiedPage(); // to indicate a change
  239. }
  240. // clear buffer
  241. memset (pDlg->m_szCounterListBuffer, 0, pDlg->m_dwCounterListBufferSize);
  242. dwReturnStatus = ERROR_SUCCESS;
  243. } else {
  244. // Not successful
  245. dwReturnStatus = pDlg->m_dlgConfig.CallBackStatus;
  246. }
  247. return dwReturnStatus;
  248. }
  249. /////////////////////////////////////////////////////////////////////////////
  250. // CAlertGenProp property page
  251. IMPLEMENT_DYNCREATE(CAlertGenProp, CSmPropertyPage)
  252. CAlertGenProp::CAlertGenProp(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  253. : CSmPropertyPage ( CAlertGenProp::IDD, hConsole )
  254. {
  255. // save variables from arg list
  256. m_pAlertQuery = reinterpret_cast <CSmAlertQuery *>(mmcCookie);
  257. ASSERT ( m_pAlertQuery->CastToAlertQuery() );
  258. // init AFX variables
  259. InitAfxDataItems();
  260. // init other member variables
  261. ZeroMemory ( &m_dlgConfig, sizeof(m_dlgConfig) );
  262. m_szCounterListBuffer = NULL;
  263. m_dwCounterListBufferSize = 0L;
  264. m_ndxCurrentItem = LB_ERR; // nothing selected
  265. m_szAlertCounterList = NULL;
  266. m_cchAlertCounterListSize = 0;
  267. m_dwMaxHorizListExtent = 0;
  268. }
  269. CAlertGenProp::CAlertGenProp() : CSmPropertyPage(CAlertGenProp::IDD)
  270. {
  271. ASSERT (FALSE); // the constructor w/ args should be used instead
  272. // init variables that should be from arg list
  273. m_pAlertQuery = NULL;
  274. // init AFX variables
  275. InitAfxDataItems();
  276. // init other member variables
  277. m_szCounterListBuffer = NULL;
  278. m_dwCounterListBufferSize = 0L;
  279. m_ndxCurrentItem = LB_ERR; // nothing selected
  280. m_szAlertCounterList = NULL;
  281. m_cchAlertCounterListSize = 0;
  282. m_dwMaxHorizListExtent = 0;
  283. }
  284. CAlertGenProp::~CAlertGenProp()
  285. {
  286. if (m_szAlertCounterList != NULL) delete (m_szAlertCounterList);
  287. if (m_szCounterListBuffer != NULL) delete (m_szCounterListBuffer);
  288. }
  289. void CAlertGenProp::InitAfxDataItems()
  290. {
  291. //{{AFX_DATA_INIT(CAlertGenProp)
  292. m_dLimitValue = eInvalidLimit;
  293. m_nSampleUnits = 0;
  294. //}}AFX_DATA_INIT
  295. }
  296. void CAlertGenProp::DoDataExchange(CDataExchange* pDX)
  297. {
  298. HWND hWndCtrl = NULL;
  299. CString strTemp;
  300. TCHAR szT[MAXSTR];
  301. LPTSTR szStop;
  302. DOUBLE dTemp;
  303. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  304. CPropertyPage::DoDataExchange(pDX);
  305. //{{AFX_DATA_MAP(CAlertGenProp)
  306. DDX_Control(pDX, IDC_ALRTS_SAMPLE_UNITS_COMBO, m_SampleUnitsCombo);
  307. DDX_Control(pDX, IDC_ALRTS_OVER_UNDER, m_OverUnderCombo);
  308. DDX_Control(pDX, IDC_ALRTS_COUNTER_LIST, m_CounterList);
  309. ValidateTextEdit(pDX, IDC_ALRTS_SAMPLE_EDIT, 6, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  310. DDX_CBIndex(pDX, IDC_ALRTS_SAMPLE_UNITS_COMBO, m_nSampleUnits);
  311. DDX_Text(pDX, IDC_ALRTS_COMMENT_EDIT, m_strComment);
  312. DDV_MaxChars(pDX, m_strComment, 255);
  313. DDX_Text(pDX, IDC_ALRTS_START_STRING, m_strStartDisplay);
  314. DDX_Text(pDX, IDC_RUNAS_EDIT, m_strUserDisplay );
  315. //}}AFX_DATA_MAP
  316. //
  317. // User defined DDX
  318. //
  319. if ( pDX->m_bSaveAndValidate ) {
  320. m_SharedData.stiSampleTime.dwUnitType =
  321. (DWORD)((CComboBox *)GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO))->
  322. GetItemData(m_nSampleUnits);
  323. }
  324. // Alert limit value
  325. {
  326. hWndCtrl = pDX->PrepareEditCtrl(IDC_ALRTS_VALUE_EDIT);
  327. if (pDX->m_bSaveAndValidate) {
  328. ::GetWindowText(hWndCtrl, szT, MAXSTR);
  329. strTemp = szT;
  330. DDV_MaxChars(pDX, strTemp, 23);
  331. if (szT[0] == _T('.') || (szT[0] >= _T('0') && szT[0] <= _T('9'))) {
  332. dTemp = _tcstod(szT, & szStop);
  333. if ( HUGE_VAL != dTemp ) {
  334. m_dLimitValue = dTemp;
  335. } else {
  336. _stprintf(szT, _T("%.*g"), DBL_DIG, m_dLimitValue);
  337. strTemp.Format (IDS_ALERT_CHECK_LIMIT_VALUE, DBL_MAX );
  338. MessageBox (strTemp, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  339. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetWindowText(szT);
  340. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetFocus();
  341. }
  342. } else {
  343. m_dLimitValue = eInvalidLimit;
  344. }
  345. } else {
  346. if ( eInvalidLimit != m_dLimitValue ) {
  347. _stprintf(szT, _T("%.*g"), DBL_DIG, m_dLimitValue);
  348. } else {
  349. // Display NULL string for invalid limit value.
  350. szT[0] = _T('\0');
  351. }
  352. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetWindowText(szT);
  353. }
  354. }
  355. }
  356. void CAlertGenProp::ImplementAdd()
  357. {
  358. LONG lBeforeCount;
  359. LONG lAfterCount;
  360. CString strText;
  361. CString strBrowseTitle;
  362. CString strDefaultPath;
  363. CString strObjCounter;
  364. ResourceStateManager rsm;
  365. if (m_szCounterListBuffer == NULL) {
  366. MFC_TRY
  367. strObjCounter.LoadString ( IDS_DEFAULT_PATH_OBJ_CTR );
  368. m_dwCounterListBufferSize = 0x4000;
  369. m_szCounterListBuffer = new WCHAR[m_dwCounterListBufferSize];
  370. if ( ((CSmLogService*)m_pAlertQuery->GetLogService())->IsLocalMachine() ) {
  371. strDefaultPath = _T("\\");
  372. } else {
  373. strDefaultPath = _T("\\\\");
  374. strDefaultPath += ((CSmLogService*)m_pAlertQuery->GetLogService())->GetMachineName();
  375. }
  376. strDefaultPath += strObjCounter;
  377. lstrcpy ( m_szCounterListBuffer, strDefaultPath);
  378. MFC_CATCH_MINIMUM;
  379. if ( NULL != m_szCounterListBuffer && !strDefaultPath.IsEmpty() ) {
  380. lstrcpy ( m_szCounterListBuffer, strDefaultPath);
  381. } else {
  382. m_dwCounterListBufferSize = 0;
  383. return;
  384. }
  385. }
  386. m_dlgConfig.bIncludeInstanceIndex = 1;
  387. m_dlgConfig.bLocalCountersOnly = 0;
  388. m_dlgConfig.bSingleCounterPerAdd = 0;
  389. m_dlgConfig.bSingleCounterPerDialog = 0;
  390. // disallow wild cards.
  391. m_dlgConfig.bWildCardInstances = 0;
  392. m_dlgConfig.bHideDetailBox = 1;
  393. m_dlgConfig.bInitializePath = 1;
  394. m_dlgConfig.bDisableMachineSelection = 0;
  395. m_dlgConfig.bIncludeCostlyObjects = 0;
  396. m_dlgConfig.bReserved = 0;
  397. m_dlgConfig.hWndOwner = this->m_hWnd;
  398. m_dlgConfig.szDataSource = NULL;
  399. m_dlgConfig.szReturnPathBuffer = m_szCounterListBuffer;
  400. m_dlgConfig.cchReturnPathLength = m_dwCounterListBufferSize;
  401. m_dlgConfig.pCallBack = (CounterPathCallBack)DialogCallBack;
  402. m_dlgConfig.dwDefaultDetailLevel = PERF_DETAIL_WIZARD;
  403. m_dlgConfig.dwCallBackArg = (UINT_PTR)this;
  404. strBrowseTitle.LoadString ( IDS_ADD_COUNTERS );
  405. m_dlgConfig.szDialogBoxCaption = strBrowseTitle.GetBuffer( strBrowseTitle.GetLength() );
  406. // get count of items in the list box before calling the browser
  407. lBeforeCount = m_CounterList.GetCount();
  408. PdhBrowseCountersW (&m_dlgConfig);
  409. strBrowseTitle.ReleaseBuffer();
  410. // get count of items in the list box After calling the browser
  411. // to see if the Apply button should enabled
  412. lAfterCount = m_CounterList.GetCount();
  413. if (lAfterCount > lBeforeCount)
  414. SetModifiedPage(TRUE);
  415. // see if the remove button should be enabled
  416. GetDlgItem (IDC_ALRTS_REMOVE_BTN)->EnableWindow(
  417. lAfterCount > 0 ? TRUE : FALSE);
  418. delete m_szCounterListBuffer;
  419. m_szCounterListBuffer = NULL;
  420. m_dwCounterListBufferSize = 0;
  421. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetFocus();
  422. SetButtonState ();
  423. }
  424. BEGIN_MESSAGE_MAP(CAlertGenProp, CSmPropertyPage)
  425. //{{AFX_MSG_MAP(CAlertGenProp)
  426. ON_BN_CLICKED(IDC_ALRTS_ADD_BTN, OnAddBtn)
  427. ON_LBN_DBLCLK(IDC_ALRTS_COUNTER_LIST, OnDblclkAlrtsCounterList)
  428. ON_BN_CLICKED(IDC_ALRTS_REMOVE_BTN, OnRemoveBtn)
  429. ON_LBN_SELCHANGE(IDC_ALRTS_COUNTER_LIST, OnSelchangeCounterList)
  430. ON_EN_CHANGE(IDC_ALRTS_COMMENT_EDIT, OnCommentEditChange)
  431. ON_EN_KILLFOCUS(IDC_ALRTS_COMMENT_EDIT, OnCommentEditKillFocus)
  432. ON_NOTIFY(UDN_DELTAPOS, IDC_ALRTS_SAMPLE_SPIN, OnDeltaposSampleSpin)
  433. ON_CBN_SELENDOK(IDC_ALRTS_SAMPLE_UNITS_COMBO, OnSelendokSampleUnitsCombo)
  434. ON_EN_CHANGE( IDC_RUNAS_EDIT, OnChangeUser )
  435. ON_EN_CHANGE(IDC_ALRTS_SAMPLE_EDIT, OnSampleTimeChanged)
  436. ON_EN_KILLFOCUS(IDC_ALRTS_SAMPLE_EDIT, OnSampleTimeChanged)
  437. ON_CBN_SELENDOK(IDC_ALRTS_OVER_UNDER, OnKillFocusUpdateAlertData)
  438. ON_CBN_KILLFOCUS (IDC_ALRTS_OVER_UNDER, OnKillFocusUpdateAlertData)
  439. ON_EN_CHANGE(IDC_ALRTS_VALUE_EDIT, OnChangeAlertValueEdit)
  440. ON_EN_KILLFOCUS (IDC_ALRTS_VALUE_EDIT, OnKillFocusUpdateAlertData)
  441. ON_BN_CLICKED(IDC_SETPWD_BTN, OnPwdBtn)
  442. ON_WM_CLOSE()
  443. //}}AFX_MSG_MAP
  444. END_MESSAGE_MAP()
  445. /////////////////////////////////////////////////////////////////////////////
  446. // CAlertGenProp message handlers
  447. void
  448. CAlertGenProp::OnChangeUser()
  449. {
  450. //
  451. // If you can not access remote WBEM, you can not modify RunAs info,
  452. // changing the user name is not allowed.
  453. //
  454. if (m_bCanAccessRemoteWbem) {
  455. // When the user hits OK in the password dialog,
  456. // the user name might not have changed.
  457. UpdateData ( TRUE );
  458. m_strUserDisplay.TrimLeft();
  459. m_strUserDisplay.TrimRight();
  460. if ( 0 != m_strUserSaved.Compare ( m_strUserDisplay ) ) {
  461. m_pAlertQuery->m_fDirtyPassword = PASSWORD_DIRTY;
  462. SetModifiedPage(TRUE);
  463. }
  464. else {
  465. m_pAlertQuery->m_fDirtyPassword &= ~PASSWORD_DIRTY;
  466. }
  467. //
  468. // If default user is typed, never need to set password
  469. //
  470. if (m_strUserDisplay.IsEmpty() || m_strUserDisplay.GetAt(0) == L'<') {
  471. if (m_bPwdButtonEnabled) {
  472. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  473. m_bPwdButtonEnabled = FALSE;
  474. }
  475. }
  476. else {
  477. if (!m_bPwdButtonEnabled) {
  478. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(TRUE);
  479. m_bPwdButtonEnabled = TRUE;
  480. }
  481. }
  482. }
  483. else {
  484. //
  485. // We can not modify the RunAs info, then display
  486. // an error message and retore the original user name in RunAs
  487. //
  488. UpdateData(TRUE);
  489. if (ConnectRemoteWbemFail(m_pAlertQuery, FALSE)) {
  490. GetDlgItem(IDC_RUNAS_EDIT)->SetWindowText(m_strUserSaved);
  491. }
  492. }
  493. }
  494. void CAlertGenProp::OnPwdBtn()
  495. {
  496. CString strTempUser;
  497. UpdateData();
  498. if (!m_bCanAccessRemoteWbem) {
  499. ConnectRemoteWbemFail(m_pAlertQuery, TRUE);
  500. return;
  501. }
  502. MFC_TRY
  503. strTempUser = m_strUserDisplay;
  504. m_strUserDisplay.TrimLeft();
  505. m_strUserDisplay.TrimRight();
  506. m_pAlertQuery->m_strUser = m_strUserDisplay;
  507. SetRunAs(m_pAlertQuery);
  508. m_strUserDisplay = m_pAlertQuery->m_strUser;
  509. if ( 0 != strTempUser.CompareNoCase ( m_strUserDisplay ) ) {
  510. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  511. }
  512. MFC_CATCH_MINIMUM;
  513. }
  514. void CAlertGenProp::OnAddBtn()
  515. {
  516. ImplementAdd();
  517. return;
  518. }
  519. void CAlertGenProp::OnDblclkAlrtsCounterList()
  520. {
  521. ImplementAdd();
  522. return;
  523. }
  524. void CAlertGenProp::OnRemoveBtn()
  525. {
  526. PALERT_INFO_BLOCK paibInfo;
  527. INT nCurSel;
  528. INT nLbItemCount;
  529. BOOL bChanged = FALSE;
  530. DWORD dwItemExtent;
  531. INT iIndex;
  532. TCHAR szPath[MAX_PATH+1];
  533. nLbItemCount = m_CounterList.GetCount();
  534. nCurSel = m_CounterList.GetCurSel();
  535. if (nCurSel != LB_ERR) {
  536. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  537. if ( paibInfo != NULL )
  538. delete(paibInfo);
  539. if ( LB_ERR != m_CounterList.DeleteString(nCurSel) ) {
  540. // clear the max extent
  541. m_dwMaxHorizListExtent = 0;
  542. for ( iIndex = 0; iIndex < m_CounterList.GetCount(); iIndex++ ) {
  543. if ( 0 < m_CounterList.GetText( iIndex, szPath ) ) {
  544. dwItemExtent = (DWORD)((m_CounterList.GetDC())->GetTextExtent (szPath)).cx;
  545. if (dwItemExtent > m_dwMaxHorizListExtent) {
  546. m_dwMaxHorizListExtent = dwItemExtent;
  547. m_CounterList.SetHorizontalExtent(dwItemExtent);
  548. }
  549. }
  550. }
  551. if (nCurSel == (nLbItemCount - 1)) {
  552. // then the last item was deleted so select the new "last"
  553. if ( 0 == nCurSel ) {
  554. nCurSel = LB_ERR;
  555. } else {
  556. nCurSel--;
  557. }
  558. } //else the current selection should still be in the list box
  559. m_CounterList.SetCurSel (nCurSel);
  560. m_ndxCurrentItem = nCurSel;
  561. LoadAlertItemData (nCurSel);
  562. bChanged = TRUE;
  563. }
  564. }
  565. SetButtonState();
  566. SetModifiedPage(bChanged);
  567. }
  568. void CAlertGenProp::OnDeltaposSampleSpin(NMHDR* pNMHDR, LRESULT* pResult)
  569. {
  570. OnDeltaposSpin(pNMHDR, pResult, &m_SharedData.stiSampleTime.dwValue, eMinSampleInterval, eMaxSampleInterval);
  571. }
  572. void
  573. CAlertGenProp::OnSelendokSampleUnitsCombo()
  574. {
  575. int nSel;
  576. nSel = ((CComboBox *)GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO))->GetCurSel();
  577. if ((nSel != LB_ERR) && (nSel != m_nSampleUnits)) {
  578. UpdateData ( TRUE );
  579. SetModifiedPage ( TRUE );
  580. }
  581. }
  582. void CAlertGenProp::OnSampleTimeChanged()
  583. {
  584. DWORD dwOldValue;
  585. dwOldValue = m_SharedData.stiSampleTime.dwValue;
  586. UpdateData ( TRUE );
  587. if (dwOldValue != m_SharedData.stiSampleTime.dwValue) {
  588. SetModifiedPage(TRUE);
  589. }
  590. }
  591. void CAlertGenProp::OnChangeAlertValueEdit()
  592. {
  593. SaveAlertItemData();
  594. }
  595. void CAlertGenProp::PublicOnSelchangeCounterList()
  596. {
  597. OnSelchangeCounterList();
  598. }
  599. void CAlertGenProp::OnKillFocusUpdateAlertData()
  600. {
  601. SaveAlertItemData();
  602. }
  603. void CAlertGenProp::OnSelchangeCounterList()
  604. {
  605. INT nCurSel;
  606. nCurSel = m_CounterList.GetCurSel();
  607. if (nCurSel != LB_ERR) {
  608. // Save the data from the previous item.
  609. SaveAlertItemData();
  610. // Load the data from the new item.
  611. LoadAlertItemData(nCurSel);
  612. } else {
  613. // clear the fields
  614. m_dLimitValue=eInvalidLimit;
  615. UpdateData(FALSE);
  616. }
  617. }
  618. void
  619. CAlertGenProp::UpdateAlertStartString ()
  620. {
  621. eStartType eCurrentStartType;
  622. int nResId = 0;
  623. ResourceStateManager rsm;
  624. eCurrentStartType = DetermineCurrentStartType();
  625. if ( eStartManually == eCurrentStartType ) {
  626. nResId = IDS_ALERT_START_MANUALLY;
  627. } else if ( eStartImmediately == eCurrentStartType ) {
  628. nResId = IDS_ALERT_START_IMMED;
  629. } else if ( eStartSched == eCurrentStartType ) {
  630. nResId = IDS_ALERT_START_SCHED;
  631. }
  632. if ( 0 != nResId ) {
  633. m_strStartDisplay.LoadString(nResId);
  634. } else {
  635. m_strStartDisplay.Empty();
  636. }
  637. return;
  638. }
  639. BOOL CAlertGenProp::IsValidLocalData()
  640. {
  641. BOOL bIsValid = FALSE;
  642. INT nInvalidIndex = -1;
  643. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  644. PALERT_INFO_BLOCK paibInfo;
  645. int iListCount;
  646. int iIndex;
  647. BOOL bInsert;
  648. BOOL bAtLeastOneDuplicateCounter = FALSE;
  649. BOOL bSelectionDeleted = FALSE;
  650. CString strText;
  651. // test to see if there are any counters in the list box
  652. if (m_CounterList.GetCount() > 0) {
  653. if ( GetDlgItem(IDC_ALRTS_VALUE_EDIT) == GetFocus() ) {
  654. SaveAlertItemData(); // Set the Is Saved flag for this value.
  655. }
  656. bIsValid = LoadListFromDlg(&nInvalidIndex, TRUE);
  657. if ( ((!bIsValid) && (nInvalidIndex != -1))
  658. || ((m_dLimitValue < 0.0) || (m_dLimitValue > DBL_MAX)))
  659. {
  660. // then one of the list items has not been reviewed
  661. // by the user so remind them
  662. strText.Format (IDS_ALERT_CHECK_LIMITS, DBL_MAX );
  663. MessageBox (strText, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  664. m_CounterList.SetCurSel(nInvalidIndex);
  665. OnSelchangeCounterList();
  666. m_CounterList.SetFocus();
  667. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->SetFocus();
  668. bIsValid = FALSE;
  669. } else {
  670. // Eliminate duplicate alert paths, then reload the list
  671. iListCount = m_CounterList.GetCount();
  672. if ( LB_ERR != iListCount ) {
  673. InitAlertHashTable ( );
  674. // Walk the list backwards to delete duplicate items.
  675. for ( iIndex = iListCount - 1; iIndex >= 0; iIndex-- ) {
  676. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(iIndex);
  677. if ( NULL != paibInfo ) {
  678. bInsert = InsertAlertToHashTable ( paibInfo );
  679. pdhStatus = bInsert ? ERROR_SUCCESS : GetLastError();
  680. } else {
  681. bInsert = FALSE;
  682. }
  683. if (! bInsert && pdhStatus == ERROR_SUCCESS) {
  684. bAtLeastOneDuplicateCounter = TRUE;
  685. // Set item data pointer to NULL because
  686. // SaveAlertItemData can be called after this.
  687. // Clear the selection if >= current index.
  688. if ( m_ndxCurrentItem >= iIndex ) {
  689. m_ndxCurrentItem = LB_ERR;
  690. bSelectionDeleted = TRUE;
  691. }
  692. m_CounterList.SetItemDataPtr(iIndex, NULL);
  693. m_CounterList.DeleteString(iIndex);
  694. delete paibInfo;
  695. }
  696. if ( ERROR_SUCCESS != pdhStatus ) {
  697. // Message box Pdh error message, go on to next
  698. CString strMsg;
  699. CString strPdhMessage;
  700. FormatSystemMessage ( pdhStatus, strPdhMessage );
  701. MFC_TRY
  702. strMsg.Format ( IDS_CTRS_PDH_ERROR, paibInfo->szCounterPath );
  703. strMsg += strPdhMessage;
  704. MFC_CATCH_MINIMUM
  705. MessageBox ( strMsg, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  706. }
  707. }
  708. ClearAlertHashTable ( );
  709. if ( bAtLeastOneDuplicateCounter ) {
  710. CString strMsg;
  711. strMsg.LoadString ( IDS_ALERT_DUPL_PATH );
  712. MessageBox ( strMsg, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONWARNING);
  713. // Only deleting duplicates, so no need to recalculate the max extent
  714. // Reset the selection if necessary
  715. if ( bSelectionDeleted && LB_ERR == m_ndxCurrentItem ) {
  716. if (m_CounterList.GetCount() > 0) {
  717. m_CounterList.SetCurSel (0);
  718. m_ndxCurrentItem = 0;
  719. m_CounterList.SetFocus();
  720. LoadAlertItemData (0);
  721. }
  722. }
  723. }
  724. bIsValid = LoadListFromDlg ( &nInvalidIndex );
  725. assert ( bIsValid );
  726. }
  727. }
  728. } else {
  729. // the counter list is empty
  730. strText.LoadString (IDS_NO_COUNTERS);
  731. MessageBox (strText, m_pAlertQuery->GetLogName(), MB_OK | MB_ICONERROR);
  732. GetDlgItem(IDC_ALRTS_ADD_BTN)->SetFocus();
  733. bIsValid = FALSE;
  734. }
  735. if (bIsValid)
  736. {
  737. bIsValid = ValidateDWordInterval(IDC_ALRTS_SAMPLE_EDIT,
  738. m_pAlertQuery->GetLogName(),
  739. (long) m_SharedData.stiSampleTime.dwValue,
  740. eMinSampleInterval,
  741. eMaxSampleInterval);
  742. }
  743. if (bIsValid) {
  744. // Validate sample interval value and unit type
  745. bIsValid = SampleIntervalIsInRange(
  746. m_SharedData.stiSampleTime,
  747. m_pAlertQuery->GetLogName() );
  748. if ( !bIsValid ) {
  749. GetDlgItem ( IDC_ALRTS_SAMPLE_EDIT )->SetFocus();
  750. }
  751. }
  752. return bIsValid;
  753. }
  754. BOOL CAlertGenProp::OnSetActive()
  755. {
  756. BOOL bReturn;
  757. bReturn = CSmPropertyPage::OnSetActive();
  758. if (!bReturn) return FALSE;
  759. ResourceStateManager rsm;
  760. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  761. UpdateAlertStartString();
  762. m_strUserDisplay = m_pAlertQuery->m_strUser;
  763. UpdateData(FALSE); //to load the static string.
  764. return TRUE;
  765. }
  766. BOOL CAlertGenProp::OnKillActive()
  767. {
  768. BOOL bContinue = TRUE;
  769. ResourceStateManager rsm;
  770. // Parent class OnKillActive calls UpdateData(TRUE)
  771. bContinue = CPropertyPage::OnKillActive();
  772. if ( bContinue ) {
  773. m_pAlertQuery->m_strUser = m_strUserDisplay;
  774. bContinue = IsValidData(m_pAlertQuery, VALIDATE_FOCUS);
  775. if ( bContinue ) {
  776. // Save property page shared data.
  777. m_pAlertQuery->SetPropPageSharedData ( &m_SharedData );
  778. }
  779. }
  780. if ( bContinue ) {
  781. SetIsActive ( FALSE );
  782. }
  783. return bContinue;
  784. }
  785. BOOL CAlertGenProp::OnApply()
  786. {
  787. BOOL bContinue = TRUE;
  788. CString strText;
  789. ResourceStateManager rsm;
  790. bContinue = UpdateData(TRUE);
  791. if ( bContinue ) {
  792. bContinue = IsValidData(m_pAlertQuery, VALIDATE_APPLY );
  793. }
  794. if ( bContinue ) {
  795. bContinue = SampleTimeIsLessThanSessionTime( m_pAlertQuery );
  796. if ( !bContinue ) {
  797. GetDlgItem ( IDC_ALRTS_SAMPLE_EDIT )->SetFocus();
  798. }
  799. }
  800. // Write the data to the query.
  801. if ( bContinue ) {
  802. // send the list to the parent query
  803. // update counter list
  804. m_pAlertQuery->SetCounterList( m_szAlertCounterList, m_cchAlertCounterListSize );
  805. m_pAlertQuery->SetLogComment ( m_strComment );
  806. // Sample interval
  807. ASSERT ( SLQ_TT_TTYPE_SAMPLE == m_SharedData.stiSampleTime.wTimeType );
  808. ASSERT ( SLQ_TT_DTYPE_UNITS == m_SharedData.stiSampleTime.wDataType );
  809. // update counter sample interval
  810. bContinue = m_pAlertQuery->SetLogTime (&m_SharedData.stiSampleTime, (DWORD)m_SharedData.stiSampleTime.wTimeType);
  811. }
  812. if ( bContinue ) {
  813. bContinue = Apply(m_pAlertQuery);
  814. }
  815. if (bContinue) {
  816. bContinue = CPropertyPage::OnApply();
  817. }
  818. if (bContinue) {
  819. // Save property page shared data.
  820. m_pAlertQuery->UpdatePropPageSharedData();
  821. bContinue = UpdateService ( m_pAlertQuery, FALSE );
  822. }
  823. return bContinue;
  824. }
  825. void CAlertGenProp::OnCancel()
  826. {
  827. m_pAlertQuery->SyncPropPageSharedData(); // clear memory shared between property pages.
  828. }
  829. void CAlertGenProp::OnClose()
  830. {
  831. // free the item data pointers from the list box
  832. INT nNumItems;
  833. INT nCurSel;
  834. PALERT_INFO_BLOCK paibInfo;
  835. nNumItems = m_CounterList.GetCount();
  836. if (nNumItems != LB_ERR) {
  837. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  838. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  839. if (paibInfo != NULL) {
  840. delete (paibInfo);
  841. m_CounterList.SetItemDataPtr(nCurSel, NULL);
  842. }
  843. }
  844. }
  845. CPropertyPage::OnClose();
  846. }
  847. void CAlertGenProp::PostNcDestroy()
  848. {
  849. // delete this;
  850. if ( NULL != m_pAlertQuery ) {
  851. m_pAlertQuery->SetActivePropertyPage( NULL );
  852. }
  853. CPropertyPage::PostNcDestroy();
  854. }
  855. BOOL CAlertGenProp::SaveAlertItemData ()
  856. {
  857. // update the info block to reflect the current values
  858. PALERT_INFO_BLOCK paibInfo;
  859. BOOL bReturn = FALSE;
  860. CComboBox* pOverUnder;
  861. INT nCurSel;
  862. DWORD dwFlags;
  863. pOverUnder = (CComboBox *)GetDlgItem(IDC_ALRTS_OVER_UNDER);
  864. if ((pOverUnder != NULL) && (m_ndxCurrentItem != LB_ERR)) {
  865. nCurSel = m_ndxCurrentItem;
  866. if (nCurSel != LB_ERR) {
  867. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  868. if (paibInfo != NULL) {
  869. DWORD dwOldFlags;
  870. double dOldLimit;
  871. dwOldFlags = paibInfo->dwFlags;
  872. dOldLimit = paibInfo->dLimit;
  873. if (UpdateData(TRUE)) {
  874. paibInfo->dLimit = m_dLimitValue;
  875. dwFlags = (pOverUnder->GetCurSel() == OU_OVER) ? AIBF_OVER : 0;
  876. if ( eInvalidLimit < paibInfo->dLimit ) {
  877. dwFlags |= AIBF_SAVED;
  878. }
  879. paibInfo->dwFlags = dwFlags;
  880. if ( ( dOldLimit != m_dLimitValue )
  881. || ( dwOldFlags & AIBF_OVER ) != ( dwFlags & AIBF_OVER ) ) {
  882. SetModifiedPage(); // to indicate a change
  883. }
  884. bReturn = TRUE;
  885. }
  886. }
  887. }
  888. }
  889. return bReturn;
  890. }
  891. BOOL CAlertGenProp::LoadAlertItemData (INT nIndex)
  892. {
  893. // update the info block to reflect the current values
  894. PALERT_INFO_BLOCK paibInfo;
  895. BOOL bReturn = FALSE;
  896. CComboBox* pOverUnder;
  897. INT nCurSel;
  898. pOverUnder = (CComboBox *)GetDlgItem(IDC_ALRTS_OVER_UNDER);
  899. if ( pOverUnder != NULL ) {
  900. nCurSel = m_CounterList.GetCurSel();
  901. if (nCurSel != LB_ERR) {
  902. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  903. if (paibInfo != NULL) {
  904. pOverUnder->SetCurSel(
  905. ((paibInfo->dwFlags & AIBF_OVER) == AIBF_OVER) ? OU_OVER : OU_UNDER);
  906. m_dLimitValue = paibInfo->dLimit;
  907. m_ndxCurrentItem = nIndex;
  908. // If the data is loaded from a property bag, the limit might not have been seen.
  909. if ( eInvalidLimit < m_dLimitValue ) {
  910. paibInfo->dwFlags |= AIBF_SEEN;
  911. }
  912. UpdateData(FALSE);
  913. bReturn = TRUE;
  914. }
  915. }
  916. }
  917. return bReturn;
  918. }
  919. BOOL CAlertGenProp::SetButtonState ()
  920. {
  921. BOOL bState;
  922. // enable the windows base on whether or not the list box
  923. // has any contents
  924. bState = (m_CounterList.GetCount() > 0);
  925. GetDlgItem(IDC_ALRTS_TRIGGER_CAPTION)->EnableWindow(bState);
  926. GetDlgItem(IDC_ALRTS_TRIGGER_VALUE_CAPTION)->EnableWindow(bState);
  927. GetDlgItem(IDC_ALRTS_OVER_UNDER)->EnableWindow(bState);
  928. GetDlgItem(IDC_ALRTS_VALUE_EDIT)->EnableWindow(bState);
  929. GetDlgItem(IDC_ALRTS_REMOVE_BTN)->EnableWindow(bState);
  930. GetDlgItem(IDC_ALRTS_SAMPLE_EDIT)->EnableWindow(bState);
  931. GetDlgItem(IDC_ALRTS_SAMPLE_CAPTION)->EnableWindow(bState);
  932. GetDlgItem(IDC_ALRTS_SAMPLE_INTERVAL_CAPTION)->EnableWindow(bState);
  933. GetDlgItem(IDC_ALRTS_SAMPLE_SPIN)->EnableWindow(bState);
  934. GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_CAPTION)->EnableWindow(bState);
  935. GetDlgItem(IDC_ALRTS_SAMPLE_UNITS_COMBO)->EnableWindow(bState);
  936. if (m_pAlertQuery->GetLogService()->IsWindows2000Server()) {
  937. CWnd* pRunAsStatic;
  938. //
  939. // Get the static "Run As" window, you can only call this function
  940. // when "Run As" really exists
  941. //
  942. pRunAsStatic = GetRunAsWindow();
  943. if (pRunAsStatic) {
  944. pRunAsStatic->EnableWindow(FALSE);
  945. }
  946. GetDlgItem(IDC_RUNAS_EDIT)->EnableWindow(FALSE);
  947. }
  948. if (m_pAlertQuery->GetLogService()->IsWindows2000Server() ||
  949. m_strUserDisplay.IsEmpty() ||
  950. m_strUserDisplay.GetAt(0) == L'<') {
  951. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  952. m_bPwdButtonEnabled = FALSE;
  953. }
  954. return bState;
  955. }
  956. BOOL CAlertGenProp::LoadDlgFromList ()
  957. {
  958. BOOL bReturn = TRUE;
  959. LPTSTR szThisString = NULL;
  960. DWORD dwBufSize;
  961. DWORD dwThisStringLen;
  962. UINT nIndex;
  963. DWORD dwItemExtent;
  964. CDC* pCDC = NULL;
  965. PALERT_INFO_BLOCK paibInfo = NULL;
  966. if (m_szAlertCounterList != NULL) {
  967. pCDC = m_CounterList.GetDC();
  968. for (szThisString = m_szAlertCounterList;
  969. *szThisString != 0 && TRUE == bReturn;
  970. szThisString += dwThisStringLen +1) {
  971. dwThisStringLen = lstrlen(szThisString);
  972. dwBufSize = sizeof (ALERT_INFO_BLOCK) + ((dwThisStringLen + 1) * sizeof (TCHAR));
  973. MFC_TRY
  974. paibInfo = (PALERT_INFO_BLOCK) new CHAR[dwBufSize];
  975. MFC_CATCH_MINIMUM;
  976. if (paibInfo != NULL) {
  977. if (MakeInfoFromString(szThisString, paibInfo, &dwBufSize)) {
  978. if ( 0 <= paibInfo->dLimit ) {
  979. paibInfo->dwFlags |= AIBF_SAVED;
  980. }
  981. nIndex = m_CounterList.AddString(paibInfo->szCounterPath);
  982. if (nIndex != LB_ERR) {
  983. m_CounterList.SetItemDataPtr (nIndex, (LPVOID)paibInfo);
  984. // update list box extent
  985. if ( NULL != pCDC ) {
  986. dwItemExtent = (DWORD)(pCDC->GetTextExtent (paibInfo->szCounterPath)).cx;
  987. if (dwItemExtent > m_dwMaxHorizListExtent) {
  988. m_dwMaxHorizListExtent = dwItemExtent;
  989. m_CounterList.SetHorizontalExtent(dwItemExtent);
  990. }
  991. }
  992. paibInfo = NULL;
  993. } else {
  994. delete paibInfo;
  995. bReturn = FALSE;
  996. }
  997. } else {
  998. delete paibInfo;
  999. bReturn = FALSE;
  1000. }
  1001. } else {
  1002. bReturn = FALSE;
  1003. }
  1004. }
  1005. }
  1006. if ( NULL != pCDC ) {
  1007. m_CounterList.ReleaseDC(pCDC);
  1008. pCDC = NULL;
  1009. }
  1010. // Todo: Error message on failure
  1011. return bReturn;
  1012. }
  1013. BOOL CAlertGenProp::LoadListFromDlg ( INT *piInvalidEntry, BOOL bInvalidateOnly )
  1014. {
  1015. INT nNumItems;
  1016. INT nCurSel;
  1017. PALERT_INFO_BLOCK paibInfo;
  1018. DWORD dwSizeReqd = 0;
  1019. DWORD dwSize;
  1020. DWORD dwSizeLeft = 0;
  1021. LPTSTR szNextString;
  1022. BOOL bReturn = TRUE;
  1023. nNumItems = m_CounterList.GetCount();
  1024. if ((nNumItems != LB_ERR) && (nNumItems > 0)) {
  1025. // find size required for buffer
  1026. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  1027. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  1028. if (paibInfo != NULL) {
  1029. if ((paibInfo->dwFlags & (AIBF_SEEN | AIBF_SAVED)) != 0) {
  1030. dwSizeReqd += (paibInfo->dwSize - sizeof(ALERT_INFO_BLOCK)) / sizeof (WCHAR);
  1031. dwSizeReqd += 24;
  1032. } else {
  1033. if (piInvalidEntry != NULL) {
  1034. *piInvalidEntry = nCurSel;
  1035. bReturn = FALSE;
  1036. break;
  1037. }
  1038. }
  1039. }
  1040. }
  1041. if ( bReturn && !bInvalidateOnly ) {
  1042. LPTSTR pszTemp = NULL;
  1043. dwSizeReqd += 1; // add room for the MSZ NULL
  1044. MFC_TRY;
  1045. pszTemp = new WCHAR[dwSizeReqd];
  1046. MFC_CATCH_MINIMUM;
  1047. if ( NULL != pszTemp ) {
  1048. // allocate a block of memory for the list
  1049. if (m_szAlertCounterList != NULL) {
  1050. delete(m_szAlertCounterList);
  1051. }
  1052. m_cchAlertCounterListSize = 0;
  1053. m_szAlertCounterList = pszTemp;
  1054. // now fill it with the Alert paths
  1055. dwSizeLeft = dwSizeReqd;
  1056. szNextString = m_szAlertCounterList;
  1057. for (nCurSel = 0; nCurSel < nNumItems; nCurSel++) {
  1058. paibInfo = (PALERT_INFO_BLOCK)m_CounterList.GetItemDataPtr(nCurSel);
  1059. if (paibInfo != NULL) {
  1060. dwSize = dwSizeLeft;
  1061. if (MakeStringFromInfo (paibInfo, szNextString, &dwSize)) {
  1062. dwSize += 1; // to include the null
  1063. dwSizeLeft -= dwSize;
  1064. m_cchAlertCounterListSize += dwSize;
  1065. szNextString += dwSize;
  1066. ASSERT (m_cchAlertCounterListSize < dwSizeReqd);
  1067. } else {
  1068. // ran out of buffer
  1069. bReturn = FALSE;
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. if (bReturn) {
  1075. *szNextString++ = 0; // MSZ Null
  1076. m_cchAlertCounterListSize++;
  1077. if (piInvalidEntry != NULL) {
  1078. *piInvalidEntry = -1;
  1079. }
  1080. }
  1081. } // else error
  1082. }
  1083. } else {
  1084. // no items to return
  1085. bReturn = FALSE;
  1086. }
  1087. return bReturn;
  1088. }
  1089. BOOL CAlertGenProp::OnInitDialog()
  1090. {
  1091. CComboBox *pCombo;
  1092. CString csComboBoxString;
  1093. DWORD nIndex;
  1094. UINT nResult;
  1095. LPTSTR szTmpCtrLst;
  1096. DWORD dwSize;
  1097. ResourceStateManager rsm;
  1098. //
  1099. // Here m_pAlertQuery should not be NULL, if it is,
  1100. // There must be something wrong.
  1101. //
  1102. if ( NULL == m_pAlertQuery ) {
  1103. return TRUE;
  1104. }
  1105. m_bCanAccessRemoteWbem = m_pAlertQuery->GetLogService()->CanAccessWbemRemote();
  1106. m_pAlertQuery->SetActivePropertyPage( this );
  1107. // call property page init to init combo members.
  1108. CSmPropertyPage::OnInitDialog();
  1109. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  1110. Initialize( m_pAlertQuery );
  1111. m_strUserDisplay = m_pAlertQuery->m_strUser;
  1112. m_strUserSaved = m_strUserDisplay;
  1113. // Load the shared data to get the sample data unit type.
  1114. m_pAlertQuery->GetPropPageSharedData ( &m_SharedData );
  1115. // load combo box
  1116. pCombo = &m_SampleUnitsCombo;
  1117. pCombo->ResetContent();
  1118. for (nIndex = 0; nIndex < dwTimeUnitComboEntries; nIndex++) {
  1119. csComboBoxString.Empty();
  1120. if (csComboBoxString.LoadString ( TimeUnitCombo[nIndex].nResId)) {
  1121. nResult = pCombo->InsertString (nIndex, (LPCWSTR)csComboBoxString);
  1122. ASSERT (nResult != CB_ERR);
  1123. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  1124. ASSERT (nResult != CB_ERR);
  1125. // set selected in combo box here
  1126. if (m_SharedData.stiSampleTime.dwUnitType == (DWORD)(TimeUnitCombo[nIndex].nData)) {
  1127. m_nSampleUnits = nIndex;
  1128. nResult = pCombo->SetCurSel(nIndex);
  1129. ASSERT (nResult != CB_ERR);
  1130. }
  1131. }
  1132. }
  1133. pCombo = &m_OverUnderCombo;
  1134. pCombo->ResetContent();
  1135. for (nIndex = 0; nIndex < dwOverUnderComboEntries; nIndex++) {
  1136. csComboBoxString.Empty();
  1137. if (csComboBoxString.LoadString ( OverUnderCombo[nIndex].nResId)) {
  1138. nResult = pCombo->InsertString (nIndex, (LPCWSTR)csComboBoxString);
  1139. ASSERT (nResult != CB_ERR);
  1140. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  1141. ASSERT (nResult != CB_ERR);
  1142. }
  1143. }
  1144. // get data from current alert query
  1145. m_pAlertQuery->GetLogComment( m_strComment );
  1146. szTmpCtrLst = (LPTSTR)m_pAlertQuery->GetCounterList (&dwSize);
  1147. if (szTmpCtrLst != NULL) {
  1148. MFC_TRY;
  1149. m_szAlertCounterList = new WCHAR [dwSize];
  1150. MFC_CATCH_MINIMUM;
  1151. if ( NULL != m_szAlertCounterList ) {
  1152. memcpy (m_szAlertCounterList, szTmpCtrLst, (dwSize * sizeof(WCHAR)));
  1153. m_cchAlertCounterListSize = dwSize;
  1154. }
  1155. }
  1156. // Call UpdateData again, after loading data into members.
  1157. UpdateData ( FALSE );
  1158. // load list box
  1159. LoadDlgFromList();
  1160. // m_CounterList is initialized in UpdateData
  1161. if (m_CounterList.GetCount() > 0) {
  1162. m_CounterList.SetCurSel (0);
  1163. m_CounterList.SetFocus();
  1164. LoadAlertItemData (0);
  1165. }
  1166. SetButtonState ();
  1167. return FALSE; // return TRUE unless you set the focus to a control
  1168. // EXCEPTION: OCX Property Pages should return FALSE
  1169. }
  1170. void CAlertGenProp::OnCommentEditChange()
  1171. {
  1172. UpdateData( TRUE );
  1173. SetModifiedPage(TRUE);
  1174. }
  1175. void CAlertGenProp::OnCommentEditKillFocus()
  1176. {
  1177. CString strOldText;
  1178. strOldText = m_strComment;
  1179. UpdateData ( TRUE );
  1180. if ( 0 != strOldText.Compare ( m_strComment ) ) {
  1181. SetModifiedPage(TRUE);
  1182. }
  1183. }