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.

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