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.

713 lines
21 KiB

  1. // DVBSTuneRequestPage.h : Declaration of the CDVBSTuneRequestPage
  2. #ifndef __DVBSTUNEREQUESTPAGE_H_
  3. #define __DVBSTUNEREQUESTPAGE_H_
  4. #include "resource.h" // main symbols
  5. #include "misccell.h"
  6. #include <list>
  7. EXTERN_C const CLSID CLSID_DVBSTuneRequestPage;
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CDVBSTuneRequestPage
  10. class ATL_NO_VTABLE CDVBSTuneRequestPage :
  11. public CComObjectRootEx<CComMultiThreadModel>,
  12. public CComCoClass<CDVBSTuneRequestPage, &CLSID_DVBSTuneRequestPage>,
  13. public IPropertyPageImpl<CDVBSTuneRequestPage>,
  14. public CDialogImpl<CDVBSTuneRequestPage>,
  15. public IBroadcastEvent
  16. {
  17. public:
  18. CDVBSTuneRequestPage()
  19. {
  20. m_dwTitleID = IDS_TITLEDVBSTuneRequestPage;
  21. m_dwHelpFileID = IDS_HELPFILEDVBSTuneRequestPage;
  22. m_dwDocStringID = IDS_DOCSTRINGDVBSTuneRequestPage;
  23. }
  24. ~CDVBSTuneRequestPage ()
  25. {
  26. ReleaseTuningSpaces ();
  27. }
  28. enum {IDD = IDD_DVBSTUNEREQUESTPAGE};
  29. DECLARE_REGISTRY_RESOURCEID(IDR_DVBSTUNEREQUESTPAGE)
  30. DECLARE_PROTECT_FINAL_CONSTRUCT()
  31. BEGIN_COM_MAP(CDVBSTuneRequestPage)
  32. COM_INTERFACE_ENTRY(IPropertyPage)
  33. COM_INTERFACE_ENTRY(IBroadcastEvent)
  34. END_COM_MAP()
  35. BEGIN_MSG_MAP(CDVBSTuneRequestPage)
  36. CHAIN_MSG_MAP(IPropertyPageImpl<CDVBSTuneRequestPage>)
  37. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  38. COMMAND_HANDLER(IDC_BUTTON_REST_TO_DEFAULT_LOCATOR, BN_CLICKED, OnClickedButton_rest_to_default_locator)
  39. COMMAND_HANDLER(IDC_BUTTON_SUBMIT_TUNE_REQUEST, BN_CLICKED, OnClickedButton_submit_tune_request)
  40. COMMAND_HANDLER(IDC_LIST_TUNING_SPACES, LBN_SELCHANGE, OnSelchangeList_tuning_spaces)
  41. END_MSG_MAP()
  42. typedef IPropertyPageImpl<CDVBSTuneRequestPage> PPGBaseClass;
  43. void
  44. ReleaseTuningSpaces ();
  45. STDMETHOD(SetObjects)(ULONG nObjects, IUnknown** ppUnk)
  46. {
  47. // Use SetObjects to perform basic sanity checks on the objects whose properties will be set
  48. // This page can only handle a single object
  49. // and that object must support the IBDA_NetworkProvider interface.
  50. // We return E_INVALIDARG in any other situation
  51. HRESULT hr = E_INVALIDARG;
  52. if (nObjects == 1) // Single object
  53. {
  54. CComQIPtr<IBDA_NetworkProvider> pNP(ppUnk[0]); // Must support IBDA_NetworkProvider
  55. if (pNP)
  56. hr = PPGBaseClass::SetObjects(nObjects, ppUnk);
  57. }
  58. return hr;
  59. }
  60. STDMETHOD(Activate)(HWND hWndParent, LPCRECT prc, BOOL bModal)
  61. {
  62. // If we don't have any objects, this method should not be called
  63. // Note that OleCreatePropertyFrame will call Activate even if a call to SetObjects fails, so this check is required
  64. if (!m_ppUnk)
  65. return E_UNEXPECTED;
  66. // Use Activate to update the property page's UI with information
  67. // obtained from the objects in the m_ppUnk array
  68. // We update the page to display the Name and ReadOnly properties of the document
  69. // Call the base class
  70. HRESULT hr = PPGBaseClass::Activate(hWndParent, prc, bModal);
  71. if (!m_ppUnk[0])
  72. return E_UNEXPECTED;
  73. //if already advised, unadvise
  74. if (m_pBroadcastEventService)
  75. {
  76. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  77. if (pConPoint)
  78. pConPoint->Unadvise (m_dwEventCookie);
  79. m_pBroadcastEventService.Release ();
  80. }
  81. IBroadcastEvent* pEvent = NULL;
  82. //register for events
  83. hr = CBDAMiscellaneous::RegisterForEvents (
  84. m_ppUnk[0],
  85. static_cast<IBroadcastEvent*>(this),
  86. &pEvent,
  87. m_dwEventCookie
  88. );
  89. if (SUCCEEDED (hr))
  90. m_pBroadcastEventService.Attach (pEvent);
  91. m_pTuner = m_ppUnk[0];
  92. if (!m_pTuner)
  93. return E_FAIL;
  94. ReleaseTuningSpaces ();
  95. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  96. ::SendMessage (hwndListBox, LB_RESETCONTENT, NULL, NULL);
  97. //get the tunning spaces
  98. CComPtr <IEnumTuningSpaces> pTuneSpaces;
  99. hr = m_pTuner->EnumTuningSpaces (&pTuneSpaces);
  100. bool bFound = false;
  101. if (SUCCEEDED (hr) && (pTuneSpaces))
  102. {
  103. ITuningSpace* pTuneSpace = NULL;
  104. IDVBSTuningSpace* pDVBSTuningSpace;
  105. while (pTuneSpaces->Next (1, &pTuneSpace, 0) == S_OK)
  106. {
  107. hr = pTuneSpace->QueryInterface(__uuidof (IDVBSTuningSpace), reinterpret_cast <void**> (&pDVBSTuningSpace));
  108. if (FAILED (hr) || (!pDVBSTuningSpace))
  109. {
  110. ASSERT (FALSE);
  111. continue;
  112. }
  113. CComBSTR uniqueName;
  114. hr = pDVBSTuningSpace->get_UniqueName (&uniqueName.m_str);
  115. if (FAILED (hr))
  116. continue;
  117. //don't bother to release the DVBSTuningSpace pointers
  118. //they will be added to a list that will be released later
  119. AddItemToListBox (uniqueName, pDVBSTuningSpace);//we will identify the items from the name
  120. bFound = true;
  121. }
  122. }
  123. if (!bFound)
  124. {
  125. //no available tuning space so just disable all controls
  126. EnableControls (FALSE);
  127. return S_OK;
  128. }
  129. if (!m_pTuneRequest)
  130. {
  131. //Now, let's see if there is any current tunerequest we can get
  132. CComPtr <ITuneRequest> pTuneRequest;
  133. hr = m_pTuner->get_TuneRequest (&pTuneRequest);
  134. m_pTuneRequest = pTuneRequest;
  135. }
  136. CComPtr <ILocator> pLocator;
  137. if (m_pTuneRequest)
  138. {
  139. hr = m_pTuneRequest->get_Locator (&pLocator);
  140. if (FAILED (hr) || (!pLocator))
  141. {
  142. ASSERT (FALSE);
  143. EnableControls (FALSE);
  144. return S_OK;
  145. }
  146. CComQIPtr <IDVBSLocator> pDVBSLocator (pLocator);
  147. if (!pDVBSLocator)
  148. {
  149. ASSERT (FALSE);
  150. EnableControls (FALSE);
  151. return S_OK;
  152. }
  153. FillControlFromLocator (pDVBSLocator);
  154. //try to find the coresponding tuning space from the list
  155. CComPtr <ITuningSpace> pReferenceTuneSpace;
  156. hr = m_pTuneRequest->get_TuningSpace (&pReferenceTuneSpace);
  157. if (FAILED (hr) || (!pReferenceTuneSpace))
  158. {
  159. ASSERT (FALSE);
  160. EnableControls (FALSE);
  161. return S_OK;
  162. }
  163. CComQIPtr <IDVBSTuningSpace> pDVBSReferenceTuningSpace (pReferenceTuneSpace);
  164. if (!pDVBSReferenceTuningSpace)
  165. {
  166. ASSERT (FALSE);
  167. EnableControls (FALSE);
  168. return S_OK;
  169. }
  170. CComBSTR refUniqueName;
  171. hr = pDVBSReferenceTuningSpace->get_UniqueName (&refUniqueName.m_str);
  172. if (FAILED (hr))
  173. {
  174. ASSERT (FALSE);
  175. EnableControls (FALSE);
  176. return S_OK;
  177. }
  178. TUNING_SPACES::iterator it = m_tunigSpaceList.begin ();
  179. CComBSTR uniqueName;
  180. int nCount = 0;
  181. while (it != m_tunigSpaceList.end ())
  182. {
  183. //BUGBUG - should check for all properties not only for UniqueName
  184. hr = (*it)->get_UniqueName (&uniqueName.m_str);
  185. if (FAILED (hr))
  186. {
  187. ASSERT (FALSE);
  188. EnableControls (FALSE);
  189. return S_OK;
  190. }
  191. if (uniqueName == refUniqueName)
  192. {
  193. //we found it, so select the proper tuning space from the list
  194. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  195. ::SendMessage (hwndListBox, LB_SETCURSEL, nCount, NULL);
  196. break;
  197. }
  198. ++it;
  199. ++nCount;
  200. }
  201. FillControlsFromTuneRequest (m_pTuneRequest);
  202. }
  203. else
  204. {
  205. //no tune request so get the first tuning space from the list
  206. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  207. ::SendMessage (hwndListBox, LB_SETCURSEL, 0, NULL);
  208. LRESULT dwData = ::SendMessage (hwndListBox, LB_GETITEMDATA, 0, NULL);
  209. if (dwData == LB_ERR)
  210. {
  211. ASSERT (FALSE);
  212. EnableControls (FALSE);
  213. return S_OK;
  214. }
  215. IDVBSTuningSpace* pSelTuningSpace = reinterpret_cast <IDVBSTuningSpace*> (dwData);
  216. if (!pSelTuningSpace)
  217. {
  218. ASSERT (FALSE);
  219. EnableControls (FALSE);
  220. return S_OK;
  221. }
  222. hr = pSelTuningSpace->get_DefaultLocator (&pLocator);
  223. if (FAILED (hr) || (!pLocator))
  224. {
  225. ASSERT (FALSE);
  226. EnableControls (FALSE);
  227. return S_OK;
  228. }
  229. CComQIPtr <IDVBSLocator> pDVBSLocator (pLocator);
  230. if (!pDVBSLocator)
  231. {
  232. ASSERT (FALSE);
  233. EnableControls (FALSE);
  234. return S_OK;
  235. }
  236. FillControlFromLocator (pDVBSLocator);
  237. SetDlgItemInt (IDC_EDIT_ONID, -1);
  238. SetDlgItemInt (IDC_EDIT_TSID, -1);
  239. SetDlgItemInt (IDC_EDIT_SID, -1);
  240. }
  241. //if everything went fine
  242. EnableControls (true);
  243. return S_OK;
  244. }
  245. STDMETHOD(Apply)(void)
  246. {
  247. //ATLTRACE(_T("CDVBS_TuneRequest::Apply\n"));
  248. for (UINT i = 0; i < m_nObjects; i++)
  249. {
  250. // Do something interesting here
  251. }
  252. m_bDirty = FALSE;
  253. return S_OK;
  254. }
  255. private:
  256. CComQIPtr <IScanningTuner> m_pTuner;
  257. CComQIPtr <IMediaEventEx> m_pEventInterface;
  258. CBDAMiscellaneous m_misc;
  259. CComQIPtr <IDVBTuneRequest> m_pTuneRequest;
  260. CComPtr <IBroadcastEvent> m_pBroadcastEventService;
  261. DWORD m_dwEventCookie;
  262. bool m_fFirstTime;
  263. typedef std::list <IDVBSTuningSpace*> TUNING_SPACES;
  264. TUNING_SPACES m_tunigSpaceList;//mantaing a list of available tuning spaces
  265. //so we can access them easier
  266. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  267. {
  268. USES_CONVERSION;
  269. //set the spins
  270. HWND hwndSpin = GetDlgItem (IDC_SPIN_SID);
  271. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  272. hwndSpin = GetDlgItem (IDC_SPIN_ONID);
  273. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  274. hwndSpin = GetDlgItem (IDC_SPIN_CARRIER);
  275. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  276. hwndSpin = GetDlgItem (IDC_SPIN_SYMBOL_RATE);
  277. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  278. hwndSpin = GetDlgItem (IDC_SPIN_TSID);
  279. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  280. hwndSpin = GetDlgItem (IDC_SPIN_AZIMUTH);
  281. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  282. hwndSpin = GetDlgItem (IDC_SPIN_ELEVATION);
  283. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  284. hwndSpin = GetDlgItem (IDC_SPIN_ORBITAL_POSITION);
  285. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  286. //fill the combos
  287. HWND hwndCombo = GetDlgItem (IDC_COMBO_INNER_FEC);
  288. int nIndex = 0;
  289. MAP_FECMethod::iterator it;
  290. for (it = m_misc.m_FECMethodMap.begin ();it != m_misc.m_FECMethodMap.end ();it++)
  291. {
  292. nIndex = ::SendMessage (
  293. hwndCombo,
  294. CB_INSERTSTRING,
  295. nIndex,
  296. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it).first.c_str())))
  297. );
  298. //set the associated data
  299. ::SendMessage (
  300. hwndCombo,
  301. CB_SETITEMDATA,
  302. nIndex,
  303. (*it).second
  304. );
  305. ++nIndex;
  306. }
  307. hwndCombo = GetDlgItem (IDC_COMBO_FEC_RATE);
  308. nIndex = 0;
  309. MAP_BinaryConvolutionCodeRate::iterator it2;
  310. for (it2 = m_misc.m_BinaryConvolutionCodeRateMap.begin ();it2 != m_misc.m_BinaryConvolutionCodeRateMap.end ();it2++)
  311. {
  312. nIndex = ::SendMessage (
  313. hwndCombo,
  314. CB_INSERTSTRING,
  315. nIndex,
  316. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it2).first.c_str())))
  317. );
  318. //set the associated data
  319. ::SendMessage (
  320. hwndCombo,
  321. CB_SETITEMDATA,
  322. nIndex,
  323. (*it2).second
  324. );
  325. ++nIndex;
  326. }
  327. hwndCombo = GetDlgItem (IDC_COMBO_MODULATION);
  328. nIndex = 0;
  329. MAP_ModulationType::iterator it3;
  330. for (it3 = m_misc.m_ModulationTypeMap.begin ();it3 != m_misc.m_ModulationTypeMap.end ();it3++)
  331. {
  332. nIndex = ::SendMessage (
  333. hwndCombo,
  334. CB_INSERTSTRING,
  335. nIndex,
  336. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it3).first.c_str())))
  337. );
  338. //set the associated data
  339. ::SendMessage (
  340. hwndCombo,
  341. CB_SETITEMDATA,
  342. nIndex,
  343. (*it3).second
  344. );
  345. ++nIndex;
  346. }
  347. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_FEC);
  348. nIndex = 0;
  349. MAP_FECMethod::iterator it4;
  350. for (it4 = m_misc.m_FECMethodMap.begin ();it4 != m_misc.m_FECMethodMap.end ();it4++)
  351. {
  352. nIndex = ::SendMessage (
  353. hwndCombo,
  354. CB_INSERTSTRING,
  355. nIndex,
  356. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it4).first.c_str())))
  357. );
  358. //set the associated data
  359. ::SendMessage (
  360. hwndCombo,
  361. CB_SETITEMDATA,
  362. nIndex,
  363. (*it4).second
  364. );
  365. ++nIndex;
  366. }
  367. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_FEC_RATE);
  368. nIndex = 0;
  369. MAP_BinaryConvolutionCodeRate::iterator it5;
  370. for (it5 = m_misc.m_BinaryConvolutionCodeRateMap.begin ();it5 != m_misc.m_BinaryConvolutionCodeRateMap.end ();it5++)
  371. {
  372. nIndex = ::SendMessage (
  373. hwndCombo,
  374. CB_INSERTSTRING,
  375. nIndex,
  376. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it5).first.c_str())))
  377. );
  378. //set the associated data
  379. ::SendMessage (
  380. hwndCombo,
  381. CB_SETITEMDATA,
  382. nIndex,
  383. (*it5).second
  384. );
  385. ++nIndex;
  386. }
  387. hwndCombo = GetDlgItem (IDC_COMBO_OUTER_SIGNAL_POLARISATION);
  388. nIndex = 0;
  389. MAP_Polarisation::iterator it6;
  390. for (it6 = m_misc.m_PolarisationMap.begin ();it6 != m_misc.m_PolarisationMap.end ();it6++)
  391. {
  392. nIndex = ::SendMessage (
  393. hwndCombo,
  394. CB_INSERTSTRING,
  395. nIndex,
  396. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it6).first.c_str())))
  397. );
  398. //set the associated data
  399. ::SendMessage (
  400. hwndCombo,
  401. CB_SETITEMDATA,
  402. nIndex,
  403. (*it6).second
  404. );
  405. ++nIndex;
  406. }
  407. hwndCombo = GetDlgItem (IDC_COMBO_SPECTRAL_INVERSION);
  408. nIndex = 0;
  409. MAP_SpectralInversion::iterator it7;
  410. for (it7 = m_misc.m_SpectralInversionMap.begin ();it7 != m_misc.m_SpectralInversionMap.end ();it7++)
  411. {
  412. nIndex = ::SendMessage (
  413. hwndCombo,
  414. CB_INSERTSTRING,
  415. nIndex,
  416. reinterpret_cast <LPARAM> (A2T(const_cast <char*>((*it7).first.c_str())))
  417. );
  418. //set the associated data
  419. ::SendMessage (
  420. hwndCombo,
  421. CB_SETITEMDATA,
  422. nIndex,
  423. (*it7).second
  424. );
  425. ++nIndex;
  426. }
  427. //SetModifiedFlag (false);
  428. return 0;
  429. }
  430. void
  431. SetModifiedFlag (bool fValue)
  432. {
  433. //this will also set the m_bDirty flag
  434. SetDirty (fValue);
  435. HWND hwndSubmit = GetDlgItem (IDC_BUTTON_SUBMIT_TUNE_REQUEST);
  436. ::EnableWindow (hwndSubmit, fValue);
  437. }
  438. HRESULT
  439. FillControlFromLocator (
  440. IDVBSLocator* pLocator
  441. );
  442. HRESULT
  443. FillControlsFromTuneRequest (
  444. IDVBTuneRequest* pDVBSTuneRequest
  445. );
  446. HRESULT
  447. FillLocatorFromControls (
  448. IDVBSLocator* pLocator
  449. );
  450. HRESULT
  451. FillTuneRequestFromControls (IDVBTuneRequest* pTuneRequest);
  452. int
  453. AddItemToListBox (
  454. CComBSTR strItem,
  455. IDVBSTuningSpace* const dwData
  456. );
  457. void
  458. SelectComboBoxFromString (
  459. UINT nID,
  460. CComBSTR strToFind
  461. );
  462. CComBSTR
  463. GetComboText (
  464. UINT nID
  465. );
  466. void
  467. EnableControls (
  468. BOOL bValue
  469. );
  470. HRESULT
  471. GetSelectedTuningSpace (IDVBSTuningSpace** pTuneSpace)
  472. {
  473. HWND hwndListBox = GetDlgItem (IDC_LIST_TUNING_SPACES);
  474. int nSelIndex = ::SendMessage (hwndListBox, LB_GETCURSEL, NULL, NULL);
  475. if (nSelIndex == LB_ERR)
  476. {
  477. ASSERT (FALSE);
  478. return E_FAIL;
  479. }
  480. LRESULT dwData = ::SendMessage (hwndListBox, LB_GETITEMDATA, nSelIndex, NULL);
  481. if (dwData == LB_ERR)
  482. {
  483. ASSERT (FALSE);
  484. return E_FAIL;
  485. }
  486. IDVBSTuningSpace* pSelTuningSpace = reinterpret_cast <IDVBSTuningSpace*> (dwData);
  487. if (!pSelTuningSpace)
  488. {
  489. ASSERT (FALSE);
  490. return E_FAIL;
  491. }
  492. *pTuneSpace = pSelTuningSpace;
  493. (*pTuneSpace)->AddRef ();
  494. return S_OK;
  495. }
  496. HRESULT
  497. GetDVBSLocatorFromTuningSpace (IDVBSTuningSpace* pTuneSpace, IDVBSLocator** pDVBSLoc)
  498. {
  499. CComPtr <ILocator> pLocator;
  500. HRESULT hr = pTuneSpace->get_DefaultLocator (&pLocator);
  501. if (FAILED (hr) || (!pLocator))
  502. {
  503. MESSAGEBOX (this, IDS_CANNOT_GET_DEFLOC);
  504. return E_FAIL;
  505. }
  506. CComQIPtr <IDVBSLocator> pDVBSLocator (pLocator);
  507. if (!pDVBSLocator)
  508. {
  509. MESSAGEBOX (this, IDS_CANNOT_GET_DEF_DVBSLOCATOR);
  510. return E_FAIL;
  511. }
  512. *pDVBSLoc = pDVBSLocator;
  513. (*pDVBSLoc)->AddRef ();
  514. return S_OK;
  515. }
  516. LRESULT OnClickedButton_rest_to_default_locator(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  517. {
  518. CComPtr <IDVBSTuningSpace> pTuneSpace;
  519. HRESULT hr = GetSelectedTuningSpace (&pTuneSpace);
  520. if (FAILED (hr) || (!pTuneSpace))
  521. {
  522. ASSERT (FALSE);
  523. return 0;
  524. }
  525. CComPtr <IDVBSLocator> pDVBSLocator;
  526. GetDVBSLocatorFromTuningSpace (pTuneSpace, &pDVBSLocator);
  527. //no error
  528. FillControlFromLocator (pDVBSLocator);
  529. return 0;
  530. }
  531. LRESULT OnClickedButton_submit_tune_request(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  532. {
  533. CComPtr <IDVBSTuningSpace> pTuneSpace;
  534. HRESULT hr = GetSelectedTuningSpace (&pTuneSpace);
  535. if (FAILED (hr) || (!pTuneSpace))
  536. {
  537. ASSERT (FALSE);
  538. return 0;
  539. }
  540. CComPtr <IDVBSLocator> pSelDVBSLocator;
  541. hr = GetDVBSLocatorFromTuningSpace (pTuneSpace, &pSelDVBSLocator);
  542. if (FAILED (hr) || (!pSelDVBSLocator))
  543. {
  544. ASSERT (FALSE);
  545. return 0;
  546. }
  547. hr = FillLocatorFromControls (pSelDVBSLocator);
  548. if (FAILED (hr))
  549. {
  550. ASSERT (FALSE);
  551. return 0;
  552. }
  553. ASSERT (m_pTuner);
  554. CComPtr <ITuneRequest> pTuneRequest;
  555. hr = pTuneSpace->CreateTuneRequest (&pTuneRequest);
  556. if (FAILED (hr) || (!pTuneRequest))
  557. {
  558. MESSAGEBOX (this, IDS_CANNOT_CREATE_NEW_TUNEREQUEST);
  559. return 0;
  560. }
  561. CComQIPtr <IDVBTuneRequest> pDVBSTuneRequest (pTuneRequest);
  562. if (!pDVBSTuneRequest)
  563. {
  564. MESSAGEBOX (this, IDS_CANNOT_RETRIEVE_DVBSTUNEREQUEST);
  565. return 0;
  566. }
  567. hr = pDVBSTuneRequest->put_Locator (pSelDVBSLocator);
  568. if (FAILED (hr))
  569. {
  570. MESSAGEBOX (this, IDS_CANNOT_SET_LOCATOR_FOR_TUNEREQUEST);
  571. return 0;
  572. }
  573. hr = FillTuneRequestFromControls (pDVBSTuneRequest);
  574. if (FAILED (hr))
  575. {
  576. //already pop-up a message error dialog box
  577. return 0;
  578. }
  579. hr = m_pTuner->put_TuneRequest (pDVBSTuneRequest);
  580. if (FAILED (hr))
  581. {
  582. MESSAGEBOX (this, IDS_CANNOT_PUT_TUNE_REQUEST);
  583. return 0;
  584. }
  585. return 0;
  586. }
  587. LRESULT OnSelchangeList_tuning_spaces(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  588. {
  589. CComPtr <IDVBSTuningSpace> pTuneSpace;
  590. HRESULT hr = GetSelectedTuningSpace (&pTuneSpace);
  591. if (FAILED (hr) || (!pTuneSpace))
  592. {
  593. ASSERT (FALSE);
  594. return 0;
  595. }
  596. CComPtr <IDVBSLocator> pDVBSLocator;
  597. GetDVBSLocatorFromTuningSpace (pTuneSpace, &pDVBSLocator);
  598. //no error
  599. FillControlFromLocator (pDVBSLocator);
  600. return 0;
  601. }
  602. STDMETHOD(Fire)(GUID EventID)
  603. {
  604. #ifdef DEBUG
  605. TCHAR szInfo[MAX_PATH];
  606. CComBSTR bstrEventID;
  607. USES_CONVERSION;
  608. StringFromCLSID (EventID, &bstrEventID);
  609. wsprintf (szInfo, _T("Notification received for %s"), OLE2T (bstrEventID));
  610. ATLTRACE (szInfo);
  611. #endif
  612. if (EventID == EVENTID_TuningChanged)
  613. {
  614. ATLTRACE ("Starting to refresh");
  615. Refresh ();
  616. }
  617. return S_OK;
  618. }
  619. HRESULT Refresh ()
  620. {
  621. //get the tunning spaces
  622. //1. get the current tuning space
  623. CComPtr <ITuningSpace> pTuneSpace;
  624. CComPtr <ITuneRequest> pTuneRequest;
  625. HRESULT hr = m_pTuner->get_TuneRequest (&pTuneRequest);
  626. if ((FAILED (hr)) || (!pTuneRequest))
  627. return E_FAIL;
  628. if (m_pTuneRequest)
  629. m_pTuneRequest.Release ();
  630. m_pTuneRequest = pTuneRequest;
  631. if (!m_pTuneRequest)
  632. //could be just the first tune request, we will get notification again..
  633. return S_OK;
  634. FillControlsFromTuneRequest (m_pTuneRequest);
  635. return S_OK;
  636. }
  637. virtual void OnFinalMessage( HWND hWnd )
  638. {
  639. if (m_pBroadcastEventService)
  640. {
  641. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  642. pConPoint->Unadvise (m_dwEventCookie);
  643. }
  644. }
  645. };
  646. #endif //__DVBSTUNEREQUESTPAGE_H_