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.

3000 lines
107 KiB

  1. /*++
  2. Copyright (C) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. cmponent.cpp
  5. Abstract:
  6. Implementation of the CComponent class.
  7. --*/
  8. #include "StdAfx.h"
  9. #include <shfolder.h>
  10. #include <strsafe.h>
  11. #include "smcfgmsg.h"
  12. #include "smproppg.h"
  13. //
  14. #include "ctrsprop.h"
  15. #include "fileprop.h"
  16. #include "provprop.h"
  17. #include "schdprop.h"
  18. #include "tracprop.h"
  19. #include "AlrtGenP.h"
  20. #include "AlrtActP.h"
  21. //
  22. #include "newqdlg.h"
  23. #include "ipropbag.h"
  24. #include "smrootnd.h"
  25. #include "smlogs.h"
  26. #include "smtracsv.h"
  27. #include "cmponent.h"
  28. USE_HANDLE_MACROS("SMLOGCFG(cmponent.cpp)")
  29. // These globals are used for dialogs and property sheets
  30. //
  31. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  32. static MMCBUTTON ToolbarResultBtnsLog[] =
  33. {
  34. { 0, IDM_NEW_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  35. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0 },
  36. { 1, IDM_START_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  37. { 2, IDM_STOP_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }
  38. };
  39. static MMCBUTTON ToolbarResultBtnsAlert[] =
  40. {
  41. { 0, IDM_NEW_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  42. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0 },
  43. { 1, IDM_START_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 },
  44. { 2, IDM_STOP_QUERY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0 }
  45. };
  46. class CButtonStringsHolder
  47. {
  48. public:
  49. CButtonStringsHolder()
  50. {
  51. m_astr = NULL;
  52. }
  53. ~CButtonStringsHolder()
  54. {
  55. if (m_astr != NULL)
  56. delete[] m_astr;
  57. }
  58. CString* m_astr; // dynamic array of CStrings
  59. };
  60. CButtonStringsHolder g_astrButtonStringsLog;
  61. CButtonStringsHolder g_astrButtonStringsAlert;
  62. CONST INT cResultBtnsLog = sizeof ( ToolbarResultBtnsLog ) / sizeof ( MMCBUTTON );
  63. CONST INT cResultBtnsAlert = sizeof ( ToolbarResultBtnsAlert ) / sizeof ( MMCBUTTON );
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CComponent
  66. HRESULT
  67. CComponent::LoadLogToolbarStrings ( MMCBUTTON * Buttons )
  68. {
  69. UINT i;
  70. HRESULT hr = S_OK;
  71. ResourceStateManager rsm;
  72. if ( NULL != Buttons ) {
  73. if ( NULL == g_astrButtonStringsLog.m_astr ) {
  74. // Load strings
  75. g_astrButtonStringsLog.m_astr = new CString[2*cResultBtnsLog];
  76. if ( NULL != g_astrButtonStringsLog.m_astr ) {
  77. for ( i = 0; i < cResultBtnsLog; i++) {
  78. // Skip separator buttons
  79. if ( 0 != Buttons[i].idCommand ) {
  80. UINT iButtonTextId = 0, iTooltipTextId = 0;
  81. switch (Buttons[i].idCommand)
  82. {
  83. case IDM_NEW_QUERY:
  84. iButtonTextId = IDS_BUTTON_NEW_LOG;
  85. iTooltipTextId = IDS_TOOLTIP_NEW_LOG;
  86. break;
  87. case IDM_START_QUERY:
  88. iButtonTextId = IDS_BUTTON_START_LOG;
  89. iTooltipTextId = IDS_TOOLTIP_START_LOG;
  90. break;
  91. case IDM_STOP_QUERY:
  92. iButtonTextId = IDS_BUTTON_STOP_LOG;
  93. iTooltipTextId = IDS_TOOLTIP_STOP_LOG;
  94. break;
  95. default:
  96. ASSERT(FALSE);
  97. break;
  98. }
  99. g_astrButtonStringsLog.m_astr[i*2].LoadString(iButtonTextId);
  100. Buttons[i].lpButtonText =
  101. const_cast<BSTR>((LPCWSTR)(g_astrButtonStringsLog.m_astr[i*2]));
  102. g_astrButtonStringsLog.m_astr[(i*2)+1].LoadString(iTooltipTextId);
  103. Buttons[i].lpTooltipText =
  104. const_cast<BSTR>((LPCWSTR)(g_astrButtonStringsLog.m_astr[(i*2)+1]));
  105. }
  106. }
  107. }
  108. } else {
  109. hr = E_OUTOFMEMORY;
  110. }
  111. } else {
  112. hr = E_INVALIDARG;
  113. }
  114. return hr;
  115. }
  116. HRESULT
  117. CComponent::LoadAlertToolbarStrings ( MMCBUTTON * Buttons )
  118. {
  119. HRESULT hr = S_OK;
  120. UINT i;
  121. ResourceStateManager rsm;
  122. if ( NULL == g_astrButtonStringsAlert.m_astr ) {
  123. // Load strings
  124. g_astrButtonStringsAlert.m_astr = new CString[2*cResultBtnsAlert];
  125. if ( NULL != g_astrButtonStringsAlert.m_astr ) {
  126. for ( i = 0; i < cResultBtnsAlert; i++) {
  127. // Skip separator buttons
  128. if ( 0 != Buttons[i].idCommand ) {
  129. UINT iButtonTextId = 0, iTooltipTextId = 0;
  130. switch (Buttons[i].idCommand)
  131. {
  132. case IDM_NEW_QUERY:
  133. iButtonTextId = IDS_BUTTON_NEW_ALERT;
  134. iTooltipTextId = IDS_TOOLTIP_NEW_ALERT;
  135. break;
  136. case IDM_START_QUERY:
  137. iButtonTextId = IDS_BUTTON_START_ALERT;
  138. iTooltipTextId = IDS_TOOLTIP_START_ALERT;
  139. break;
  140. case IDM_STOP_QUERY:
  141. iButtonTextId = IDS_BUTTON_STOP_ALERT;
  142. iTooltipTextId = IDS_TOOLTIP_STOP_ALERT;
  143. break;
  144. default:
  145. ASSERT(FALSE);
  146. break;
  147. }
  148. g_astrButtonStringsAlert.m_astr[i*2].LoadString(iButtonTextId);
  149. Buttons[i].lpButtonText =
  150. const_cast<BSTR>((LPCWSTR)(g_astrButtonStringsAlert.m_astr[i*2]));
  151. g_astrButtonStringsAlert.m_astr[(i*2)+1].LoadString(iTooltipTextId);
  152. Buttons[i].lpTooltipText =
  153. const_cast<BSTR>((LPCWSTR)(g_astrButtonStringsAlert.m_astr[(i*2)+1]));
  154. }
  155. }
  156. } else {
  157. hr = E_OUTOFMEMORY;
  158. }
  159. } else {
  160. hr = E_INVALIDARG;
  161. }
  162. return hr;
  163. }
  164. CComponent::CComponent()
  165. : m_ipConsole ( NULL ),
  166. m_ipHeaderCtrl ( NULL ),
  167. m_ipResultData ( NULL ),
  168. m_ipConsoleVerb ( NULL ),
  169. m_ipImageResult ( NULL ),
  170. m_ipCompData ( NULL ),
  171. m_ipControlbar ( NULL ),
  172. m_ipToolbarLogger ( NULL ),
  173. m_ipToolbarAlerts ( NULL ),
  174. m_ipToolbarAttached ( NULL ),
  175. m_pViewedNode ( NULL )
  176. {
  177. m_hModule = (HINSTANCE)GetModuleHandleW (_CONFIG_DLL_NAME_W_);
  178. } // end Constructor()
  179. //---------------------------------------------------------------------------
  180. //
  181. CComponent::~CComponent()
  182. {
  183. } // end Destructor()
  184. /////////////////////////////////////////////////////////////////////////////
  185. // IComponent implementation
  186. //
  187. //---------------------------------------------------------------------------
  188. // IComponent::Initialize is called when a snap-in is being created and
  189. // has items in the result pane to enumerate. The pointer to IConsole that
  190. // is passed in is used to make QueryInterface calls to the console for
  191. // interfaces such as IResultData.
  192. //
  193. STDMETHODIMP
  194. CComponent::Initialize (
  195. LPCONSOLE lpConsole ) // [in] Pointer to IConsole's IUnknown interface
  196. {
  197. HRESULT hr = E_POINTER;
  198. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  199. ASSERT( NULL != lpConsole );
  200. if ( NULL != lpConsole ) {
  201. // Save away all the interfaces we'll need.
  202. // Fail if we can't QI the required interfaces.
  203. m_ipConsole = lpConsole;
  204. m_ipConsole->AddRef();
  205. hr = m_ipConsole->QueryInterface(
  206. IID_IResultData,
  207. (VOID**)&m_ipResultData );
  208. if ( SUCCEEDED ( hr ) ) {
  209. hr = m_ipConsole->QueryInterface(
  210. IID_IHeaderCtrl,
  211. (VOID**)&m_ipHeaderCtrl );
  212. if( SUCCEEDED ( hr ) ) {
  213. m_ipConsole->SetHeader( m_ipHeaderCtrl );
  214. }
  215. if ( SUCCEEDED ( hr ) ) {
  216. hr = m_ipConsole->QueryResultImageList( &m_ipImageResult);
  217. }
  218. if ( SUCCEEDED ( hr ) ) {
  219. hr = m_ipConsole->QueryConsoleVerb( &m_ipConsoleVerb );
  220. }
  221. }
  222. }
  223. return hr;
  224. } // end Initialize()
  225. //---------------------------------------------------------------------------
  226. // Handle the most important notifications.
  227. //
  228. STDMETHODIMP
  229. CComponent::Notify (
  230. LPDATAOBJECT pDataObject, // [in] Points to data object
  231. MMC_NOTIFY_TYPE event, // [in] Identifies action taken by user
  232. LPARAM arg, // [in] Depends on the notification type
  233. LPARAM Param // [in] Depends on the notification type
  234. )
  235. {
  236. HRESULT hr = S_OK;
  237. CDataObject* pDO = NULL;
  238. CSmLogQuery* pQuery = NULL;
  239. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  240. ASSERT( NULL != m_ipCompData );
  241. switch( event ) {
  242. case MMCN_ADD_IMAGES:
  243. hr = OnAddImages( pDataObject, arg, Param );
  244. break;
  245. case MMCN_DELETE:
  246. hr = OnDelete ( pDataObject, arg, Param );
  247. break;
  248. case MMCN_PASTE:
  249. LOCALTRACE( L"CComponent::Notify: MMCN_PASTE unimplemented\n" );
  250. /*
  251. hr = OnPaste( pDataObject, arg, Param );
  252. */
  253. break;
  254. case MMCN_QUERY_PASTE:
  255. LOCALTRACE( L"CComponent::Notify: MMCN_QUERY_PASTE unimplemented\n" );
  256. /*
  257. hr = OnQueryPaste( pDataObject, arg, Param );
  258. */
  259. break;
  260. case MMCN_REFRESH:
  261. hr = OnRefresh( pDataObject );
  262. break;
  263. case MMCN_SELECT:
  264. hr = OnSelect( pDataObject, arg, Param );
  265. break;
  266. case MMCN_SHOW:
  267. hr = OnShow( pDataObject, arg, Param );
  268. break;
  269. case MMCN_VIEW_CHANGE:
  270. hr = OnViewChange( pDataObject, arg, Param );
  271. break;
  272. case MMCN_PROPERTY_CHANGE:
  273. if ( NULL != Param ) {
  274. // Data object is passed as parameter
  275. hr = OnViewChange( (LPDATAOBJECT)Param, arg, CComponentData::eSmHintModifyQuery );
  276. } else {
  277. hr = S_FALSE;
  278. }
  279. break;
  280. case MMCN_CLICK:
  281. LOCALTRACE( L"CComponent::Notify: MMCN_CLICK unimplemented\n" );
  282. break;
  283. case MMCN_DBLCLICK:
  284. pDO = ExtractOwnDataObject(pDataObject);
  285. if ( NULL != pDO ) {
  286. hr = (HRESULT) OnDoubleClick ((ULONG) pDO->GetCookie(),pDataObject);
  287. } else {
  288. hr = S_FALSE;
  289. }
  290. break;
  291. case MMCN_ACTIVATE:
  292. LOCALTRACE( L"CComponent::Notify: MMCN_ACTIVATE unimplemented\n" );
  293. break;
  294. case MMCN_MINIMIZED:
  295. LOCALTRACE( L"CComponent::Notify: MMCN_MINIMIZED unimplemented\n" );
  296. break;
  297. case MMCN_BTN_CLICK:
  298. LOCALTRACE( L"CComponent::Notify: MMCN_BTN_CLICK unimplemented\n" );
  299. break;
  300. case MMCN_CONTEXTHELP:
  301. hr = OnDisplayHelp( pDataObject );
  302. break;
  303. default:
  304. LOCALTRACE( L"CComponent::Notify: unimplemented event %x\n", event );
  305. hr = S_FALSE;
  306. break;
  307. }
  308. return hr;
  309. } // end Notify()
  310. //---------------------------------------------------------------------------
  311. // Releases all references to the console.
  312. // Only the console should call this method.
  313. //
  314. STDMETHODIMP
  315. CComponent::Destroy (
  316. MMC_COOKIE /* mmcCookie */ // Reserved, not in use at this time
  317. )
  318. {
  319. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  320. // Release the interfaces that we QI'ed
  321. m_ipConsole->SetHeader(NULL);
  322. SAFE_RELEASE( m_ipHeaderCtrl );
  323. SAFE_RELEASE( m_ipResultData );
  324. SAFE_RELEASE( m_ipImageResult );
  325. SAFE_RELEASE( m_ipConsoleVerb );
  326. SAFE_RELEASE( m_ipConsole );
  327. SAFE_RELEASE( m_ipControlbar );
  328. SAFE_RELEASE( m_ipToolbarLogger );
  329. SAFE_RELEASE( m_ipToolbarAlerts );
  330. return S_OK;
  331. } // end Destroy()
  332. //---------------------------------------------------------------------------
  333. // Returns a data object that can be used to retrieve context information
  334. // for the specified mmcCookie.
  335. //
  336. STDMETHODIMP
  337. CComponent::QueryDataObject (
  338. MMC_COOKIE mmcCookie, // [in] Specifies the unique identifier
  339. DATA_OBJECT_TYPES context, // [in] Type of data object
  340. LPDATAOBJECT* ppDataObject // [out] Points to address of returned data
  341. )
  342. {
  343. HRESULT hr = S_OK;
  344. BOOL bIsQuery = FALSE;
  345. CComObject<CDataObject>* pDataObj = NULL;
  346. CSmLogQuery* pQuery = NULL;
  347. INT iResult;
  348. CString strMessage;
  349. ResourceStateManager rsm;
  350. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  351. ASSERT( CCT_SCOPE == context // Must have a context
  352. || CCT_RESULT == context // we understand
  353. || CCT_SNAPIN_MANAGER == context );
  354. ASSERT( NULL != m_ipCompData );
  355. if ( NULL != ppDataObject
  356. && ( CCT_SCOPE == context // Must have a context
  357. || CCT_RESULT == context // we understand
  358. || CCT_SNAPIN_MANAGER == context ) )
  359. {
  360. if ( NULL != m_ipCompData
  361. && NULL != m_ipConsole )
  362. {
  363. if( CCT_RESULT == context && NULL != mmcCookie ) {
  364. CComObject<CDataObject>::CreateInstance( &pDataObj );
  365. if( NULL == pDataObj ) { // DataObject was not created
  366. MFC_TRY
  367. strMessage.LoadString( IDS_ERRMSG_OUTOFMEMORY );
  368. MFC_CATCH_HR
  369. hr = m_ipConsole->MessageBox( strMessage,
  370. L"CComponent::QueryDataObject", // not localized
  371. MB_OK | MB_ICONERROR,
  372. &iResult
  373. );
  374. hr = E_OUTOFMEMORY;
  375. } else {
  376. // Now we have a data object, init the mmcCookie, context and type
  377. bIsQuery = m_ipCompData->IsLogQuery (mmcCookie);
  378. if ( bIsQuery ) {
  379. pQuery = (CSmLogQuery*)mmcCookie;
  380. ASSERT ( NULL != pQuery );
  381. if ( NULL != pQuery ) {
  382. if ( CComponentData::eCounterLog == pQuery->GetLogType() ) {
  383. pDataObj->SetData( mmcCookie, CCT_RESULT, COOKIE_IS_COUNTERMAINNODE );
  384. } else if ( CComponentData::eTraceLog == pQuery->GetLogType() ) {
  385. pDataObj->SetData( mmcCookie, CCT_RESULT, COOKIE_IS_TRACEMAINNODE );
  386. } else if ( CComponentData::eAlert == pQuery->GetLogType() ) {
  387. pDataObj->SetData( mmcCookie, CCT_RESULT, COOKIE_IS_ALERTMAINNODE );
  388. } else {
  389. ::MessageBox( NULL,
  390. L"Bad Cookie",
  391. L"CComponentData::QueryDataObject",
  392. MB_OK | MB_ICONERROR
  393. );
  394. hr = E_OUTOFMEMORY;
  395. }
  396. }
  397. } else {
  398. if ( m_ipCompData->IsScopeNode( mmcCookie ) ) {
  399. if ( NULL != (reinterpret_cast<PSMNODE>(mmcCookie))->CastToRootNode() ) {
  400. pDataObj->SetData(mmcCookie, CCT_RESULT, COOKIE_IS_ROOTNODE);
  401. } else {
  402. ::MessageBox( NULL,
  403. L"Bad Cookie",
  404. L"CComponentData::QueryDataObject",
  405. MB_OK | MB_ICONERROR
  406. );
  407. hr = E_OUTOFMEMORY;
  408. }
  409. }
  410. }
  411. }
  412. } else if ((CCT_SNAPIN_MANAGER == context) && (NULL != mmcCookie)) {
  413. // this is received by the snap in when it is added
  414. // as an extension snap ine
  415. CComObject<CDataObject>::CreateInstance( &pDataObj );
  416. if( NULL == pDataObj ) { // DataObject was not created
  417. MFC_TRY
  418. strMessage.LoadString( IDS_ERRMSG_OUTOFMEMORY );
  419. MFC_CATCH_HR
  420. hr = m_ipConsole->MessageBox( strMessage,
  421. L"CComponent::QueryDataObject", // not localized
  422. MB_OK | MB_ICONERROR,
  423. &iResult
  424. );
  425. hr = E_OUTOFMEMORY;
  426. } else {
  427. // Now we have a data object, init the mmcCookie, context and type
  428. pDataObj->SetData( mmcCookie, CCT_SNAPIN_MANAGER, COOKIE_IS_MYCOMPUTER );
  429. }
  430. } else { // Request must have been from an
  431. // unknown source. Should never see
  432. ASSERT ( FALSE );
  433. hr = E_UNEXPECTED;
  434. }
  435. if ( SUCCEEDED ( hr ) ) {
  436. hr = pDataObj->QueryInterface( IID_IDataObject,
  437. reinterpret_cast<void**>(ppDataObject) );
  438. } else {
  439. if ( NULL != pDataObj ) {
  440. delete pDataObj;
  441. }
  442. *ppDataObject = NULL;
  443. }
  444. } else {
  445. hr = S_FALSE;
  446. }
  447. } else {
  448. hr = E_POINTER;
  449. }
  450. return hr;
  451. } // end QueryDataObject()
  452. //---------------------------------------------------------------------------
  453. // This is where we provide strings for items we added to the the result
  454. // pane. We get asked for a string for each column.
  455. // Note that we still need to provide strings for items that are actually
  456. // scope pane items. Notice that when the scope pane item was asked for a
  457. // string for the scope pane we gave it. Here we actually have two columns
  458. // of strings - "Name" and "Type".
  459. // We also get asked for the icons for items in both panes.
  460. //
  461. STDMETHODIMP
  462. CComponent::GetDisplayInfo (
  463. LPRESULTDATAITEM pResultItem ) // [in,out] Type of info required
  464. {
  465. HRESULT hr = S_OK;
  466. PSLQUERY pQuery;
  467. CSmNode* pNode;
  468. PSROOT pRoot;
  469. PSLSVC pSvc;
  470. WCHAR szErrorText[MAX_PATH + 1];
  471. ResourceStateManager rsm;
  472. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  473. if ( NULL == pResultItem ) {
  474. ASSERT ( FALSE );
  475. hr = E_POINTER;
  476. } else {
  477. if( FALSE == pResultItem->bScopeItem ) { // Doing result items...
  478. if( pResultItem->mask & RDI_STR ) { // Now we have a object
  479. // Note: Text buffer allocated for each information type, so that
  480. // the buffer pointer is persistent for a single item (line in the result pane).
  481. MFC_TRY
  482. switch (pResultItem->nCol) {
  483. case ROOT_COL_QUERY_NAME:
  484. pQuery = reinterpret_cast<PSLQUERY>(pResultItem->lParam);
  485. m_strDisplayInfoName = pQuery->GetLogName ( );
  486. pResultItem->str = m_strDisplayInfoName.GetBuffer( 0 );
  487. m_strDisplayInfoName.ReleaseBuffer( );
  488. break;
  489. case ROOT_COL_COMMENT:
  490. pQuery= reinterpret_cast<PSLQUERY>(pResultItem->lParam);
  491. m_strDisplayInfoComment = pQuery->GetLogComment ( );
  492. pResultItem->str = m_strDisplayInfoComment.GetBuffer( 0 );
  493. m_strDisplayInfoComment.ReleaseBuffer( );
  494. break;
  495. case ROOT_COL_LOG_TYPE:
  496. pQuery= reinterpret_cast<PSLQUERY>(pResultItem->lParam);
  497. // Query type should not be Alert
  498. ASSERT ( SLQ_ALERT != pQuery->GetLogType() );
  499. m_strDisplayInfoLogFileType = pQuery->GetLogFileType ( );
  500. pResultItem->str = m_strDisplayInfoLogFileType.GetBuffer( 0 );
  501. m_strDisplayInfoLogFileType.ReleaseBuffer( );
  502. break;
  503. case ROOT_COL_LOG_NAME:
  504. pQuery= reinterpret_cast<PSLQUERY>(pResultItem->lParam);
  505. // Query type should not be Alert
  506. ASSERT ( SLQ_ALERT != pQuery->GetLogType() );
  507. m_strDisplayInfoLogFileName = pQuery->GetLogFileName ();
  508. pResultItem->str = m_strDisplayInfoLogFileName.GetBuffer( 0 );
  509. m_strDisplayInfoLogFileName.ReleaseBuffer( );
  510. break;
  511. default:
  512. StringCchPrintf ( szErrorText, MAX_PATH + 1, L"Error: Column %d Selected for Result Item\n", pResultItem->nCol);
  513. ASSERT ( FALSE );
  514. LOCALTRACE( szErrorText );
  515. hr = E_UNEXPECTED;
  516. }
  517. MFC_CATCH_HR
  518. }
  519. if (pResultItem->mask & RDI_IMAGE) {
  520. pQuery= reinterpret_cast<PSLQUERY>(pResultItem->lParam);
  521. if ( NULL != pQuery ) {
  522. pResultItem->nImage = (pQuery->IsRunning() ? 0 : 1);
  523. } else {
  524. ASSERT ( FALSE );
  525. hr = E_UNEXPECTED;
  526. }
  527. }
  528. }
  529. else // TRUE == pResultItem->bScopeItem
  530. {
  531. pNode = reinterpret_cast<CSmNode*>(pResultItem->lParam);
  532. if( pResultItem->mask & RDI_STR ) {
  533. if ( pNode->CastToRootNode() ) {
  534. MFC_TRY
  535. pRoot = reinterpret_cast<PSROOT>(pResultItem->lParam);
  536. switch ( pResultItem->nCol ) {
  537. case EXTENSION_COL_NAME:
  538. m_strDisplayInfoName = pRoot->GetDisplayName();
  539. pResultItem->str = m_strDisplayInfoName.GetBuffer( 0 );
  540. m_strDisplayInfoName.ReleaseBuffer( );
  541. break;
  542. case EXTENSION_COL_TYPE:
  543. m_strDisplayInfoQueryType = pRoot->GetType();
  544. pResultItem->str = m_strDisplayInfoQueryType.GetBuffer( 0 );
  545. m_strDisplayInfoQueryType.ReleaseBuffer( );
  546. break;
  547. case EXTENSION_COL_DESC:
  548. m_strDisplayInfoDesc = pRoot->GetDescription();
  549. pResultItem->str = m_strDisplayInfoDesc.GetBuffer( 0 );
  550. m_strDisplayInfoDesc.ReleaseBuffer( );
  551. break;
  552. default:
  553. StringCchPrintf ( szErrorText, MAX_PATH + 1, L"Error: Column %d Selected for Scope Item\n", pResultItem->nCol);
  554. ASSERT ( FALSE );
  555. LOCALTRACE( szErrorText );
  556. hr = E_UNEXPECTED;
  557. }
  558. MFC_CATCH_HR
  559. } else {
  560. ASSERT ( pNode->CastToLogService() );
  561. MFC_TRY
  562. if( pResultItem->nCol == MAIN_COL_NAME ) {
  563. pSvc = reinterpret_cast<PSLSVC>(pResultItem->lParam);
  564. m_strDisplayInfoName = pSvc->GetDisplayName();
  565. pResultItem->str = m_strDisplayInfoName.GetBuffer( 0 );
  566. m_strDisplayInfoName.ReleaseBuffer( );
  567. } else if( pResultItem->nCol == MAIN_COL_DESC ) {
  568. pSvc = reinterpret_cast<PSLSVC>(pResultItem->lParam);
  569. m_strDisplayInfoDesc = pSvc->GetDescription();
  570. pResultItem->str = m_strDisplayInfoDesc.GetBuffer( 0 );
  571. m_strDisplayInfoDesc.ReleaseBuffer( );
  572. } else {
  573. StringCchPrintf ( szErrorText, MAX_PATH + 1, L"Error: Column %d Selected for Result Item\n", pResultItem->nCol);
  574. ASSERT ( FALSE );
  575. LOCALTRACE( szErrorText );
  576. hr = E_UNEXPECTED;
  577. }
  578. MFC_CATCH_HR
  579. }
  580. }
  581. if (pResultItem->mask & RDI_IMAGE)
  582. {
  583. if ( NULL != pNode->CastToRootNode() ) {
  584. pResultItem->nImage = CComponentData::eBmpRootIcon;
  585. } else if ( NULL != pNode->CastToAlertService() ) {
  586. pResultItem->nImage = CComponentData::eBmpAlertType;
  587. } else {
  588. pResultItem->nImage = CComponentData::eBmpLogType;
  589. }
  590. }
  591. }
  592. }
  593. return hr;
  594. } // end GetDisplayInfo()
  595. //---------------------------------------------------------------------------
  596. // Determines what the result pane view should be
  597. //
  598. STDMETHODIMP
  599. CComponent::GetResultViewType (
  600. MMC_COOKIE /* mmcCookie */, // [in] Specifies the unique identifier
  601. BSTR *ppViewType, // [out] Points to address of the returned view type
  602. long *pViewOptions // [out] Pointer to the MMC_VIEW_OPTIONS enumeration
  603. )
  604. {
  605. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  606. // Ask for default listview.
  607. if ( NULL != ppViewType ) {
  608. *ppViewType = NULL;
  609. }
  610. if ( NULL != pViewOptions ) {
  611. *pViewOptions = MMC_VIEW_OPTIONS_NONE;
  612. }
  613. return S_FALSE;
  614. } // end GetResultViewType()
  615. //---------------------------------------------------------------------------
  616. // Not used
  617. //
  618. HRESULT
  619. CComponent::CompareObjects (
  620. LPDATAOBJECT /* lpDataObjectA */, // [in] First data object to compare
  621. LPDATAOBJECT /* lpDataObjectB */ // [in] Second data object to compare
  622. )
  623. {
  624. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  625. return S_FALSE;
  626. } // end CompareObjects()
  627. /////////////////////////////////////////////////////////////////////////////
  628. // Support methods
  629. //
  630. //---------------------------------------------------------------------------
  631. // Here is where we handle the MMCN_SHOW message. Insert the column
  632. // headers, and then the rows of data into the result pane.
  633. //
  634. HRESULT
  635. CComponent::OnShow (
  636. LPDATAOBJECT pDataObject, // [in] Points to data object
  637. LPARAM Arg, // [in]
  638. LPARAM /* Param */ ) // [in] not used
  639. {
  640. HRESULT hr = S_OK;
  641. CDataObject* pDO = NULL;
  642. CString strColHeader;
  643. INT iCommentSize;
  644. PSLSVC pSvc = NULL;
  645. ResourceStateManager rsm;
  646. if ( TRUE == Arg ) {
  647. if ( NULL == pDataObject ) {
  648. ASSERT ( FALSE );
  649. hr = E_POINTER;
  650. } else {
  651. pDO = ExtractOwnDataObject(pDataObject);
  652. if ( NULL == pDO ) {
  653. ASSERT ( FALSE );
  654. hr = E_UNEXPECTED;
  655. }
  656. }
  657. if ( SUCCEEDED ( hr ) ) {
  658. if ( NULL == m_ipHeaderCtrl ) {
  659. hr = S_FALSE;
  660. } else {
  661. m_pViewedNode = (CSmNode*)pDO->GetCookie();
  662. if( !(COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) ) {
  663. // Query name
  664. MFC_TRY
  665. strColHeader.LoadString ( IDS_ROOT_COL_QUERY_NAME );
  666. MFC_CATCH_HR;
  667. hr = m_ipHeaderCtrl->InsertColumn(
  668. ROOT_COL_QUERY_NAME,
  669. strColHeader,
  670. LVCFMT_LEFT,
  671. ROOT_COL_QUERY_NAME_SIZE );
  672. ASSERT( S_OK == hr );
  673. // Comment
  674. STANDARD_TRY
  675. strColHeader.LoadString ( IDS_ROOT_COL_COMMENT );
  676. MFC_CATCH_HR
  677. iCommentSize = ROOT_COL_COMMENT_SIZE;
  678. if ( COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() ) {
  679. iCommentSize += ROOT_COL_ALERT_COMMENT_XTRA;
  680. }
  681. hr = m_ipHeaderCtrl->InsertColumn(
  682. ROOT_COL_COMMENT,
  683. strColHeader,
  684. LVCFMT_LEFT,
  685. iCommentSize);
  686. ASSERT( S_OK == hr );
  687. // Log type
  688. if ( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  689. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType() ) {
  690. STANDARD_TRY
  691. strColHeader.LoadString ( IDS_ROOT_COL_LOG_TYPE );
  692. MFC_CATCH_HR
  693. hr = m_ipHeaderCtrl->InsertColumn(
  694. ROOT_COL_LOG_TYPE,
  695. strColHeader,
  696. LVCFMT_LEFT,
  697. ROOT_COL_LOG_TYPE_SIZE);
  698. ASSERT( S_OK == hr );
  699. STANDARD_TRY
  700. strColHeader.LoadString ( IDS_ROOT_COL_LOG_FILE_NAME );
  701. MFC_CATCH_HR
  702. hr = m_ipHeaderCtrl->InsertColumn(
  703. ROOT_COL_LOG_NAME,
  704. strColHeader,
  705. LVCFMT_LEFT,
  706. ROOT_COL_LOG_NAME_SIZE);
  707. ASSERT( S_OK == hr );
  708. }
  709. // Set the items in the results pane rows
  710. ASSERT( CCT_SCOPE == pDO->GetContext() );
  711. ASSERT( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  712. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType()
  713. || COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() );
  714. // The lParam is what we see in QueryDataObject as the mmcCookie.
  715. // Now we have an object representing row data, so that the
  716. // mmcCookie knows what to display in the results pane, when we
  717. // get into GetDisplayInfo we cast the mmcCookie to our object,
  718. // and then we can get the data to display.
  719. //
  720. pSvc = reinterpret_cast<PSLSVC>(pDO->GetCookie());
  721. if ( NULL != pSvc ) {
  722. // m_pViewedNode has already been set to the cookie value.
  723. if ( TRUE == pSvc->GetRefreshOnShow() ) {
  724. hr = RefreshResultPane( pDataObject );
  725. } else {
  726. hr = PopulateResultPane( pDO->GetCookie() );
  727. }
  728. if ( SUCCEEDED ( hr ) ) {
  729. pSvc->SetRefreshOnShow ( FALSE );
  730. }
  731. }
  732. } else {
  733. MFC_TRY
  734. strColHeader.LoadString ( IDS_MAIN_COL_NODE_NAME );
  735. MFC_CATCH_HR
  736. if ( SUCCEEDED ( hr ) ) {
  737. // Set the column headers in the results pane
  738. hr = m_ipHeaderCtrl->InsertColumn(
  739. MAIN_COL_NAME,
  740. strColHeader,
  741. LVCFMT_LEFT,
  742. MAIN_COL_NAME_SIZE);
  743. ASSERT( S_OK == hr );
  744. STANDARD_TRY
  745. strColHeader.LoadString ( IDS_MAIN_COL_NODE_DESCRIPTION );
  746. MFC_CATCH_HR
  747. hr = m_ipHeaderCtrl->InsertColumn(
  748. MAIN_COL_DESC,
  749. strColHeader,
  750. LVCFMT_LEFT,
  751. MAIN_COL_DESC_SIZE);
  752. ASSERT( S_OK == hr );
  753. }
  754. }
  755. }
  756. }
  757. } else {
  758. m_pViewedNode = NULL;
  759. }
  760. return hr;
  761. } // end OnShow()
  762. //---------------------------------------------------------------------------
  763. //
  764. HRESULT
  765. CComponent::OnAddImages (
  766. LPDATAOBJECT /* pDataObject */, // [in] Points to the data object
  767. LPARAM /* arg */, // [in] Not used
  768. LPARAM /* param */ // [in] Not used
  769. )
  770. {
  771. HRESULT hr = S_FALSE;
  772. ASSERT( NULL != m_ipImageResult );
  773. HBITMAP hbmp16x16 = NULL;
  774. HBITMAP hbmp32x32 = NULL;
  775. if ( NULL != g_hinst && NULL != m_ipImageResult ) {
  776. hbmp16x16 = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_NODES_16x16));
  777. hbmp32x32 = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_NODES_32x32));
  778. hr = m_ipImageResult->ImageListSetStrip(
  779. (LONG_PTR *)hbmp16x16,
  780. (LONG_PTR *)hbmp32x32,
  781. 0,
  782. RGB(0,255,0)
  783. );
  784. ASSERT( S_OK == hr );
  785. if ( NULL != hbmp16x16 )
  786. {
  787. DeleteObject (hbmp16x16);
  788. }
  789. if ( NULL != hbmp32x32 )
  790. {
  791. DeleteObject (hbmp32x32);
  792. }
  793. }
  794. return hr;
  795. } // end OnAddImages()
  796. //---------------------------------------------------------------------------
  797. // This is a handler for the MMCN_PASTE notification. The user
  798. // copied a node to the clipboard. Paste the counters from the data object
  799. // into the currently selected node.
  800. //
  801. HRESULT
  802. CComponent::OnPaste (
  803. LPDATAOBJECT pDataObject, // [in] Points to the data object
  804. LPARAM arg, // [in] Points to source data object
  805. LPARAM /* param */ // [in] Not used
  806. )
  807. {
  808. HRESULT hr = S_FALSE;
  809. CDataObject* pDO = NULL;
  810. CDataObject* pDOSource = NULL;
  811. BOOL bIsQuery = FALSE;
  812. ASSERT( NULL != m_ipCompData );
  813. if ( NULL == pDataObject ) {
  814. ASSERT ( FALSE );
  815. hr = E_POINTER;
  816. } else {
  817. pDO = ExtractOwnDataObject(pDataObject);
  818. }
  819. if ( SUCCEEDED ( hr ) ) {
  820. // Bail if we couldn't get the console verb interface, or if the
  821. // selected item is the root;
  822. if ( NULL == (LPDATAOBJECT)arg ) {
  823. ASSERT ( FALSE );
  824. hr = E_INVALIDARG;
  825. } else {
  826. pDOSource = ExtractOwnDataObject((LPDATAOBJECT)arg);
  827. }
  828. }
  829. if ( SUCCEEDED ( hr )
  830. && NULL != pDO
  831. && NULL != pDOSource
  832. && NULL != m_ipCompData )
  833. {
  834. bIsQuery = m_ipCompData->IsLogQuery (pDO->GetCookie())
  835. && m_ipCompData->IsLogQuery (pDOSource->GetCookie());
  836. // Note: Can't check with compdata to determine if query, because
  837. // can be from another compdata
  838. if ( bIsQuery )
  839. hr = S_OK;
  840. }
  841. return hr;
  842. } // end OnPaste()
  843. //---------------------------------------------------------------------------
  844. // This is a handler for the MMCN_QUERY_PASTE notification. The user
  845. // copied a node to the clipboard. Determine if that data object
  846. // can be pasted into the currently selected node.
  847. //
  848. HRESULT
  849. CComponent::OnQueryPaste (
  850. LPDATAOBJECT pDataObject, // [in] Points to the data object
  851. LPARAM arg, // [in] Points to source data object
  852. LPARAM /* param */ ) // [in] Not used
  853. {
  854. HRESULT hr = S_FALSE;
  855. CDataObject* pDO = NULL;
  856. CDataObject* pDOSource = NULL;
  857. BOOL bIsQuery = FALSE;
  858. BOOL bState;
  859. ASSERT( NULL != m_ipCompData );
  860. // Bail if we couldn't get the console verb interface, or if the
  861. // selected item is the root;
  862. if ( NULL == pDataObject ) {
  863. ASSERT ( FALSE );
  864. hr = E_POINTER;
  865. } else {
  866. pDO = ExtractOwnDataObject(pDataObject);
  867. }
  868. if ( SUCCEEDED ( hr ) ) {
  869. if ( NULL == (LPDATAOBJECT)arg ) {
  870. ASSERT ( FALSE );
  871. hr = E_INVALIDARG;
  872. } else {
  873. pDOSource = ExtractOwnDataObject((LPDATAOBJECT)arg);
  874. }
  875. }
  876. if ( SUCCEEDED ( hr)
  877. && NULL != pDO
  878. && NULL != pDOSource
  879. && NULL != m_ipCompData
  880. && NULL != m_ipConsoleVerb )
  881. {
  882. bIsQuery = m_ipCompData->IsLogQuery (pDO->GetCookie());
  883. if ( bIsQuery ) {
  884. hr = m_ipConsoleVerb->GetVerbState ( MMC_VERB_PASTE, ENABLED, &bState );
  885. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, TRUE );
  886. hr = m_ipConsoleVerb->GetVerbState ( MMC_VERB_PASTE, ENABLED, &bState );
  887. ASSERT( S_OK == hr );
  888. hr = S_OK;
  889. }
  890. }
  891. return hr;
  892. } // end OnQueryPaste()
  893. //---------------------------------------------------------------------------
  894. // This is a handler for the MMCN_SELECT notification. The user
  895. // selected the node that populated the result pane. We have a
  896. // chance to enable verbs.
  897. //
  898. HRESULT
  899. CComponent::OnSelect (
  900. LPDATAOBJECT pDataObject, // [in] Points to the data object
  901. LPARAM arg, // [in] Contains flags about the selected item
  902. LPARAM /* param */ ) // [in] Not used
  903. {
  904. HRESULT hr = S_OK;
  905. BOOL fScopePane;
  906. BOOL fSelected;
  907. CDataObject* pDO = NULL;
  908. MMC_COOKIE mmcCookie = 0;
  909. BOOL bIsQuery = FALSE;
  910. CSmNode* pNode = NULL;
  911. PSLQUERY pQuery = NULL;
  912. ASSERT( NULL != m_ipCompData );
  913. if ( NULL == pDataObject ) {
  914. ASSERT ( FALSE );
  915. hr = E_POINTER;
  916. } else {
  917. pDO = ExtractOwnDataObject(pDataObject);
  918. if ( NULL == pDO ) {
  919. ASSERT ( FALSE );
  920. hr = E_UNEXPECTED;
  921. }
  922. }
  923. if ( SUCCEEDED ( hr ) ) {
  924. // Bail if we couldn't get the console verb interface, or if the
  925. // selected item is the root;
  926. if( NULL == m_ipConsoleVerb || COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) {
  927. hr = S_OK;
  928. } else {
  929. // Use selections and set which verbs are allowed
  930. fScopePane = LOWORD(arg);
  931. fSelected = HIWORD(arg);
  932. if( fScopePane ) { // Selection in the scope pane
  933. // Enabled refresh for main node type, only if that node type is currently
  934. // being viewed in the result pane.
  935. if ( fSelected ) {
  936. if ( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  937. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType()
  938. || COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() ) {
  939. if ( NULL != m_pViewedNode ) {
  940. if ( m_pViewedNode == (CSmNode*)pDO->GetCookie() ) {
  941. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  942. ASSERT( S_OK == hr );
  943. }
  944. }
  945. }
  946. }
  947. } else {
  948. // Selection in the result pane
  949. // Properties is default verb
  950. if ( NULL != m_ipCompData
  951. && NULL != m_ipConsoleVerb )
  952. {
  953. if ( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  954. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType()
  955. || COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() )
  956. {
  957. if ( NULL != m_pViewedNode ) {
  958. mmcCookie = (MMC_COOKIE)pDO->GetCookie();
  959. bIsQuery = m_ipCompData->IsLogQuery (mmcCookie);
  960. if ( bIsQuery ) {
  961. pQuery = (PSLQUERY)pDO->GetCookie();
  962. if ( NULL != pQuery ) {
  963. pNode = (CSmNode*)pQuery->GetLogService();
  964. }
  965. } else {
  966. pNode = (CSmNode*)pDO->GetCookie();
  967. }
  968. if ( NULL != m_pViewedNode && m_pViewedNode == pNode ) {
  969. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_REFRESH, ENABLED, TRUE );
  970. ASSERT( S_OK == hr );
  971. }
  972. }
  973. }
  974. if ( fSelected ) {
  975. hr = m_ipConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  976. ASSERT( S_OK == hr );
  977. // Enable properties and delete verbs
  978. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  979. ASSERT( S_OK == hr );
  980. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_DELETE, ENABLED, TRUE );
  981. ASSERT( S_OK == hr );
  982. /*
  983. // Enable copying and pasting the object
  984. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_COPY, ENABLED, TRUE );
  985. ASSERT( S_OK == hr );
  986. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PASTE, HIDDEN, FALSE );
  987. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, FALSE );
  988. ASSERT( S_OK == hr );
  989. } else {
  990. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PASTE, HIDDEN, FALSE );
  991. hr = m_ipConsoleVerb->SetVerbState( MMC_VERB_PASTE, ENABLED, FALSE );
  992. ASSERT( S_OK == hr );
  993. */
  994. }
  995. }
  996. }
  997. hr = S_OK;
  998. }
  999. }
  1000. return hr;
  1001. } // end OnSelect()
  1002. //---------------------------------------------------------------------------
  1003. // Respond to the MMCN_REFRESH notification and refresh the rows.
  1004. //
  1005. HRESULT
  1006. CComponent::OnRefresh (
  1007. LPDATAOBJECT pDataObject ) // [in] Points to the data object
  1008. {
  1009. HRESULT hr = S_OK;
  1010. CDataObject* pDO = NULL;
  1011. if ( NULL == pDataObject ) {
  1012. ASSERT ( FALSE );
  1013. hr = E_POINTER;
  1014. } else {
  1015. pDO = ExtractOwnDataObject(pDataObject);
  1016. if ( NULL == pDO ) {
  1017. ASSERT ( FALSE );
  1018. hr = E_UNEXPECTED;
  1019. }
  1020. }
  1021. if ( SUCCEEDED ( hr ) ) {
  1022. // If this is the root node, don't need to do anything
  1023. if( COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) {
  1024. hr = S_FALSE;
  1025. } else {
  1026. // Refresh the data model and update the result pane.
  1027. if ( NULL != m_pViewedNode ) {
  1028. hr = RefreshResultPane( pDataObject );
  1029. }
  1030. // RefreshResultPane cancels any selection.
  1031. hr = HandleExtToolbars( TRUE, (LPARAM)0, (LPARAM)pDataObject );
  1032. }
  1033. }
  1034. return hr;
  1035. } // end OnRefresh()
  1036. //---------------------------------------------------------------------------
  1037. // Respond to the MMCN_VIEW_CHANGE notification and refresh as specified.
  1038. //
  1039. HRESULT
  1040. CComponent::OnViewChange (
  1041. LPDATAOBJECT pDataObject, // [in] Points to the data object
  1042. LPARAM /* arg */, // [in] Not used
  1043. LPARAM param ) // [in] Contains view change hint
  1044. {
  1045. HRESULT hr = S_OK;
  1046. CDataObject* pDO = NULL;
  1047. if ( NULL == pDataObject ) {
  1048. ASSERT ( FALSE );
  1049. hr = E_POINTER;
  1050. } else {
  1051. pDO = ExtractOwnDataObject(pDataObject);
  1052. if ( NULL == pDO ) {
  1053. ASSERT ( FALSE );
  1054. hr = E_UNEXPECTED;
  1055. }
  1056. }
  1057. if ( SUCCEEDED ( hr ) ) {
  1058. if ( NULL == m_ipCompData
  1059. || NULL == m_ipResultData )
  1060. {
  1061. hr = S_FALSE;
  1062. } else {
  1063. if ( m_ipCompData->IsLogService ( pDO->GetCookie() )
  1064. && CComponentData::eSmHintNewQuery == param )
  1065. {
  1066. hr = OnRefresh( pDataObject );
  1067. } else if ( CComponentData::eSmHintPreRefresh == param )
  1068. {
  1069. // Delete the result items in each view before refreshing
  1070. // the queries, to handle the case where queries have been deleted.
  1071. hr = m_ipResultData->DeleteAllRsltItems();
  1072. } else if ( CComponentData::eSmHintRefresh == param )
  1073. {
  1074. // Use the stored pointer to the known viewed node, to handle the
  1075. // case where the result pane contains scope nodes, and to handle
  1076. // the case where the cookie is a query.
  1077. hr = PopulateResultPane( (MMC_COOKIE)m_pViewedNode );
  1078. } else {
  1079. hr = S_FALSE;
  1080. if ( CCT_RESULT == pDO->GetContext() ) {
  1081. HRESULTITEM hItemID = NULL;
  1082. PSLQUERY pSlQuery = reinterpret_cast<PSLQUERY>(pDO->GetCookie());
  1083. if ( NULL != pSlQuery ) {
  1084. // Redraw the item or delete it.
  1085. hr = m_ipResultData->FindItemByLParam ( (LPARAM)pSlQuery, &hItemID );
  1086. if ( SUCCEEDED(hr) ) {
  1087. if ( CComponentData::eSmHintPreDeleteQuery == param ) {
  1088. hr = m_ipResultData->DeleteItem ( hItemID, 0 );
  1089. } else {
  1090. // Query modified via property dialog, or by manual start or stop.
  1091. hr = m_ipResultData->UpdateItem ( hItemID );
  1092. }
  1093. }
  1094. }
  1095. // Sync the toolbar start/stop buttons.
  1096. // 0 second arg indicates result scope.
  1097. hr = HandleExtToolbars( FALSE, (LPARAM)0, (LPARAM)pDataObject );
  1098. }
  1099. }
  1100. }
  1101. }
  1102. return hr;
  1103. }
  1104. //---------------------------------------------------------------------------
  1105. // Implementing a handler for MMCN_PROPERTY_CHANGE.
  1106. // Param is the address of the PROPCHANGE struct that originally
  1107. // came from the PropertySheet via MMCPropertyChangeNotify()
  1108. //
  1109. HRESULT
  1110. CComponent::OnPropertyChange (
  1111. LPARAM /* param */ // [in] PROPCHANGE_DATA struct with new data
  1112. )
  1113. {
  1114. return S_OK;
  1115. } // end OnPropertyChange()
  1116. //---------------------------------------------------------------------------
  1117. // Store the parent IComponetData object.
  1118. //
  1119. HRESULT
  1120. CComponent::SetIComponentData (
  1121. CComponentData* pData ) // [in] Parent CComponentData object
  1122. {
  1123. HRESULT hr = E_POINTER;
  1124. LPUNKNOWN pUnk = NULL;
  1125. ASSERT( NULL == m_ipCompData ); // Can't do this twice
  1126. if ( NULL != pData
  1127. && NULL == m_ipCompData )
  1128. {
  1129. pUnk = pData->GetUnknown(); // Get the object IUnknown
  1130. if ( NULL != pUnk ) {
  1131. hr = pUnk->QueryInterface( IID_IComponentData,
  1132. reinterpret_cast<void**>(&m_ipCompData) );
  1133. } else {
  1134. hr = E_UNEXPECTED;
  1135. }
  1136. }
  1137. return hr;
  1138. } // end SetIComponentData()
  1139. //---------------------------------------------------------------------------
  1140. // Respond to the MMCN_CONTEXTHELP notification.
  1141. //
  1142. HRESULT
  1143. CComponent::OnDisplayHelp (
  1144. LPDATAOBJECT /* pDataObject */ ) // [in] Points to the data object
  1145. {
  1146. HRESULT hr = E_FAIL;
  1147. IDisplayHelp* pDisplayHelp;
  1148. CString strTopicPath;
  1149. LPOLESTR pCompiledHelpFile = NULL;
  1150. UINT nBytes;
  1151. USES_CONVERSION;
  1152. if ( NULL == m_ipCompData
  1153. || NULL == m_ipConsole )
  1154. {
  1155. hr = S_FALSE;
  1156. } else {
  1157. hr = m_ipConsole->QueryInterface(IID_IDisplayHelp, reinterpret_cast<void**>(&pDisplayHelp));
  1158. if ( SUCCEEDED(hr) ) {
  1159. MFC_TRY
  1160. // construct help topic path = (help file::topic string)
  1161. strTopicPath = m_ipCompData->GetConceptsHTMLHelpFileName();
  1162. strTopicPath += L"::/";
  1163. strTopicPath += m_ipCompData->GetHTMLHelpTopic(); // sample.chm::/helptopic.htm
  1164. nBytes = (strTopicPath.GetLength()+1) * sizeof(WCHAR);
  1165. pCompiledHelpFile = (LPOLESTR)::CoTaskMemAlloc(nBytes);
  1166. if ( NULL == pCompiledHelpFile ) {
  1167. hr = E_OUTOFMEMORY;
  1168. } else {
  1169. memcpy(pCompiledHelpFile, (LPCWSTR)strTopicPath, nBytes);
  1170. hr = pDisplayHelp->ShowTopic( pCompiledHelpFile );
  1171. ::CoTaskMemFree ( pCompiledHelpFile );
  1172. pDisplayHelp->Release();
  1173. }
  1174. MFC_CATCH_HR
  1175. }
  1176. }
  1177. return hr;
  1178. } // end OnDisplayHelp()
  1179. /////////////////////////////////////////////////////////////////////////////
  1180. // IExtendContextMenu methods
  1181. //
  1182. //---------------------------------------------------------------------------
  1183. // Implement some context menu items
  1184. //
  1185. STDMETHODIMP
  1186. CComponent::AddMenuItems (
  1187. LPDATAOBJECT pDataObject, // [in] Points to data object
  1188. LPCONTEXTMENUCALLBACK pCallbackUnknown, // [in] Points to callback function
  1189. long* pInsertionAllowed ) // [in,out] Insertion flags
  1190. {
  1191. HRESULT hr = S_OK;
  1192. static CONTEXTMENUITEM ctxMenu[3];
  1193. CDataObject* pDO = NULL;
  1194. CString strTemp1, strTemp2, strTemp3, strTemp4, strTemp5, strTemp6;
  1195. CSmLogQuery* pQuery;
  1196. ResourceStateManager rsm;
  1197. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1198. ASSERT( NULL != m_ipCompData );
  1199. if ( NULL == pDataObject ) {
  1200. ASSERT ( FALSE );
  1201. hr = E_POINTER;
  1202. } else {
  1203. pDO = ExtractOwnDataObject( pDataObject );
  1204. if ( NULL == pDO ) {
  1205. ASSERT ( FALSE );
  1206. hr = E_UNEXPECTED;
  1207. }
  1208. }
  1209. if ( SUCCEEDED ( hr ) ) {
  1210. if ( NULL == m_ipCompData ) {
  1211. hr = S_FALSE;
  1212. } else {
  1213. // Only add menu items when we are allowed to.
  1214. if ( ( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType() )
  1215. || ( COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType() )
  1216. || ( COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() ) )
  1217. {
  1218. if( CCM_INSERTIONALLOWED_NEW & *pInsertionAllowed ) {
  1219. // Add "New Query..." context menu item
  1220. hr = m_ipCompData->AddMenuItems ( pDataObject, pCallbackUnknown, pInsertionAllowed );
  1221. } else if( CCM_INSERTIONALLOWED_TASK & *pInsertionAllowed ) {
  1222. if ( m_ipCompData->IsLogQuery ( pDO->GetCookie() ) ) {
  1223. pQuery = (CSmLogQuery*)pDO->GetCookie();
  1224. if ( NULL != pQuery ) {
  1225. ZeroMemory ( &ctxMenu, sizeof ctxMenu );
  1226. // Add "Start" context menu item
  1227. strTemp1.LoadString ( IDS_MMC_MENU_START );
  1228. strTemp2.LoadString ( IDS_MMC_STATUS_START );
  1229. ctxMenu[0].strName = const_cast<LPWSTR>((LPCWSTR)strTemp1);
  1230. ctxMenu[0].strStatusBarText = const_cast<LPWSTR>((LPCWSTR)strTemp2);
  1231. ctxMenu[0].lCommandID = IDM_START_QUERY;
  1232. ctxMenu[0].lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  1233. ctxMenu[0].fFlags = MF_ENABLED;
  1234. ctxMenu[0].fSpecialFlags = 0;
  1235. // Add "Stop" context menu item
  1236. strTemp3.LoadString ( IDS_MMC_MENU_STOP );
  1237. strTemp4.LoadString ( IDS_MMC_STATUS_STOP );
  1238. ctxMenu[1].strName = const_cast<LPWSTR>((LPCWSTR)strTemp3);
  1239. ctxMenu[1].strStatusBarText = const_cast<LPWSTR>((LPCWSTR)strTemp4);
  1240. ctxMenu[1].lCommandID = IDM_STOP_QUERY;
  1241. ctxMenu[1].lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  1242. ctxMenu[1].fFlags = MF_ENABLED;
  1243. ctxMenu[1].fSpecialFlags = 0;
  1244. // Add "Save As..." context menu item
  1245. strTemp5.LoadString ( IDS_MMC_MENU_SAVE_AS );
  1246. strTemp6.LoadString ( IDS_MMC_STATUS_SAVE_AS );
  1247. ctxMenu[2].strName = const_cast<LPWSTR>((LPCWSTR)strTemp5);
  1248. ctxMenu[2].strStatusBarText = const_cast<LPWSTR>((LPCWSTR)strTemp6);
  1249. ctxMenu[2].lCommandID = IDM_SAVE_QUERY_AS;
  1250. ctxMenu[2].lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TOP;
  1251. ctxMenu[2].fFlags = MF_ENABLED;
  1252. ctxMenu[2].fSpecialFlags = 0;
  1253. if ( pQuery->IsRunning() ) {
  1254. ctxMenu[0].fFlags = MF_GRAYED;
  1255. } else {
  1256. ctxMenu[1].fFlags = MF_GRAYED;
  1257. }
  1258. hr = pCallbackUnknown->AddItem( &ctxMenu[0] );
  1259. if ( SUCCEEDED( hr ) ) {
  1260. hr = pCallbackUnknown->AddItem( &ctxMenu[1] );
  1261. }
  1262. if ( SUCCEEDED( hr ) ) {
  1263. hr = pCallbackUnknown->AddItem( &ctxMenu[2] );
  1264. }
  1265. } else {
  1266. ASSERT ( FALSE );
  1267. hr = E_UNEXPECTED;
  1268. }
  1269. }
  1270. }
  1271. } else {
  1272. hr = S_OK;
  1273. }
  1274. }
  1275. }
  1276. return hr;
  1277. } // end AddMenuItems()
  1278. //---------------------------------------------------------------------------
  1279. // Implement the command method so we can handle notifications
  1280. // from our Context menu extensions.
  1281. //
  1282. STDMETHODIMP
  1283. CComponent::Command (
  1284. long nCommandID, // [in] Command to handle
  1285. LPDATAOBJECT pDataObject ) // [in] Points to data object, pass through
  1286. {
  1287. HRESULT hr = S_OK;
  1288. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1289. ASSERT( NULL != m_ipCompData );
  1290. if ( NULL != m_ipCompData ) {
  1291. switch( nCommandID ) {
  1292. case IDM_NEW_QUERY:
  1293. m_ipCompData->CreateNewLogQuery( pDataObject );
  1294. break;
  1295. case IDM_NEW_QUERY_FROM:
  1296. m_ipCompData->CreateLogQueryFrom( pDataObject );
  1297. break;
  1298. case IDM_START_QUERY:
  1299. StartLogQuery( pDataObject );
  1300. break;
  1301. case IDM_STOP_QUERY:
  1302. StopLogQuery( pDataObject );
  1303. break;
  1304. case IDM_SAVE_QUERY_AS:
  1305. SaveLogQueryAs( pDataObject );
  1306. break;
  1307. default:
  1308. hr = S_FALSE;
  1309. }
  1310. } else {
  1311. hr = S_FALSE;
  1312. }
  1313. return hr;
  1314. } // end Command()
  1315. /////////////////////////////////////////////////////////////////////////////
  1316. // IExtendControlBar implementation
  1317. //---------------------------------------------------------------------------
  1318. // Now the toolbar has three buttons
  1319. // We don't attach the toolbar to a window yet, that is handled
  1320. // after we get a notification.
  1321. //
  1322. STDMETHODIMP
  1323. CComponent::SetControlbar (
  1324. LPCONTROLBAR pControlbar ) // [in] Points to IControlBar
  1325. {
  1326. HRESULT hr = S_OK;
  1327. HBITMAP hbmpToolbarRes = NULL;
  1328. HWND hwndMain = NULL;
  1329. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1330. if ( NULL != m_ipConsole ) {
  1331. if( NULL != pControlbar ) { // Make sure the Controlbar is OK
  1332. if( NULL != m_ipControlbar ) { // Don't orphan it if we already
  1333. // had a pointer to it
  1334. m_ipControlbar->Release();
  1335. }
  1336. m_ipControlbar = pControlbar; // Cache the pointer
  1337. m_ipControlbar->AddRef();
  1338. if( NULL == m_ipToolbarLogger ) { // Toolbar not created yet...
  1339. hr = m_ipControlbar->Create(
  1340. TOOLBAR,
  1341. this,
  1342. reinterpret_cast<LPUNKNOWN*>(&m_ipToolbarLogger) );
  1343. if ( SUCCEEDED ( hr ) ) {
  1344. hr = m_ipConsole->GetMainWindow( &hwndMain );
  1345. }
  1346. if ( SUCCEEDED ( hr ) ) {
  1347. LoadLogToolbarStrings ( ToolbarResultBtnsLog );
  1348. // Add the toolbar bitmap
  1349. // Load special start button bitmap if RTL layout is enabled.
  1350. if ( ! ( CWnd::FromHandle(hwndMain)->GetExStyle() & WS_EX_LAYOUTRTL ) ) {
  1351. hbmpToolbarRes = LoadBitmap( g_hinst, MAKEINTRESOURCE(IDB_TOOLBAR_RES));
  1352. } else {
  1353. hbmpToolbarRes = LoadBitmap( g_hinst, MAKEINTRESOURCE(IDB_TOOLBAR_RES_RTL ));
  1354. }
  1355. hr = m_ipToolbarLogger->AddBitmap( 3, hbmpToolbarRes, 16, 16, RGB(255,0,255) );
  1356. ASSERT( SUCCEEDED(hr) );
  1357. // Add a few buttons
  1358. hr = m_ipToolbarLogger->AddButtons(cResultBtnsLog, ToolbarResultBtnsLog);
  1359. }
  1360. }
  1361. if( NULL == m_ipToolbarAlerts ) { // Toolbar not created yet...
  1362. hr = m_ipControlbar->Create(
  1363. TOOLBAR,
  1364. this,
  1365. reinterpret_cast<LPUNKNOWN*>(&m_ipToolbarAlerts) );
  1366. if ( SUCCEEDED ( hr ) ) {
  1367. hr = m_ipConsole->GetMainWindow( &hwndMain );
  1368. }
  1369. if ( SUCCEEDED ( hr ) ) {
  1370. LoadAlertToolbarStrings ( ToolbarResultBtnsAlert );
  1371. // Add the toolbar bitmap
  1372. // Load special start button bitmap if RTL layout is enabled.
  1373. if ( ! ( CWnd::FromHandle(hwndMain)->GetExStyle() & WS_EX_LAYOUTRTL ) ) {
  1374. hbmpToolbarRes = LoadBitmap( g_hinst, MAKEINTRESOURCE(IDB_TOOLBAR_RES));
  1375. } else {
  1376. hbmpToolbarRes = LoadBitmap( g_hinst, MAKEINTRESOURCE(IDB_TOOLBAR_RES_RTL ));
  1377. }
  1378. hr = m_ipToolbarAlerts->AddBitmap( 3, hbmpToolbarRes, 16, 16, RGB(255,0,255) );
  1379. // Add a few buttons
  1380. hr = m_ipToolbarAlerts->AddButtons(cResultBtnsAlert, ToolbarResultBtnsAlert);
  1381. }
  1382. }
  1383. if( NULL != hbmpToolbarRes ) {
  1384. DeleteObject(hbmpToolbarRes);
  1385. }
  1386. // Finished creating the toolbars
  1387. hr = S_OK;
  1388. } else {
  1389. hr = S_FALSE; // No ControlBar available
  1390. }
  1391. } else {
  1392. hr = S_FALSE; // No m_ipConsole
  1393. }
  1394. return hr;
  1395. } // end SetControlBar()
  1396. //---------------------------------------------------------------------------
  1397. // Handle ControlBar notifications to our toolbar
  1398. // Now we can delete an object
  1399. //
  1400. STDMETHODIMP
  1401. CComponent::ControlbarNotify (
  1402. MMC_NOTIFY_TYPE event, // [in] Type of notification
  1403. LPARAM arg, // [in] Depends on notification
  1404. LPARAM param ) // [in] Depends on notification
  1405. {
  1406. HRESULT hr = S_OK;
  1407. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1408. ASSERT( NULL != m_ipCompData );
  1409. if ( NULL != m_ipCompData ) {
  1410. switch( event ){
  1411. case MMCN_BTN_CLICK: // For a Controlbar click, the
  1412. switch( param ) { // param is the MenuItemID
  1413. case IDM_NEW_QUERY:
  1414. m_ipCompData->CreateNewLogQuery( reinterpret_cast<LPDATAOBJECT>(arg) );
  1415. break;
  1416. case IDM_START_QUERY:
  1417. StartLogQuery ( reinterpret_cast<LPDATAOBJECT>(arg) );
  1418. break;
  1419. case IDM_STOP_QUERY:
  1420. StopLogQuery ( reinterpret_cast<LPDATAOBJECT>(arg) );
  1421. break;
  1422. default:
  1423. LOCALTRACE( L"ControlbarNotify: Unknown message" );
  1424. }
  1425. break;
  1426. case MMCN_DESELECT_ALL: // How to display the Toolbar
  1427. case MMCN_SELECT:
  1428. hr = HandleExtToolbars( (event == MMCN_DESELECT_ALL), arg, param );
  1429. break;
  1430. case MMCN_MENU_BTNCLICK: // Not handling menus here
  1431. DebugMsg( L"MMCN_MENU_BTNCLICK", L"CComponent::ControlbarNotify");
  1432. // Drop through...
  1433. default:
  1434. hr = S_FALSE;
  1435. break;
  1436. }
  1437. } else {
  1438. hr = S_FALSE;
  1439. }
  1440. return hr;
  1441. } // end ControlbarNotify()
  1442. //---------------------------------------------------------------------------
  1443. // Handle how the toolbars are displayed
  1444. //
  1445. HRESULT
  1446. CComponent::HandleExtToolbars (
  1447. bool bDeselectAll, // [in] Notification
  1448. LPARAM /* arg */, // [in] Depends on notification
  1449. LPARAM param // [in] Depends on notification
  1450. )
  1451. {
  1452. HRESULT hr = S_OK;
  1453. BOOL bStartEnable = FALSE;
  1454. BOOL bStopEnable = FALSE;
  1455. BOOL bNewEnable = FALSE;
  1456. CDataObject* pDO = NULL;
  1457. LPDATAOBJECT pDataObject;
  1458. CSmLogQuery* pQuery = NULL;
  1459. ASSERT( NULL != m_ipCompData );
  1460. if ( NULL != m_ipCompData ) {
  1461. pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  1462. if( NULL == pDataObject ) {
  1463. hr = S_FALSE;
  1464. } else {
  1465. pDO = ExtractOwnDataObject( pDataObject );
  1466. if ( NULL == pDO ) {
  1467. hr = E_UNEXPECTED;
  1468. }
  1469. if ( SUCCEEDED ( hr ) ) {
  1470. hr = S_FALSE;
  1471. if( CCT_SCOPE == pDO->GetContext() ) {
  1472. // Scope item selected, in either the scope or result pane.
  1473. if( COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) {
  1474. if ( NULL != m_ipToolbarAttached ) {
  1475. hr = m_ipControlbar->Detach( (LPUNKNOWN)m_ipToolbarAttached );
  1476. m_ipToolbarAttached = NULL;
  1477. }
  1478. ASSERT( SUCCEEDED(hr) );
  1479. } else if( COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() ) {
  1480. // Attach the Alerts toolbar
  1481. if ( m_ipToolbarAttached != NULL && m_ipToolbarAttached != m_ipToolbarAlerts ) {
  1482. hr = m_ipControlbar->Detach( (LPUNKNOWN)m_ipToolbarAttached );
  1483. m_ipToolbarAttached = NULL;
  1484. }
  1485. hr = m_ipControlbar->Attach(TOOLBAR, (LPUNKNOWN)m_ipToolbarAlerts);
  1486. ASSERT( SUCCEEDED(hr) );
  1487. m_ipToolbarAttached = m_ipToolbarAlerts;
  1488. bNewEnable = TRUE;
  1489. } else {
  1490. // Attach the Logger toolbar
  1491. if ( m_ipToolbarAttached != NULL && m_ipToolbarAttached != m_ipToolbarLogger ) {
  1492. hr = m_ipControlbar->Detach( (LPUNKNOWN)m_ipToolbarAttached );
  1493. m_ipToolbarAttached = NULL;
  1494. }
  1495. hr = m_ipControlbar->Attach(TOOLBAR, (LPUNKNOWN)m_ipToolbarLogger);
  1496. ASSERT( SUCCEEDED(hr) );
  1497. m_ipToolbarAttached = m_ipToolbarLogger;
  1498. bNewEnable = TRUE;
  1499. }
  1500. } else {
  1501. if ( !bDeselectAll ) {
  1502. // Result pane context.
  1503. if( CCT_RESULT == pDO->GetContext() ) {
  1504. bStartEnable = m_ipCompData->IsLogQuery (pDO->GetCookie()) ? TRUE : FALSE;
  1505. if (bStartEnable) {
  1506. // then this is a log query, so see if the item is running or not
  1507. pQuery = (CSmLogQuery*)pDO->GetCookie();
  1508. if ( NULL != pQuery ) {
  1509. if (pQuery->IsRunning()) {
  1510. // enable only the stop button
  1511. bStartEnable = FALSE;
  1512. } else {
  1513. // enable only the start button
  1514. }
  1515. } else {
  1516. ASSERT ( FALSE );
  1517. }
  1518. bStopEnable = !bStartEnable;
  1519. }
  1520. }
  1521. } else {
  1522. bNewEnable = TRUE;
  1523. }
  1524. }
  1525. if ( NULL != m_ipToolbarAttached ) {
  1526. hr = m_ipToolbarAttached->SetButtonState( IDM_NEW_QUERY, ENABLED , bNewEnable );
  1527. ASSERT( SUCCEEDED(hr) );
  1528. hr = m_ipToolbarAttached->SetButtonState( IDM_START_QUERY, ENABLED , bStartEnable );
  1529. ASSERT( SUCCEEDED(hr) );
  1530. hr = m_ipToolbarAttached->SetButtonState( IDM_STOP_QUERY, ENABLED , bStopEnable );
  1531. ASSERT( SUCCEEDED(hr) );
  1532. }
  1533. }
  1534. }
  1535. } else {
  1536. hr = S_FALSE;
  1537. }
  1538. return hr;
  1539. } // end HandleExtToolbars()
  1540. /////////////////////////////////////////////////////////////////////////////
  1541. // IExtendPropertySheet implementation
  1542. //
  1543. HRESULT
  1544. CComponent::AddPropertyPage (
  1545. LPPROPERTYSHEETCALLBACK lpProvider,
  1546. CSmPropertyPage*& rpPage
  1547. )
  1548. {
  1549. HRESULT hr = S_OK;
  1550. PROPSHEETPAGE_V3 sp_v3 = {0};
  1551. HPROPSHEETPAGE hPage = NULL;
  1552. ASSERT( NULL != m_ipCompData );
  1553. if ( NULL != m_ipCompData ) {
  1554. if ( NULL == rpPage ) {
  1555. ASSERT ( FALSE );
  1556. hr = E_UNEXPECTED;
  1557. } else {
  1558. rpPage->SetContextHelpFilePath( m_ipCompData->GetContextHelpFilePath() );
  1559. rpPage->m_psp.lParam = (INT_PTR)rpPage;
  1560. rpPage->m_psp.pfnCallback = &CSmPropertyPage::PropSheetPageProc;
  1561. CopyMemory (&sp_v3, &rpPage->m_psp, rpPage->m_psp.dwSize);
  1562. sp_v3.dwSize = sizeof(sp_v3);
  1563. hPage = CreatePropertySheetPage (&sp_v3);
  1564. if ( NULL != hPage ) {
  1565. hr = lpProvider->AddPage(hPage);
  1566. if ( FAILED(hr) ) {
  1567. ASSERT ( FALSE );
  1568. delete rpPage;
  1569. rpPage = NULL;
  1570. }
  1571. } else {
  1572. delete rpPage;
  1573. rpPage = NULL;
  1574. ASSERT ( FALSE );
  1575. hr = E_UNEXPECTED;
  1576. }
  1577. }
  1578. } else {
  1579. hr = S_FALSE;
  1580. }
  1581. return hr;
  1582. }
  1583. HRESULT
  1584. CComponent::CreatePropertyPages(
  1585. LPPROPERTYSHEETCALLBACK lpProvider, // Pointer to the callback interface
  1586. LONG_PTR handle, // Handle for routing notification
  1587. LPDATAOBJECT pDataObject // Pointer to the data object
  1588. )
  1589. {
  1590. HRESULT hr = S_OK;
  1591. CDataObject* pDO = NULL;
  1592. MMC_COOKIE Cookie;
  1593. CSmLogQuery* pQuery = NULL;
  1594. DWORD dwLogType;
  1595. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1596. ASSERT( NULL != m_ipCompData );
  1597. if ( NULL == pDataObject
  1598. || NULL == lpProvider ) {
  1599. ASSERT ( FALSE );
  1600. hr = E_POINTER;
  1601. } else {
  1602. pDO = ExtractOwnDataObject(pDataObject);
  1603. if ( NULL == pDO ) {
  1604. ASSERT ( FALSE );
  1605. hr = E_UNEXPECTED;
  1606. }
  1607. }
  1608. // We cheat a little here and pass what we need to a custom
  1609. // constructor for our derived property page class
  1610. if ( SUCCEEDED ( hr ) ) {
  1611. if ( NULL != m_ipCompData ) {
  1612. Cookie = pDO->GetCookie();
  1613. if ( NULL != Cookie ) {
  1614. CWnd* pPropSheet = NULL;
  1615. pQuery = (CSmLogQuery *)Cookie;
  1616. if ( NULL != pQuery ) {
  1617. // If the property sheet for this query is already active, just bring it to the foreground.
  1618. pPropSheet = pQuery->GetActivePropertySheet();
  1619. if ( NULL != pPropSheet ) {
  1620. pPropSheet->SetForegroundWindow();
  1621. MMCFreeNotifyHandle(handle);
  1622. hr = S_FALSE;
  1623. } else {
  1624. dwLogType = pQuery->GetLogType();
  1625. if (SLQ_ALERT != dwLogType) {
  1626. if ( SLQ_TRACE_LOG == dwLogType) {
  1627. CSmPropertyPage* pPage1 = NULL;
  1628. CWaitCursor WaitCursor;
  1629. // Connect to the server before creating the dialog
  1630. // so that the wait cursor can be used consistently.
  1631. // Sync the providers here so that the WMI calls are consistently
  1632. // from a single thread.
  1633. ASSERT ( NULL != pQuery->CastToTraceLogQuery() );
  1634. hr = (pQuery->CastToTraceLogQuery())->SyncGenProviders();
  1635. if ( SUCCEEDED ( hr ) ) {
  1636. MFC_TRY
  1637. pPage1 = new CProvidersProperty (Cookie, handle);
  1638. if ( NULL != pPage1 ) {
  1639. hr = AddPropertyPage ( lpProvider, pPage1 );
  1640. }
  1641. MFC_CATCH_HR
  1642. } else {
  1643. CString strMachineName;
  1644. CString strLogName;
  1645. pQuery->GetMachineDisplayName( strMachineName );
  1646. strLogName = pQuery->GetLogName();
  1647. m_ipCompData->HandleTraceConnectError (
  1648. hr,
  1649. strLogName,
  1650. strMachineName );
  1651. }
  1652. } else {
  1653. CSmPropertyPage *pPage1 = NULL;
  1654. MFC_TRY
  1655. pPage1 = new CCountersProperty (Cookie, handle );
  1656. if ( NULL != pPage1 ) {
  1657. hr = AddPropertyPage ( lpProvider, pPage1 );
  1658. }
  1659. MFC_CATCH_HR
  1660. }
  1661. if ( SUCCEEDED(hr) ) {
  1662. CSmPropertyPage* pPage2 = NULL;
  1663. CSmPropertyPage* pPage3 = NULL;
  1664. MFC_TRY
  1665. pPage2 = new CFilesProperty(Cookie, handle);
  1666. if ( NULL != pPage2 ) {
  1667. hr = AddPropertyPage ( lpProvider, pPage2 );
  1668. }
  1669. if ( SUCCEEDED(hr) ) {
  1670. pPage3 = new CScheduleProperty (Cookie, handle, pDataObject );
  1671. if ( NULL != pPage3 ) {
  1672. hr = AddPropertyPage ( lpProvider, pPage3 );
  1673. }
  1674. }
  1675. MFC_CATCH_HR
  1676. if ( FAILED(hr) ) {
  1677. if ( NULL != pPage3 ) {
  1678. delete pPage3;
  1679. }
  1680. if ( NULL != pPage2 ) {
  1681. delete pPage2;
  1682. }
  1683. }
  1684. }
  1685. if ( SUCCEEDED(hr) ) {
  1686. if ( SLQ_TRACE_LOG == pQuery->GetLogType() ) {
  1687. CSmPropertyPage* pPage4 = NULL;
  1688. MFC_TRY
  1689. pPage4 = new CTraceProperty(Cookie, handle);
  1690. if ( NULL != pPage4 ) {
  1691. hr = AddPropertyPage ( lpProvider, pPage4 );
  1692. }
  1693. MFC_CATCH_HR
  1694. }
  1695. }
  1696. } else {
  1697. ASSERT ( SLQ_ALERT == dwLogType );
  1698. CSmPropertyPage* pPage1 = NULL;
  1699. CSmPropertyPage* pPage2 = NULL;
  1700. CSmPropertyPage* pPage3 = NULL;
  1701. MFC_TRY
  1702. pPage1 = new CAlertGenProp (Cookie, handle);
  1703. if ( NULL != pPage1 ) {
  1704. hr = AddPropertyPage ( lpProvider, pPage1 );
  1705. }
  1706. if ( SUCCEEDED(hr) ) {
  1707. pPage2 = new CAlertActionProp (Cookie, handle);
  1708. if ( NULL != pPage2 ) {
  1709. hr = AddPropertyPage ( lpProvider, pPage2 );
  1710. }
  1711. }
  1712. if ( SUCCEEDED(hr) ) {
  1713. pPage3 = new CScheduleProperty (Cookie, handle, pDataObject);
  1714. if ( NULL != pPage3 ) {
  1715. hr = AddPropertyPage ( lpProvider, pPage3 );
  1716. }
  1717. }
  1718. MFC_CATCH_HR
  1719. if ( FAILED(hr) ) {
  1720. if ( NULL != pPage3 ) {
  1721. delete pPage3;
  1722. }
  1723. if ( NULL != pPage2 ) {
  1724. delete pPage2;
  1725. }
  1726. if ( NULL != pPage1 ) {
  1727. delete pPage1;
  1728. }
  1729. }
  1730. }
  1731. }
  1732. } else {
  1733. ASSERT ( FALSE );
  1734. hr = E_UNEXPECTED;
  1735. }
  1736. } else {
  1737. ASSERT ( FALSE );
  1738. hr = E_UNEXPECTED;
  1739. }
  1740. } else {
  1741. hr = S_FALSE;
  1742. }
  1743. }
  1744. return hr;
  1745. } // end CreatePropertyPages()
  1746. //---------------------------------------------------------------------------
  1747. // The console calls this method to determine whether the Properties menu
  1748. // item should be added to the context menu. We added the Properties item
  1749. // by enabling the verb. So long as we have a vaild DataObject we
  1750. // can return OK.
  1751. //
  1752. HRESULT
  1753. CComponent::QueryPagesFor (
  1754. LPDATAOBJECT pDataObject ) // [in] Points to IDataObject for selected node
  1755. {
  1756. HRESULT hr = S_OK;
  1757. CDataObject* pDO = NULL;
  1758. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1759. if ( NULL == pDataObject ) {
  1760. ASSERT ( FALSE );
  1761. hr = E_POINTER;
  1762. } else {
  1763. pDO = ExtractOwnDataObject(pDataObject);
  1764. if ( NULL == pDO ) {
  1765. ASSERT ( FALSE );
  1766. hr = E_UNEXPECTED;
  1767. }
  1768. }
  1769. if ( SUCCEEDED ( hr ) ) {
  1770. if ( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  1771. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType()
  1772. || COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() )
  1773. {
  1774. hr = S_OK;
  1775. } else {
  1776. hr = S_FALSE;
  1777. }
  1778. }
  1779. return hr;
  1780. } // end QueryPagesFor()
  1781. HRESULT
  1782. CComponent::PopulateResultPane (
  1783. MMC_COOKIE mmcCookie )
  1784. {
  1785. HRESULT hr = S_OK;
  1786. PSLSVC pSLSVC = NULL;
  1787. PSLQUERY pSlQuery = NULL;
  1788. POSITION Pos;
  1789. RESULTDATAITEM rdi;
  1790. ASSERT ( NULL != m_ipResultData );
  1791. if ( NULL == mmcCookie ) {
  1792. ASSERT ( FALSE );
  1793. hr = E_INVALIDARG;
  1794. } else {
  1795. if ( NULL == m_ipResultData ) {
  1796. hr = S_FALSE;
  1797. } else {
  1798. pSLSVC = reinterpret_cast<PSLSVC>(mmcCookie);
  1799. ASSERT ( NULL != pSLSVC->CastToLogService() );
  1800. hr = m_ipResultData->DeleteAllRsltItems();
  1801. if( SUCCEEDED(hr) ) {
  1802. memset(&rdi, 0, sizeof(RESULTDATAITEM));
  1803. rdi.mask = RDI_STR | // Displayname is valid
  1804. // RDI_IMAGE | // nImage is valid
  1805. RDI_PARAM; // lParam is valid
  1806. rdi.str = MMC_CALLBACK;
  1807. rdi.nImage = 2;
  1808. Pos = pSLSVC->m_QueryList.GetHeadPosition();
  1809. // load the query object pointers into the results page
  1810. while ( Pos != NULL) {
  1811. pSlQuery = pSLSVC->m_QueryList.GetNext( Pos );
  1812. rdi.lParam = reinterpret_cast<LPARAM>(pSlQuery);
  1813. hr = m_ipResultData->InsertItem( &rdi );
  1814. if( FAILED(hr) )
  1815. DisplayError( hr, L"PopulateResultPane" );
  1816. }
  1817. }
  1818. }
  1819. }
  1820. return hr;
  1821. } // end PopulateResultPane()
  1822. HRESULT
  1823. CComponent::RefreshResultPane (
  1824. LPDATAOBJECT pDataObject )
  1825. {
  1826. HRESULT hr = S_OK;
  1827. DWORD dwStatus = ERROR_SUCCESS;
  1828. PSLSVC pSLSVC = NULL;
  1829. PSLQUERY pActiveQuery = NULL;
  1830. CString strMessage;
  1831. CString strTitle;
  1832. INT iResult;
  1833. // pDataObject is provided to pass through to UpdateAllViews.
  1834. // Use the stored pointer to the known viewed node, to handle the
  1835. // case where the result pane contains scope nodes, and to handle
  1836. // the case where the cookie is a query.
  1837. pSLSVC = reinterpret_cast<PSLSVC>(m_pViewedNode);
  1838. if ( NULL != pSLSVC ) {
  1839. dwStatus = pSLSVC->CheckForActiveQueries ( &pActiveQuery );
  1840. if ( ERROR_SUCCESS == dwStatus ) {
  1841. // UpdateAllViews is called to delete list items in all result panes.
  1842. m_ipConsole->UpdateAllViews ( pDataObject, 0, CComponentData::eSmHintPreRefresh );
  1843. dwStatus = pSLSVC->SyncWithRegistry ( &pActiveQuery );
  1844. }
  1845. if ( ERROR_SUCCESS == dwStatus ) {
  1846. // UpdateAllViews is called to populate all result panes.
  1847. m_ipConsole->UpdateAllViews ( pDataObject, 0, CComponentData::eSmHintRefresh );
  1848. } else {
  1849. if ( NULL != pActiveQuery ) {
  1850. // Don't refresh queries with open property pages.
  1851. strMessage.LoadString ( IDS_ERRMSG_REFRESH_OPEN_QUERY );
  1852. strTitle.LoadString ( IDS_PROJNAME );
  1853. hr = m_ipConsole->MessageBox(
  1854. (LPCWSTR)strMessage,
  1855. (LPCWSTR)strTitle,
  1856. MB_OK | MB_ICONWARNING,
  1857. &iResult );
  1858. ((CWnd*)pActiveQuery->GetActivePropertySheet())->SetForegroundWindow();
  1859. }
  1860. hr = E_FAIL;
  1861. }
  1862. }
  1863. return hr;
  1864. }
  1865. HRESULT
  1866. CComponent::OnDelete (
  1867. LPDATAOBJECT pDataObject, // [in] Points to data object
  1868. LPARAM /* arg */ , // Not used
  1869. LPARAM /* param */ // Not used
  1870. )
  1871. {
  1872. HRESULT hr = S_OK;
  1873. DWORD dwStatus = ERROR_SUCCESS;
  1874. CDataObject *pDO = NULL;
  1875. PSLQUERY pQuery = NULL;
  1876. CSmLogService* pSvc = NULL;
  1877. int iResult;
  1878. CString strMessage;
  1879. CString csTitle;
  1880. CString strMachineName;
  1881. MMC_COOKIE mmcCookie = 0;
  1882. BOOL bIsQuery = FALSE;
  1883. BOOL bContinue = TRUE;
  1884. ResourceStateManager rsm;
  1885. HRESULTITEM hItemID = NULL;
  1886. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1887. ASSERT( NULL != m_ipCompData );
  1888. if ( NULL == pDataObject ) {
  1889. ASSERT ( FALSE );
  1890. hr = E_POINTER;
  1891. } else if ( NULL == m_ipCompData || NULL == m_ipConsole ) {
  1892. hr = S_FALSE;
  1893. } else {
  1894. pDO = ExtractOwnDataObject( pDataObject );
  1895. if( NULL == pDO ) {
  1896. // Unknown data object
  1897. strMessage.LoadString ( IDS_ERRMSG_UNKDATAOBJ );
  1898. hr = m_ipConsole->MessageBox( (LPCWSTR)strMessage,
  1899. L"CComponentData::OnDelete",
  1900. MB_OK | MB_ICONERROR,
  1901. &iResult
  1902. );
  1903. ASSERT ( FALSE );
  1904. hr = E_UNEXPECTED;
  1905. } else {
  1906. // If this is the root node, don't need to do anything
  1907. if( COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) {
  1908. hr = S_FALSE;
  1909. } else {
  1910. // Just make sure we are where we think we are
  1911. ASSERT( CCT_RESULT == pDO->GetContext() );
  1912. ASSERT( COOKIE_IS_COUNTERMAINNODE == pDO->GetCookieType()
  1913. || COOKIE_IS_TRACEMAINNODE == pDO->GetCookieType()
  1914. || COOKIE_IS_ALERTMAINNODE == pDO->GetCookieType() );
  1915. mmcCookie = (MMC_COOKIE)pDO->GetCookie();
  1916. bIsQuery = m_ipCompData->IsLogQuery (mmcCookie);
  1917. if (bIsQuery) {
  1918. pQuery = (PSLQUERY)mmcCookie;
  1919. if ( NULL != pQuery ) {
  1920. pSvc = ( pQuery->GetLogService() );
  1921. if ( !pQuery->IsExecuteOnly() ) {
  1922. if ( pQuery->IsModifiable() ) {
  1923. if ( m_ipCompData->IsRunningQuery( pQuery ) ) {
  1924. iResult = IDOK;
  1925. // Don't delete running queries. Stop the query if requested
  1926. // by the user.
  1927. strMessage.LoadString ( IDS_ERRMSG_DELETE_RUNNING_QUERY );
  1928. csTitle.LoadString ( IDS_PROJNAME );
  1929. hr = m_ipConsole->MessageBox(
  1930. (LPCWSTR)strMessage,
  1931. (LPCWSTR)csTitle,
  1932. MB_OKCANCEL | MB_ICONWARNING,
  1933. &iResult
  1934. );
  1935. if ( IDOK == iResult ) {
  1936. // If property page is open, StopLogQuery
  1937. // shows error message
  1938. hr = StopLogQuery ( pDataObject, FALSE );
  1939. if ( FAILED ( hr )
  1940. || S_FALSE == hr ) {
  1941. bContinue = FALSE;
  1942. hr = S_FALSE;
  1943. }
  1944. } else {
  1945. bContinue = FALSE;
  1946. hr = S_FALSE;
  1947. }
  1948. } else if ( NULL != pQuery->GetActivePropertySheet() ){
  1949. // Don't delete queries with open property pages.
  1950. strMessage.LoadString ( IDS_ERRMSG_DELETE_OPEN_QUERY );
  1951. csTitle.LoadString ( IDS_PROJNAME );
  1952. hr = m_ipConsole->MessageBox(
  1953. (LPCWSTR)strMessage,
  1954. (LPCWSTR)csTitle,
  1955. MB_OK | MB_ICONWARNING,
  1956. &iResult );
  1957. ((CWnd*)pQuery->GetActivePropertySheet())->SetForegroundWindow();
  1958. bContinue = FALSE;
  1959. hr = S_FALSE;
  1960. }
  1961. if ( bContinue ) {
  1962. if ( NULL != pSvc ) {
  1963. hr = m_ipConsole->UpdateAllViews (
  1964. pDataObject,
  1965. 0,
  1966. CComponentData::eSmHintPreDeleteQuery );
  1967. if ( SUCCEEDED(hr) ) {
  1968. dwStatus = pSvc->DeleteQuery(pQuery);
  1969. // Mark as deleted. Already deleted
  1970. // from the UI of each view.
  1971. hr = S_OK;
  1972. } else {
  1973. hr = S_FALSE;
  1974. }
  1975. } else {
  1976. ASSERT ( FALSE );
  1977. hr = E_UNEXPECTED;
  1978. }
  1979. }
  1980. } else {
  1981. if ( NULL != pSvc ) {
  1982. strMachineName = pSvc->GetMachineDisplayName();
  1983. } else {
  1984. strMachineName.Empty();
  1985. }
  1986. FormatSmLogCfgMessage (
  1987. strMessage,
  1988. m_hModule,
  1989. SMCFG_NO_MODIFY_ACCESS,
  1990. (LPCWSTR)strMachineName);
  1991. csTitle.LoadString ( IDS_PROJNAME );
  1992. hr = m_ipConsole->MessageBox(
  1993. (LPCWSTR)strMessage,
  1994. (LPCWSTR)csTitle,
  1995. MB_OK | MB_ICONERROR,
  1996. &iResult );
  1997. hr = S_FALSE;
  1998. }
  1999. } else {
  2000. // Don't delete template queries.
  2001. strMessage.LoadString ( IDS_ERRMSG_DELETE_TEMPLATE_QRY );
  2002. csTitle.LoadString ( IDS_PROJNAME );
  2003. hr = m_ipConsole->MessageBox(
  2004. (LPCWSTR)strMessage,
  2005. (LPCWSTR)csTitle,
  2006. MB_OK | MB_ICONERROR,
  2007. &iResult
  2008. );
  2009. hr = S_FALSE;
  2010. }
  2011. } else {
  2012. ASSERT ( FALSE );
  2013. hr = E_UNEXPECTED;
  2014. }
  2015. } else {
  2016. hr = S_FALSE;
  2017. }
  2018. }
  2019. }
  2020. }
  2021. return hr;
  2022. }
  2023. HRESULT
  2024. CComponent::OnDoubleClick (
  2025. ULONG ulRecNo,
  2026. LPDATAOBJECT pDataObject ) // [in] Points to the data object
  2027. {
  2028. HRESULT hr = S_OK;
  2029. CDataObject* pDO = NULL;
  2030. MMC_COOKIE mmcCookie;
  2031. BOOL bIsQuery = FALSE;
  2032. PSLQUERY pQuery = NULL;
  2033. LONG_PTR handle = NULL;
  2034. CWnd* pPropSheet = NULL;
  2035. ASSERT( NULL != m_ipCompData );
  2036. if ( NULL == pDataObject ) {
  2037. ASSERT ( FALSE );
  2038. hr = E_POINTER;
  2039. } else {
  2040. pDO = ExtractOwnDataObject(pDataObject);
  2041. if ( NULL == pDO ) {
  2042. hr = S_OK;
  2043. } else {
  2044. // If this is the root node, don't need to do anything
  2045. if( COOKIE_IS_ROOTNODE == pDO->GetCookieType() ) {
  2046. hr = S_FALSE;
  2047. } else if ( CCT_RESULT != pDO->GetContext() ) {
  2048. // Just make sure we are where we think we are
  2049. hr = S_FALSE;
  2050. }
  2051. if ( S_OK == hr ) {
  2052. if ( NULL == m_ipCompData ) {
  2053. hr = S_FALSE;
  2054. } else {
  2055. mmcCookie = (MMC_COOKIE)pDO->GetCookie();
  2056. bIsQuery = m_ipCompData->IsLogQuery (mmcCookie);
  2057. if (!bIsQuery) {
  2058. // Pass the notification to the scope pane to expand.
  2059. hr = S_FALSE;
  2060. } else {
  2061. pQuery = (PSLQUERY)mmcCookie;
  2062. if ( NULL != pQuery ) {
  2063. // If the property sheet for this query is already active, just bring it to the foreground.
  2064. pPropSheet = pQuery->GetActivePropertySheet();
  2065. if ( NULL != pPropSheet ) {
  2066. pPropSheet->SetForegroundWindow();
  2067. MMCFreeNotifyHandle(handle);
  2068. hr = S_OK;
  2069. } else {
  2070. hr = _InvokePropertySheet(ulRecNo, pDataObject);
  2071. }
  2072. } else {
  2073. ASSERT ( FALSE );
  2074. hr = E_UNEXPECTED;
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. return hr;
  2082. } // end OnDoubleClick()
  2083. HRESULT
  2084. CComponent::StartLogQuery (
  2085. LPDATAOBJECT pDataObject ) // [in] Points to the data object
  2086. {
  2087. HRESULT hr = S_OK;
  2088. CDataObject* pDO = NULL;
  2089. CSmLogQuery* pQuery = NULL;
  2090. CString strMessage;
  2091. CString strSysMessage;
  2092. CString strTitle;
  2093. CString strMachineName;
  2094. int iResult;
  2095. DWORD dwStatus = ERROR_SUCCESS;
  2096. ResourceStateManager rsm;
  2097. ASSERT( NULL != m_ipCompData );
  2098. if ( NULL == pDataObject ) {
  2099. ASSERT ( FALSE );
  2100. hr = E_POINTER;
  2101. } else {
  2102. pDO = ExtractOwnDataObject(pDataObject);
  2103. if ( NULL == pDO ) {
  2104. ASSERT ( FALSE );
  2105. hr = E_UNEXPECTED;
  2106. }
  2107. }
  2108. if ( NULL == m_ipCompData
  2109. || NULL == m_ipConsole ) {
  2110. hr = E_FAIL;
  2111. }
  2112. if ( SUCCEEDED ( hr ) ) {
  2113. if ( m_ipCompData->IsLogQuery ( pDO->GetCookie() ) ) {
  2114. pQuery = (CSmLogQuery*)pDO->GetCookie();
  2115. if ( NULL != pQuery ) {
  2116. if ( NULL != pQuery->GetActivePropertySheet() ) {
  2117. // Don't start queries with open property pages.
  2118. strMessage.LoadString ( IDS_ERRMSG_START_OPEN_QUERY );
  2119. hr = m_ipConsole->MessageBox(
  2120. (LPCWSTR)strMessage,
  2121. pQuery->GetLogName(),
  2122. MB_OK | MB_ICONWARNING,
  2123. &iResult );
  2124. ((CWnd*)pQuery->GetActivePropertySheet())->SetForegroundWindow();
  2125. hr = S_FALSE;
  2126. } else {
  2127. {
  2128. CWaitCursor WaitCursor;
  2129. dwStatus = pQuery->ManualStart();
  2130. }
  2131. // Ignore errors related to autostart setting.
  2132. if ( ERROR_SUCCESS == dwStatus ) {
  2133. // Update all views generates view change notification.
  2134. m_ipConsole->UpdateAllViews (pDO, 0, CComponentData::eSmHintStartQuery );
  2135. } else {
  2136. strTitle.LoadString ( IDS_PROJNAME );
  2137. if ( ERROR_ACCESS_DENIED == dwStatus ) {
  2138. pQuery->GetMachineDisplayName ( strMachineName );
  2139. FormatSmLogCfgMessage (
  2140. strMessage,
  2141. m_hModule,
  2142. SMCFG_NO_MODIFY_ACCESS,
  2143. (LPCWSTR)strMachineName);
  2144. } else if ( SMCFG_START_TIMED_OUT == dwStatus ) {
  2145. FormatSmLogCfgMessage (
  2146. strMessage,
  2147. m_hModule,
  2148. SMCFG_START_TIMED_OUT,
  2149. (LPCWSTR)pQuery->GetLogName());
  2150. } else {
  2151. FormatSmLogCfgMessage (
  2152. strMessage,
  2153. m_hModule,
  2154. SMCFG_SYSTEM_MESSAGE,
  2155. (LPCWSTR)pQuery->GetLogName());
  2156. FormatMessage (
  2157. FORMAT_MESSAGE_FROM_SYSTEM,
  2158. NULL,
  2159. dwStatus,
  2160. 0,
  2161. strSysMessage.GetBufferSetLength( MAX_PATH ),
  2162. MAX_PATH,
  2163. NULL );
  2164. strSysMessage.ReleaseBuffer();
  2165. if ( strSysMessage.IsEmpty() ) {
  2166. strSysMessage.Format ( L"0x%08lX", dwStatus );
  2167. }
  2168. strMessage += strSysMessage;
  2169. }
  2170. hr = m_ipConsole->MessageBox(
  2171. strMessage,
  2172. strTitle,
  2173. MB_OK | MB_ICONERROR,
  2174. &iResult );
  2175. hr = E_FAIL;
  2176. }
  2177. }
  2178. } else {
  2179. ASSERT ( FALSE );
  2180. hr = E_UNEXPECTED;
  2181. }
  2182. }
  2183. }
  2184. return hr;
  2185. } // end StartLogQuery()
  2186. HRESULT
  2187. CComponent::StopLogQuery (
  2188. LPDATAOBJECT pDataObject, // [in] Points to the data object
  2189. BOOL bWarnOnRestartCancel )
  2190. {
  2191. HRESULT hr = S_OK;
  2192. CDataObject* pDO = NULL;
  2193. CSmLogQuery* pQuery = NULL;
  2194. DWORD dwStatus = ERROR_SUCCESS;
  2195. INT iResult = IDOK;
  2196. CString strMessage;
  2197. CString strSysMessage;
  2198. CString strTitle;
  2199. CString strMachineName;
  2200. ResourceStateManager rsm;
  2201. ASSERT( NULL != m_ipCompData );
  2202. if ( NULL == pDataObject ) {
  2203. ASSERT ( FALSE );
  2204. hr = E_POINTER;
  2205. } else {
  2206. pDO = ExtractOwnDataObject(pDataObject);
  2207. if ( NULL == pDO ) {
  2208. ASSERT ( FALSE );
  2209. hr = E_UNEXPECTED;
  2210. }
  2211. }
  2212. if ( NULL == m_ipCompData
  2213. || NULL == m_ipConsole ) {
  2214. hr = E_FAIL;
  2215. }
  2216. if ( SUCCEEDED ( hr ) ) {
  2217. if ( m_ipCompData->IsLogQuery ( pDO->GetCookie() ) ) {
  2218. pQuery = (CSmLogQuery*)pDO->GetCookie();
  2219. if ( NULL != pQuery ) {
  2220. if ( NULL != pQuery->GetActivePropertySheet() ) {
  2221. // Don't stop queries with open property pages.
  2222. strMessage.LoadString ( IDS_ERRMSG_STOP_OPEN_QUERY );
  2223. hr = m_ipConsole->MessageBox(
  2224. (LPCWSTR)strMessage,
  2225. pQuery->GetLogName(),
  2226. MB_OK | MB_ICONWARNING,
  2227. &iResult );
  2228. ((CWnd*)pQuery->GetActivePropertySheet())->SetForegroundWindow();
  2229. hr = S_FALSE;
  2230. } else {
  2231. if ( pQuery->IsAutoRestart() && bWarnOnRestartCancel ) {
  2232. CString strMessage;
  2233. strMessage.LoadString( IDS_CANCEL_AUTO_RESTART );
  2234. hr = m_ipConsole->MessageBox(
  2235. strMessage,
  2236. pQuery->GetLogName(),
  2237. MB_OKCANCEL | MB_ICONINFORMATION,
  2238. &iResult );
  2239. }
  2240. if ( IDOK == iResult ) {
  2241. {
  2242. CWaitCursor WaitCursor;
  2243. dwStatus = pQuery->ManualStop ();
  2244. }
  2245. // Ignore errors related to autostart setting.
  2246. if ( ERROR_SUCCESS == dwStatus ) {
  2247. // Update all views generates view change notification.
  2248. m_ipConsole->UpdateAllViews (pDO, 0, CComponentData::eSmHintStopQuery );
  2249. } else {
  2250. strTitle.LoadString ( IDS_PROJNAME );
  2251. if ( ERROR_ACCESS_DENIED == dwStatus ) {
  2252. pQuery->GetMachineDisplayName ( strMachineName );
  2253. FormatSmLogCfgMessage (
  2254. strMessage,
  2255. m_hModule,
  2256. SMCFG_NO_MODIFY_ACCESS,
  2257. (LPCWSTR)strMachineName);
  2258. } else if ( SMCFG_STOP_TIMED_OUT == dwStatus ) {
  2259. FormatSmLogCfgMessage (
  2260. strMessage,
  2261. m_hModule,
  2262. SMCFG_STOP_TIMED_OUT,
  2263. (LPCWSTR)pQuery->GetLogName());
  2264. } else {
  2265. FormatSmLogCfgMessage (
  2266. strMessage,
  2267. m_hModule,
  2268. SMCFG_SYSTEM_MESSAGE,
  2269. (LPCWSTR)pQuery->GetLogName());
  2270. FormatMessage (
  2271. FORMAT_MESSAGE_FROM_SYSTEM,
  2272. NULL,
  2273. dwStatus,
  2274. 0,
  2275. strSysMessage.GetBufferSetLength( MAX_PATH ),
  2276. MAX_PATH,
  2277. NULL );
  2278. strSysMessage.ReleaseBuffer();
  2279. if ( strSysMessage.IsEmpty() ) {
  2280. strSysMessage.Format ( L"0x%08lX", dwStatus );
  2281. }
  2282. strMessage += strSysMessage;
  2283. }
  2284. hr = m_ipConsole->MessageBox(
  2285. strMessage,
  2286. strTitle,
  2287. MB_OK | MB_ICONERROR,
  2288. &iResult );
  2289. hr = E_FAIL;
  2290. }
  2291. }
  2292. }
  2293. } else {
  2294. ASSERT ( FALSE );
  2295. hr = E_UNEXPECTED;
  2296. }
  2297. }
  2298. }
  2299. return hr;
  2300. } // end StopLogQuery()
  2301. HRESULT
  2302. CComponent::SaveLogQueryAs (
  2303. LPDATAOBJECT pDataObject ) // [in] Points to the data object
  2304. {
  2305. HRESULT hr = S_OK;
  2306. DWORD dwStatus = ERROR_SUCCESS;
  2307. CDataObject* pDO = NULL;
  2308. CSmLogQuery* pQuery = NULL;
  2309. CString strFileExtension;
  2310. CString strFileFilter;
  2311. WCHAR szDefaultFileName[MAX_PATH + 1];
  2312. INT_PTR iPtrResult = IDCANCEL;
  2313. HWND hwndMain;
  2314. WCHAR szInitialDir[MAX_PATH + 1];
  2315. ResourceStateManager rsm;
  2316. ASSERT( NULL != m_ipCompData );
  2317. if ( NULL == pDataObject ) {
  2318. ASSERT ( FALSE );
  2319. hr = E_POINTER;
  2320. } else {
  2321. pDO = ExtractOwnDataObject(pDataObject);
  2322. if ( NULL == pDO ) {
  2323. ASSERT ( FALSE );
  2324. hr = E_UNEXPECTED;
  2325. }
  2326. }
  2327. if ( NULL == m_ipCompData
  2328. || NULL == m_ipConsole ) {
  2329. hr = E_FAIL;
  2330. }
  2331. if ( SUCCEEDED ( hr ) ) {
  2332. if ( m_ipCompData->IsLogQuery ( pDO->GetCookie() ) ) {
  2333. pQuery = (CSmLogQuery*)pDO->GetCookie();
  2334. if ( NULL != pQuery ) {
  2335. MFC_TRY
  2336. strFileExtension.LoadString ( IDS_HTML_EXTENSION );
  2337. strFileFilter.LoadString ( IDS_HTML_FILE );
  2338. MFC_CATCH_HR
  2339. strFileFilter.Replace ( L'|', L'\0' );
  2340. StringCchCopy ( szDefaultFileName, MAX_PATH + 1, pQuery->GetLogName() );
  2341. ReplaceBlanksWithUnderscores( szDefaultFileName );
  2342. hr = m_ipConsole->GetMainWindow( &hwndMain );
  2343. if ( SUCCEEDED(hr) ) {
  2344. OPENFILENAME ofn;
  2345. BOOL bResult;
  2346. ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
  2347. ofn.lStructSize = sizeof(OPENFILENAME);
  2348. ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  2349. ofn.lpstrDefExt = (LPCWSTR)strFileExtension;
  2350. ofn.lpstrFile = szDefaultFileName;
  2351. ofn.lpstrFilter = strFileFilter;
  2352. ofn.nMaxFile = MAX_PATH;
  2353. ofn.hwndOwner = hwndMain;
  2354. ofn.hInstance = m_hModule;
  2355. if ( SUCCEEDED ( SHGetFolderPathW ( NULL, CSIDL_PERSONAL, NULL, 0, szInitialDir ) ) ) {
  2356. ofn.lpstrInitialDir = szInitialDir;
  2357. }
  2358. bResult = GetSaveFileName( &ofn );
  2359. if ( bResult ) {
  2360. dwStatus = pQuery->SaveAs( ofn.lpstrFile );
  2361. if ( ERROR_SUCCESS != dwStatus ) {
  2362. hr = E_FAIL;
  2363. }
  2364. }
  2365. }
  2366. } else {
  2367. ASSERT ( FALSE );
  2368. hr = E_UNEXPECTED;
  2369. }
  2370. }
  2371. }
  2372. return hr;
  2373. } // end SaveLogQueryAs()
  2374. //+--------------------------------------------------------------------------
  2375. //
  2376. // Member: CComponent::_InvokePropertySheet
  2377. //
  2378. // Synopsis: Open or bring to foreground an event record details
  2379. // property sheet focused on record [ulRecNo].
  2380. //
  2381. // Arguments: [ulRecNo] - number of rec to display in prop sheet
  2382. // [pDataObject] - data object containing rec [ulRecNo]
  2383. //
  2384. // Returns: HRESULT
  2385. //
  2386. // History: 5-28-1999 a-akamal
  2387. //
  2388. //---------------------------------------------------------------------------
  2389. HRESULT
  2390. CComponent::_InvokePropertySheet(
  2391. ULONG ulRecNo,
  2392. LPDATAOBJECT pDataObject)
  2393. {
  2394. //TRACE_METHOD(CComponent, _InvokePropertySheet);
  2395. HRESULT hr = S_OK;
  2396. MMC_COOKIE Cookie;
  2397. PSLQUERY pQuery = NULL;
  2398. CDataObject* pDO = NULL;
  2399. ASSERT( NULL != m_ipCompData );
  2400. if ( NULL == pDataObject ) {
  2401. ASSERT ( FALSE );
  2402. hr = E_POINTER;
  2403. } else {
  2404. pDO = ExtractOwnDataObject(pDataObject);
  2405. if ( NULL == pDO ) {
  2406. ASSERT ( FALSE );
  2407. hr = E_UNEXPECTED;
  2408. }
  2409. }
  2410. if ( SUCCEEDED ( hr ) ) {
  2411. Cookie = (MMC_COOKIE)pDO->GetCookie();;
  2412. pQuery = (PSLQUERY)Cookie;
  2413. if ( NULL != pQuery && NULL != m_ipCompData )
  2414. {
  2415. hr = InvokePropertySheet (
  2416. m_ipCompData->GetPropSheetProvider(),
  2417. (LPCWSTR)pQuery->GetLogName(),
  2418. (LONG) ulRecNo,
  2419. pDataObject,
  2420. (IExtendPropertySheet*) this,
  2421. 0 );
  2422. } else {
  2423. ASSERT ( FALSE );
  2424. hr = E_UNEXPECTED;
  2425. }
  2426. }
  2427. return hr;
  2428. }
  2429. //+--------------------------------------------------------------------------
  2430. //
  2431. // Function: InvokePropertySheet
  2432. //
  2433. // Synopsis: Bring to top an existing or create a new property sheet
  2434. // using the parameters provided.
  2435. //
  2436. // Arguments: [pPrshtProvider] - used to search for or create sheet
  2437. // [wszTitle] - sheet caption
  2438. // [lCookie] - a loginfo* or an event record number
  2439. // [pDataObject] - DO on object sheet's being opened on
  2440. // (cookie in DO should == cookie)
  2441. // [pPrimary] - IExtendPropertySheet interface on
  2442. // calling CSnapin or CComponentData
  2443. // [usStartingPage] - which page number should be active when
  2444. // sheet opens
  2445. //
  2446. // Returns: HRESULT
  2447. //
  2448. // History: 5-28-1999 a-akamal
  2449. //
  2450. // Notes: Call this routine when you want a property sheet to appear
  2451. // as if the user had just selected "Properties" on it.
  2452. //
  2453. //---------------------------------------------------------------------------
  2454. HRESULT
  2455. CComponent::
  2456. InvokePropertySheet(
  2457. IPropertySheetProvider *pPrshtProvider,
  2458. LPCWSTR wszTitle,
  2459. LONG lCookie,
  2460. LPDATAOBJECT pDataObject,
  2461. IExtendPropertySheet *pPrimary,
  2462. USHORT usStartingPage)
  2463. {
  2464. HRESULT hr = S_OK;
  2465. //
  2466. // Because we pass NULL for the second arg, the first is not allowed
  2467. // to be null.
  2468. //
  2469. if ( 0 == lCookie ) {
  2470. ASSERT ( FALSE );
  2471. hr = E_INVALIDARG;
  2472. } else {
  2473. do {
  2474. hr = pPrshtProvider->FindPropertySheet(lCookie, NULL, pDataObject);
  2475. if ( S_OK == hr ) {
  2476. break;
  2477. }
  2478. hr = pPrshtProvider->CreatePropertySheet(wszTitle,
  2479. TRUE,
  2480. lCookie,
  2481. pDataObject,
  2482. 0);
  2483. if ( S_OK != hr ) {
  2484. break;
  2485. }
  2486. hr = pPrshtProvider->AddPrimaryPages(pPrimary, TRUE, NULL, FALSE);
  2487. if ( S_OK != hr ) {
  2488. break;
  2489. }
  2490. hr = pPrshtProvider->Show(NULL, usStartingPage);
  2491. } while (0);
  2492. }
  2493. return hr;
  2494. }