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.

1023 lines
27 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: TextResCtrl.cpp
  4. //
  5. // Synopsis: This file holds the implementation of the
  6. // of CTextResCtrl class
  7. //
  8. // History: 01/15/2001 serdarun Created
  9. //
  10. // Copyright (C) 2000-2001 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //#--------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "Localuiresource.h"
  16. #include "TextResCtrl.h"
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CTextResCtrl
  19. //
  20. // currently supports at most 3 resources due LCD size
  21. //
  22. #define MAX_RESOURCE_COUNT 3
  23. const WCHAR ELEMENT_RETRIEVER [] = L"Elementmgr.ElementRetriever";
  24. const WCHAR LOCALIZATION_MANAGER [] = L"ServerAppliance.LocalizationManager";
  25. const WCHAR RESOURCE_CONTAINER [] = L"LocalUIResource";
  26. //
  27. // localui resource definition properties
  28. //
  29. const WCHAR CAPTION_PROPERTY [] = L"CaptionRID";
  30. const WCHAR SOURCE_PROPERTY [] = L"Source";
  31. const WCHAR RESOURCENAME_PROPERTY [] = L"ResourceName";
  32. const WCHAR MERIT_PROPERTY [] = L"Merit";
  33. const WCHAR STATE_PROPERTY [] = L"State";
  34. const WCHAR TEXTRESOURCE_PROPERTY [] = L"IsTextResource";
  35. const WCHAR UNIQUE_NAME [] = L"UniqueName";
  36. const WCHAR DISPLAY_INFORMATION [] = L"DisplayInformationID";
  37. //++--------------------------------------------------------------
  38. //
  39. // Function: AddTextResource
  40. //
  41. // Synopsis: This is the CTextResCtrl method to retrieve
  42. // each resource information
  43. //
  44. // Arguments: IWebElement * pElement
  45. //
  46. // Returns: HRESULT - success/failure
  47. //
  48. // History: serdarun Created 01/01/2001
  49. //
  50. //----------------------------------------------------------------
  51. STDMETHODIMP CTextResCtrl::AddTextResource(IWebElement * pElement)
  52. {
  53. HRESULT hr;
  54. USES_CONVERSION;
  55. CComVariant varUniqueName;
  56. wstring wsUniqueName;
  57. wstring wsTextKey;
  58. DWORD dwMerit;
  59. CComBSTR bstrResourceName = CComBSTR(RESOURCENAME_PROPERTY);
  60. CComBSTR bstrSourceProp = CComBSTR(SOURCE_PROPERTY);
  61. CComBSTR bstrMeritProp = CComBSTR(MERIT_PROPERTY);
  62. CComBSTR bstrCaptionProp = CComBSTR(CAPTION_PROPERTY);
  63. if ( (bstrResourceName.m_str == NULL) ||
  64. (bstrSourceProp.m_str == NULL) ||
  65. (bstrMeritProp.m_str == NULL) ||
  66. (bstrCaptionProp.m_str == NULL) )
  67. {
  68. SATraceString(" CTextResCtrl::AddTextResource failed on memory allocation ");
  69. return E_OUTOFMEMORY;
  70. }
  71. ResourceStructPtr pResourceStruct = NULL;
  72. //
  73. // get the unique name for the resource
  74. //
  75. hr = pElement->GetProperty (bstrResourceName, &varUniqueName);
  76. if (FAILED(hr))
  77. {
  78. SATraceString ("CTextResCtrl::AddTextResource failed on getting uniquename");
  79. return hr;
  80. }
  81. //
  82. // store the unique name for later use
  83. //
  84. wsUniqueName = V_BSTR (&varUniqueName);
  85. //
  86. // get the resource dll for the resource
  87. //
  88. CComVariant varSource;
  89. hr = pElement->GetProperty (bstrSourceProp, &varSource);
  90. if (FAILED(hr))
  91. {
  92. SATraceString ("CTextResCtrl::AddTextResource failed on getting resource dll");
  93. return hr;
  94. }
  95. //
  96. // allocate a new struct for the resource
  97. //
  98. pResourceStruct = new ResourceStruct;
  99. if (NULL == pResourceStruct)
  100. {
  101. return E_OUTOFMEMORY;
  102. }
  103. //
  104. // set default values
  105. //
  106. pResourceStruct->lState = 0;
  107. //
  108. // get the merit for resource
  109. //
  110. CComVariant varResMerit;
  111. hr = pElement->GetProperty (bstrMeritProp, &varResMerit);
  112. if (FAILED(hr))
  113. {
  114. SATraceString ("CTextResCtrl::AddTextResource failed on getting merit");
  115. return hr;
  116. }
  117. dwMerit = V_I4 (&varResMerit);
  118. //
  119. // get the default icon resource id
  120. //
  121. CComVariant varResText;
  122. hr = pElement->GetProperty (bstrCaptionProp, &varResText);
  123. if (FAILED(hr))
  124. {
  125. SATraceString ("CTextResCtrl::AddTextResource failed on getting captionrid");
  126. return hr;
  127. }
  128. int iCount = 0;
  129. //
  130. // while there are state texts
  131. //
  132. while (SUCCEEDED(hr))
  133. {
  134. CComBSTR pszValue;
  135. CComVariant varReplacementString;
  136. hr = m_pSALocInfo->GetString(
  137. V_BSTR (&varSource),
  138. HexStringToULong(wstring(V_BSTR (&varResText))),
  139. &varReplacementString,
  140. &pszValue
  141. );
  142. if (FAILED(hr))
  143. {
  144. SATracePrintf ("CTextResCtrl::AddTextResource, Loading the text failed, %x :",hr);
  145. break;
  146. }
  147. //
  148. // insert the icon to state-icon map
  149. //
  150. (pResourceStruct->mapResText).insert(ResourceTextMap::value_type(iCount,wstring(pszValue.m_str)));
  151. //
  152. // create statekey, state0, state1...
  153. //
  154. iCount++;
  155. WCHAR wstrCount[10];
  156. _itow(iCount,wstrCount,10);
  157. wsTextKey = L"State";
  158. wsTextKey.append(wstring(wstrCount));
  159. varResText.Clear();
  160. CComBSTR bstrTextKey = CComBSTR(wsTextKey.c_str());
  161. if (bstrTextKey.m_str == NULL)
  162. {
  163. SATraceString(" CTextResCtrl::AddTextResource failed on memory allocation ");
  164. return E_OUTOFMEMORY;
  165. }
  166. //
  167. // get the resource id for state icon
  168. //
  169. hr = pElement->GetProperty (bstrTextKey, &varResText);
  170. if (FAILED(hr))
  171. {
  172. break;
  173. }
  174. }
  175. //
  176. // increment the number of resources
  177. //
  178. m_lResourceCount++;
  179. //
  180. // insert the info to the resource map
  181. //
  182. m_ResourceMap.insert(ResourceMap::value_type(wsUniqueName,pResourceStruct));
  183. //
  184. // insert merit and resource name to merit map
  185. //
  186. m_MeritMap.insert(MeritMap::value_type(dwMerit,wsUniqueName));
  187. return S_OK;
  188. }// end of CTextResCtrl::AddTextResource
  189. //++--------------------------------------------------------------
  190. //
  191. // Function: GetLocalUIResources
  192. //
  193. // Synopsis: This is the CTextResCtrl method to retrieve
  194. // each resource from element manager
  195. //
  196. // Arguments: none
  197. //
  198. // Returns: HRESULT - success/failure
  199. //
  200. // History: serdarun Created 01/01/2001
  201. //
  202. //----------------------------------------------------------------
  203. STDMETHODIMP CTextResCtrl::GetLocalUIResources()
  204. {
  205. HRESULT hr;
  206. CLSID clsid;
  207. CComPtr<IWebElementRetriever> pWebElementRetriever = NULL;
  208. CComPtr<IDispatch> pDispatch = NULL;
  209. CComPtr<IWebElementEnum> pWebElementEnum = NULL;
  210. CComPtr<IUnknown> pUnknown = NULL;
  211. CComPtr<IEnumVARIANT> pEnumVariant = NULL;
  212. CComVariant varElement;
  213. DWORD dwElementsLeft = 0;
  214. CComBSTR bstrTextResource = CComBSTR(TEXTRESOURCE_PROPERTY);
  215. CComBSTR bstrResourceContainer = CComBSTR(RESOURCE_CONTAINER);
  216. if ( (bstrTextResource.m_str == NULL) ||
  217. (bstrResourceContainer.m_str == NULL) )
  218. {
  219. SATraceString(" CTextResCtrl::GetLocalUIResources failed on memory allocation ");
  220. return E_OUTOFMEMORY;
  221. }
  222. //
  223. // get the CLSID for Element manager
  224. //
  225. hr = ::CLSIDFromProgID (ELEMENT_RETRIEVER,&clsid);
  226. if (FAILED (hr))
  227. {
  228. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on CLSIDFromProgID:%x",hr);
  229. return hr;
  230. }
  231. //
  232. // create the Element Retriever now
  233. //
  234. hr = ::CoCreateInstance (
  235. clsid,
  236. NULL,
  237. CLSCTX_LOCAL_SERVER,
  238. IID_IWebElementRetriever,
  239. (PVOID*) &pWebElementRetriever
  240. );
  241. if (FAILED (hr))
  242. {
  243. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on CoCreateInstance:%x",hr);
  244. return hr;
  245. }
  246. //
  247. // get the CLSID localization manager
  248. //
  249. hr = ::CLSIDFromProgID (
  250. LOCALIZATION_MANAGER,
  251. &clsid
  252. );
  253. if (FAILED (hr))
  254. {
  255. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on CLSIDFromProgID:%x",hr);
  256. return hr;
  257. }
  258. //
  259. // create the Localization Manager COM object
  260. //
  261. hr = ::CoCreateInstance (
  262. clsid,
  263. NULL,
  264. CLSCTX_INPROC_SERVER,
  265. __uuidof (ISALocInfo),
  266. (PVOID*) &m_pSALocInfo
  267. );
  268. if (FAILED (hr))
  269. {
  270. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on CoCreateInstance:%x",hr);
  271. return hr;
  272. }
  273. //
  274. // get localui resource elements
  275. //
  276. hr = pWebElementRetriever->GetElements (
  277. 1,
  278. bstrResourceContainer,
  279. &pDispatch
  280. );
  281. if (FAILED (hr))
  282. {
  283. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on GetElements:%x",hr);
  284. return hr;
  285. }
  286. //
  287. // get the enum variant
  288. //
  289. hr = pDispatch->QueryInterface (
  290. IID_IWebElementEnum,
  291. (LPVOID*) (&pWebElementEnum)
  292. );
  293. if (FAILED (hr))
  294. {
  295. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on QueryInterface:%x",hr);
  296. return hr;
  297. }
  298. m_lResourceCount = 0;
  299. //
  300. // get number of resource elements
  301. //
  302. hr = pWebElementEnum->get_Count (&m_lResourceCount);
  303. if (FAILED (hr))
  304. {
  305. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on get_Count:%x",hr);
  306. return hr;
  307. }
  308. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on QueryInterface:%d",m_lResourceCount);
  309. //
  310. // no resources, just return
  311. //
  312. if (0 == m_lResourceCount)
  313. {
  314. return S_FALSE;
  315. }
  316. hr = pWebElementEnum->get__NewEnum (&pUnknown);
  317. if (FAILED (hr))
  318. {
  319. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on get__NewEnum:%x",hr);
  320. return hr;
  321. }
  322. //
  323. // get the enum variant
  324. //
  325. hr = pUnknown->QueryInterface (
  326. IID_IEnumVARIANT,
  327. (LPVOID*)(&pEnumVariant)
  328. );
  329. if (FAILED (hr))
  330. {
  331. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on QueryInterface:%x",hr);
  332. return hr;
  333. }
  334. //
  335. // get elements out of the collection and initialize
  336. //
  337. hr = pEnumVariant->Next (1, &varElement, &dwElementsLeft);
  338. if (FAILED (hr))
  339. {
  340. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on Next:%x",hr);
  341. }
  342. m_lResourceCount = 0;
  343. //
  344. // for each resource
  345. //
  346. while ((dwElementsLeft> 0) && (SUCCEEDED (hr)) && (m_lResourceCount < MAX_RESOURCE_COUNT))
  347. {
  348. //
  349. // get the IWebElement Interface
  350. //
  351. CComPtr <IWebElement> pElement;
  352. hr = varElement.pdispVal->QueryInterface (
  353. __uuidof (IWebElement),
  354. (LPVOID*)(&pElement)
  355. );
  356. if (FAILED (hr))
  357. {
  358. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on QueryInterface:%x",hr);
  359. }
  360. //
  361. // check if it is a text resource
  362. //
  363. CComVariant varIsTextResource;
  364. hr = pElement->GetProperty (bstrTextResource, &varIsTextResource);
  365. if (SUCCEEDED(hr))
  366. {
  367. if (0 != V_I4(&varIsTextResource))
  368. {
  369. AddTextResource(pElement);
  370. }
  371. }
  372. //
  373. // clear the perClient value from this variant
  374. //
  375. varElement.Clear ();
  376. varIsTextResource.Clear();
  377. //
  378. // get next client out of the collection
  379. //
  380. hr = pEnumVariant->Next (1, &varElement, &dwElementsLeft);
  381. if (FAILED (hr))
  382. {
  383. SATracePrintf ("CTextResCtrl::GetLocalUIResources failed on Next:%x",hr);
  384. }
  385. }
  386. return S_OK;
  387. } // end of CTextResCtrl::GetLocalUIResources
  388. //++--------------------------------------------------------------
  389. //
  390. // Function: InitializeWbemSink
  391. //
  392. // Synopsis: This is the CTextResCtrl method to initialize the
  393. // component
  394. //
  395. // Arguments: none
  396. //
  397. // Returns: HRESULT - success/failure
  398. //
  399. // History: serdarun Created 01/01/2001
  400. //
  401. //----------------------------------------------------------------
  402. STDMETHODIMP CTextResCtrl::InitializeWbemSink(void)
  403. {
  404. CComPtr <IWbemLocator> pWbemLocator;
  405. CComBSTR strNetworkRes = CComBSTR(_T("\\\\.\\ROOT\\CIMV2"));
  406. CComBSTR strQueryLang = CComBSTR(_T("WQL"));
  407. CComBSTR strQueryString = CComBSTR(_T("select * from Microsoft_SA_ResourceEvent"));
  408. if ( (strNetworkRes.m_str == NULL) ||
  409. (strQueryLang.m_str == NULL) ||
  410. (strQueryString.m_str == NULL) )
  411. {
  412. SATraceString(" CTextResCtrl::InitializeWbemSink failed on memory allocation ");
  413. return E_OUTOFMEMORY;
  414. }
  415. //
  416. // create the WBEM locator object
  417. //
  418. HRESULT hr = ::CoCreateInstance (
  419. __uuidof (WbemLocator),
  420. 0, //aggregation pointer
  421. CLSCTX_INPROC_SERVER,
  422. __uuidof (IWbemLocator),
  423. (PVOID*) &pWbemLocator
  424. );
  425. if (SUCCEEDED (hr) && (pWbemLocator.p))
  426. {
  427. //
  428. // connect to WMI
  429. //
  430. hr = pWbemLocator->ConnectServer (
  431. strNetworkRes,
  432. NULL, //user-name
  433. NULL, //password
  434. NULL, //current-locale
  435. 0, //reserved
  436. NULL, //authority
  437. NULL, //context
  438. &m_pWbemServices
  439. );
  440. if (SUCCEEDED (hr))
  441. {
  442. //
  443. // set up the consumer object as the event sync
  444. // for the object type we are interested in
  445. //
  446. hr = m_pWbemServices->ExecNotificationQueryAsync (
  447. strQueryLang,
  448. strQueryString,
  449. 0, //no-status
  450. NULL, //status
  451. (IWbemObjectSink*)(this)
  452. );
  453. if (FAILED (hr))
  454. {
  455. SATracePrintf ("CTextResCtrl::InitializeWbemSink failed on ExecNotificationQueryAsync:%x",hr);
  456. }
  457. }
  458. else
  459. {
  460. SATracePrintf ("CTextResCtrl::InitializeWbemSink failed on ConnectServer:%x",hr);
  461. }
  462. }
  463. else
  464. {
  465. SATracePrintf ("CTextResCtrl::InitializeWbemSink failed on CoCreateInstance:%x",hr);
  466. }
  467. return (hr);
  468. } // end of CTextResCtrl::InitializeWbemSink method
  469. //++--------------------------------------------------------------
  470. //
  471. // Function: FinalConstruct
  472. //
  473. // Synopsis: This is the CTextResCtrl method to initialize the
  474. // component
  475. //
  476. // Arguments: none
  477. //
  478. // Returns: HRESULT - success/failure
  479. //
  480. // History: serdarun Created 01/01/2001
  481. //
  482. //----------------------------------------------------------------
  483. STDMETHODIMP CTextResCtrl::FinalConstruct()
  484. {
  485. HRESULT hr;
  486. //
  487. // initialize the variables
  488. //
  489. m_ResourceMap.clear();
  490. m_MeritMap.clear();
  491. m_lResourceCount = 0;
  492. m_pWbemServices = NULL;
  493. m_pSALocInfo = NULL;
  494. //
  495. // get the local resources
  496. //
  497. hr = GetLocalUIResources();
  498. if (FAILED(hr))
  499. {
  500. SATracePrintf ("CTextResCtrl::FinalConstruct failed on GetLocalUIResources:%x",hr);
  501. }
  502. //
  503. // register in the wbem sink, if we have any resources
  504. //
  505. if (m_lResourceCount > 0)
  506. {
  507. hr = InitializeWbemSink();
  508. if (FAILED(hr))
  509. {
  510. SATracePrintf ("CTextResCtrl::FinalConstruct failed on InitializeWbemSink:%x",hr);
  511. //
  512. // returning failure cause component to be destroyed
  513. //
  514. return S_OK;
  515. }
  516. }
  517. return S_OK;
  518. } // end of CTextResCtrl::FinalConstruct method
  519. //++--------------------------------------------------------------
  520. //
  521. // Function: FinalRelease
  522. //
  523. // Synopsis: This is the CTextResCtrl method to release the
  524. // resources
  525. //
  526. // Arguments: none
  527. //
  528. // Returns: HRESULT - success/failure
  529. //
  530. // History: serdarun Created 01/01/2001
  531. //
  532. //----------------------------------------------------------------
  533. STDMETHODIMP CTextResCtrl::FinalRelease()
  534. {
  535. HRESULT hr;
  536. //
  537. // cancel the call for wmi resource events
  538. //
  539. if (m_pWbemServices)
  540. {
  541. hr = m_pWbemServices->CancelAsyncCall ((IWbemObjectSink*)(this));
  542. if (FAILED (hr))
  543. {
  544. SATracePrintf ("CTextResCtrl::FinalRelease failed on-CancelAsyncCall failed with error:%x:",hr);
  545. }
  546. }
  547. m_pWbemServices = NULL;
  548. m_pSALocInfo = NULL;
  549. ResourceStructPtr ptrResourceStruct = NULL;
  550. ResourceMapIterator itrResourceMap = m_ResourceMap.begin();
  551. //
  552. // for each resource element
  553. //
  554. while (itrResourceMap != m_ResourceMap.end())
  555. {
  556. ptrResourceStruct = NULL;
  557. //
  558. // get resource information struct
  559. //
  560. ptrResourceStruct = (*itrResourceMap).second;
  561. //
  562. // delete the text map
  563. //
  564. (ptrResourceStruct->mapResText).clear();
  565. itrResourceMap++;
  566. }
  567. m_ResourceMap.clear();
  568. return S_OK;
  569. } // end of CTextResCtrl::FinalRelease method
  570. //++--------------------------------------------------------------
  571. //
  572. // Function: Indicate
  573. //
  574. // Synopsis: This is the IWbemObjectSink interface method
  575. // through which WBEM calls back to provide the
  576. // event objects
  577. //
  578. // Arguments:
  579. // [in] LONG - number of events
  580. // [in] IWbemClassObject** - array of events
  581. //
  582. // Returns: HRESULT - success/failure
  583. //
  584. // History: serdarun Created 12/10/2000
  585. //
  586. // Called By: WBEM
  587. //
  588. //----------------------------------------------------------------
  589. STDMETHODIMP CTextResCtrl::Indicate (
  590. /*[in]*/ LONG lObjectCount,
  591. /*[in]*/ IWbemClassObject **ppObjArray
  592. )
  593. {
  594. wstring wsUniqueName = L"";
  595. BOOL bDirty = FALSE;
  596. ResourceMapIterator itrResourceMap = NULL;
  597. CComBSTR bstrUniqueName = CComBSTR(UNIQUE_NAME);
  598. CComBSTR bstrDisplayInfo = CComBSTR(DISPLAY_INFORMATION);
  599. if ( (bstrUniqueName.m_str == NULL) ||
  600. (bstrDisplayInfo.m_str == NULL) )
  601. {
  602. SATraceString(" CTextResCtrl::Indicate failed on memory allocation ");
  603. return WBEM_NO_ERROR;
  604. }
  605. // Get the info from the object.
  606. // =============================
  607. try
  608. {
  609. for (long i = 0; i < lObjectCount; i++)
  610. {
  611. itrResourceMap = NULL;
  612. IWbemClassObject *pObj = ppObjArray[i];
  613. //
  614. // get the unique name
  615. //
  616. CComVariant vUniqueName;
  617. pObj->Get(bstrUniqueName, 0, &vUniqueName, 0, 0);
  618. wsUniqueName = V_BSTR(&vUniqueName);
  619. //
  620. // If here, we know the object is one of the kind we asked for.
  621. //
  622. itrResourceMap = m_ResourceMap.find(wsUniqueName);
  623. ResourceStructPtr ptrResourceStruct = NULL;
  624. if ( (itrResourceMap != NULL) )
  625. {
  626. ptrResourceStruct = (*itrResourceMap).second;
  627. //
  628. // get the new display state
  629. //
  630. CComVariant vDisplayInformationID;
  631. pObj->Get(bstrDisplayInfo, 0, &vDisplayInformationID, 0, 0);
  632. if (ptrResourceStruct)
  633. {
  634. //
  635. // if new state is different set dirty flag
  636. //
  637. if (ptrResourceStruct->lState != vDisplayInformationID.lVal)
  638. {
  639. ptrResourceStruct->lState = vDisplayInformationID.lVal;
  640. bDirty = TRUE;
  641. }
  642. }
  643. }
  644. }
  645. //
  646. // force a repaint
  647. //
  648. if (bDirty)
  649. {
  650. FireViewChange();
  651. }
  652. }
  653. catch(...)
  654. {
  655. SATraceString("CTextResCtrl::Indicate, unknown exception occured");
  656. }
  657. return WBEM_NO_ERROR;
  658. } // end of CTextResCtrl::Indicate method
  659. //++--------------------------------------------------------------
  660. //
  661. // Function: SetStatus
  662. //
  663. // Synopsis: This is the IWbemObjectSink interface method
  664. // through which WBEM calls in to indicate end of
  665. // event sequence or provide other error codes
  666. //
  667. // Arguments:
  668. // [in] LONG - progress
  669. // [in] HRESULT - status information
  670. // [in] BSTR - string info
  671. // [in] IWbemClassObject* - status object
  672. //
  673. // Returns: HRESULT - success/failure
  674. //
  675. // History: serdarun Created 12/10/2000
  676. //
  677. // Called By: WBEM
  678. //
  679. //----------------------------------------------------------------
  680. STDMETHODIMP CTextResCtrl::SetStatus (
  681. /*[in]*/ LONG lFlags,
  682. /*[in]*/ HRESULT hResult,
  683. /*[in]*/ BSTR strParam,
  684. /*[in]*/ IWbemClassObject *pObjParam
  685. )
  686. {
  687. SATracePrintf ("SAConsumer-IWbemObjectSink::SetStatus called:%x",hResult);
  688. return (WBEM_S_NO_ERROR);
  689. } // end of CTextResCtrl::SetStatus method
  690. //++--------------------------------------------------------------
  691. //
  692. // Function: OnDraw
  693. //
  694. // Synopsis: Method used to draw the icons
  695. //
  696. //
  697. // Returns: HRESULT - success/failure
  698. //
  699. // History: serdarun Created 12/10/2000
  700. //
  701. //----------------------------------------------------------------
  702. HRESULT CTextResCtrl::OnDraw(ATL_DRAWINFO& di)
  703. {
  704. LOGFONT logfnt;
  705. ::memset (&logfnt, 0, sizeof (logfnt));
  706. logfnt.lfHeight = 13;
  707. logfnt.lfCharSet = DEFAULT_CHARSET;
  708. //
  709. // let GDI decide which font to use
  710. // depending on the setting above
  711. //
  712. lstrcpy(logfnt.lfFaceName, TEXT("Arial"));
  713. HFONT hFont = ::CreateFontIndirect(&logfnt);
  714. //
  715. // if we cannot create font, return
  716. //
  717. if (NULL == hFont)
  718. {
  719. return E_FAIL;
  720. }
  721. //
  722. // select this font
  723. //
  724. HFONT hOldFont = (HFONT) ::SelectObject(di.hdcDraw, hFont);
  725. //
  726. // get the drawing rectangle
  727. //
  728. RECT& rc = *(RECT*)di.prcBounds;
  729. //
  730. // position of the text from top
  731. //
  732. int iTop = 0;
  733. ResourceStructPtr ptrResourceStruct = NULL;
  734. ResourceTextMapIterator itrTextMap = NULL;
  735. //
  736. // iterator for resource
  737. //
  738. ResourceMapIterator itrResourceMap = m_ResourceMap.end();
  739. MeritMapIterator itrMeritMap = m_MeritMap.begin();
  740. //
  741. // for each resource in merit map
  742. //
  743. while (itrMeritMap != m_MeritMap.end())
  744. {
  745. //
  746. // find the resource in resource map
  747. //
  748. itrResourceMap = m_ResourceMap.find((*itrMeritMap).second);
  749. //
  750. // if it is not in the map, continue with the next item
  751. //
  752. if (itrResourceMap == m_ResourceMap.end())
  753. {
  754. itrMeritMap++;
  755. continue;
  756. }
  757. ptrResourceStruct = NULL;
  758. //
  759. // get resource information struct
  760. //
  761. ptrResourceStruct = (*itrResourceMap).second;
  762. if (NULL != ptrResourceStruct)
  763. {
  764. //
  765. // find the icon corresponding to the state
  766. //
  767. itrTextMap = (ptrResourceStruct->mapResText).find(ptrResourceStruct->lState);
  768. if (itrTextMap != (ptrResourceStruct->mapResText).end())
  769. {
  770. RECT rectHeader = {rc.left,rc.top + iTop,rc.right ,rc.top + iTop + 12};
  771. DrawText(
  772. di.hdcDraw,
  773. ((*itrTextMap).second).c_str(),
  774. wcslen(((*itrTextMap).second).c_str()),
  775. &rectHeader,
  776. DT_VCENTER|DT_LEFT
  777. );
  778. }
  779. }
  780. itrMeritMap++;
  781. iTop = iTop + 12;
  782. }
  783. DeleteObject(SelectObject(di.hdcDraw,hOldFont));
  784. return S_OK;
  785. } // end of CTextResCtrl::OnDraw method
  786. //++--------------------------------------------------------------
  787. //
  788. // Function: HexCharToULong
  789. //
  790. // Synopsis: converts a hex digit to base 10 number
  791. //
  792. //
  793. // Returns: ULONG
  794. //
  795. // History: serdarun Created 12/10/2000
  796. //
  797. //----------------------------------------------------------------
  798. ULONG CTextResCtrl::HexCharToULong(WCHAR wch)
  799. {
  800. if ((wch >= '0') && (wch <= '9') )
  801. {
  802. return ULONG(wch - '0');
  803. }
  804. if ((wch >= 'A') && (wch <= 'F') )
  805. {
  806. return ULONG(wch - 'A' + 10);
  807. }
  808. if ((wch >= 'a') && (wch <= 'f') )
  809. {
  810. return ULONG(wch - 'a' + 10);
  811. }
  812. return 0;
  813. }
  814. //++--------------------------------------------------------------
  815. //
  816. // Function: HexStringToULong
  817. //
  818. // Synopsis: converts a hex string to unsigned long
  819. //
  820. //
  821. // Returns: ULONG
  822. //
  823. // History: serdarun Created 12/10/2000
  824. //
  825. //----------------------------------------------------------------
  826. ULONG CTextResCtrl::HexStringToULong(wstring wsHexString)
  827. {
  828. int iLength;
  829. int iIndex = 0;
  830. ULONG ulResult = 0;
  831. iLength = wsHexString.size();
  832. while (iIndex < iLength)
  833. {
  834. ulResult *= 16;
  835. ulResult += HexCharToULong(wsHexString[iIndex]);
  836. iIndex++;
  837. }
  838. return ulResult;
  839. }