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.

278 lines
8.0 KiB

  1. // ATSCPropPage.h : Declaration of the CATSCPropPage
  2. #ifndef __ATSCPROPPAGE_H_
  3. #define __ATSCPROPPAGE_H_
  4. #include "resource.h" // main symbols
  5. EXTERN_C const CLSID CLSID_ATSCPropPage;
  6. #include "misccell.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CATSCPropPage
  9. class ATL_NO_VTABLE CATSCPropPage :
  10. public CComObjectRootEx<CComMultiThreadModel>,
  11. public CComCoClass<CATSCPropPage, &CLSID_ATSCPropPage>,
  12. public IPropertyPageImpl<CATSCPropPage>,
  13. public CDialogImpl<CATSCPropPage>,
  14. public IBroadcastEvent
  15. {
  16. public:
  17. CATSCPropPage():
  18. m_bFirstTime (true)
  19. {
  20. m_dwTitleID = IDS_TITLEATSCPropPage;
  21. m_dwHelpFileID = IDS_HELPFILEATSCPropPage;
  22. m_dwDocStringID = IDS_DOCSTRINGATSCPropPage;
  23. }
  24. enum {IDD = IDD_ATSCPROPPAGE};
  25. DECLARE_REGISTRY_RESOURCEID(IDR_ATSCPROPPAGE)
  26. DECLARE_PROTECT_FINAL_CONSTRUCT()
  27. BEGIN_COM_MAP(CATSCPropPage)
  28. COM_INTERFACE_ENTRY(IPropertyPage)
  29. COM_INTERFACE_ENTRY(IBroadcastEvent)
  30. END_COM_MAP()
  31. BEGIN_MSG_MAP(CATSCPropPage)
  32. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  33. COMMAND_HANDLER(IDC_BUTTON_VALIDATE, BN_CLICKED, OnValidateTuneRequest)
  34. COMMAND_HANDLER(IDC_BUTTON_SUBMIT_TUNE_REQUEST, BN_CLICKED, OnSubmitTuneRequest)
  35. CHAIN_MSG_MAP(IPropertyPageImpl<CATSCPropPage>)
  36. END_MSG_MAP()
  37. // Handler prototypes:
  38. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  39. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  40. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  41. typedef IPropertyPageImpl<CATSCPropPage> PPGBaseClass;
  42. STDMETHOD(SetObjects)(ULONG nObjects, IUnknown** ppUnk)
  43. {
  44. // Use SetObjects to perform basic sanity checks on the objects whose properties will be set
  45. // This page can only handle a single object
  46. // and that object must support the IBDA_NetworkProvider interface.
  47. // We return E_INVALIDARG in any other situation
  48. HRESULT hr = E_INVALIDARG;
  49. if (nObjects == 1) // Single object
  50. {
  51. CComQIPtr<IBDA_NetworkProvider> pNP(ppUnk[0]); // Must support IBDA_NetworkProvider
  52. if (pNP)
  53. hr = PPGBaseClass::SetObjects(nObjects, ppUnk);
  54. }
  55. return hr;
  56. }
  57. STDMETHOD(Activate)(HWND hWndParent, LPCRECT prc, BOOL bModal)
  58. {
  59. // If we don't have any objects, this method should not be called
  60. // Note that OleCreatePropertyFrame will call Activate even if a call to SetObjects fails, so this check is required
  61. if (!m_ppUnk)
  62. return E_UNEXPECTED;
  63. // Use Activate to update the property page's UI with information
  64. // obtained from the objects in the m_ppUnk array
  65. // We update the page to display the Name and ReadOnly properties of the document
  66. // Call the base class
  67. HRESULT hr = PPGBaseClass::Activate(hWndParent, prc, bModal);
  68. if (!m_ppUnk[0])
  69. return E_UNEXPECTED;
  70. //if already advised, unadvise
  71. if (m_pBroadcastEventService)
  72. {
  73. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  74. if (pConPoint)
  75. pConPoint->Unadvise (m_dwEventCookie);
  76. m_pBroadcastEventService.Release ();
  77. }
  78. IBroadcastEvent* pEvent = NULL;
  79. //register for events
  80. hr = CBDAMiscellaneous::RegisterForEvents (
  81. m_ppUnk[0],
  82. static_cast<IBroadcastEvent*>(this),
  83. &pEvent,
  84. m_dwEventCookie
  85. );
  86. if (SUCCEEDED (hr))
  87. m_pBroadcastEventService.Attach (pEvent);
  88. m_pTuner = m_ppUnk[0];
  89. if (!m_pTuner)
  90. return E_FAIL;
  91. return Refresh ();
  92. }
  93. STDMETHOD(Apply)(void)
  94. {
  95. //ATLTRACE(_T("CNP_CommonPage::Apply\n"));
  96. for (UINT i = 0; i < m_nObjects; i++)
  97. {
  98. // Do something interesting here
  99. }
  100. m_bDirty = FALSE;
  101. return S_OK;
  102. }
  103. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  104. {
  105. USES_CONVERSION;
  106. //set the spins
  107. HWND hwndSpin = GetDlgItem (IDC_SPIN_PHYSICAL_CHANNEL);
  108. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  109. hwndSpin = GetDlgItem (IDC_SPIN_MINOR_CHANNEL);
  110. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  111. hwndSpin = GetDlgItem (IDC_SPIN_MAJOR_CHANNEL);
  112. ::SendMessage(hwndSpin, UDM_SETRANGE32, -1, 1000000000);
  113. return 0;
  114. }
  115. private:
  116. CComQIPtr <IScanningTuner> m_pTuner;
  117. CComQIPtr <IATSCChannelTuneRequest> m_pCurrentTuneRequest;
  118. CComQIPtr <IMediaEventEx> m_pEventInterface;
  119. CComPtr <IBroadcastEvent> m_pBroadcastEventService;
  120. bool m_bFirstTime;
  121. DWORD m_dwEventCookie;
  122. void
  123. FillControlsFromLocator (
  124. IATSCLocator* pATSCLocator
  125. );
  126. void
  127. FillControlsFromTuneRequest (
  128. IATSCChannelTuneRequest* pTuneRequest
  129. );
  130. HRESULT
  131. UpdateTuneRequest ()
  132. {
  133. if (!m_pCurrentTuneRequest)
  134. return E_FAIL;
  135. USES_CONVERSION;
  136. LONG lMinorChannel = GetDlgItemInt (IDC_EDIT_MINOR_CHANNEL);
  137. LONG lMajorChannel = GetDlgItemInt (IDC_EDIT_MAJOR_CHANNEL);
  138. LONG lPhysicalChannel = GetDlgItemInt (IDC_EDIT_PHYSICAL_CHANNEL);
  139. if (FAILED (m_pCurrentTuneRequest->put_Channel (lMajorChannel)))
  140. {
  141. MESSAGEBOX (this, IDS_PUT_CHANNEL);
  142. return S_OK;
  143. }
  144. if (FAILED (m_pCurrentTuneRequest->put_MinorChannel (lMinorChannel)))
  145. {
  146. MESSAGEBOX (this, IDS_PUT_MINOR_CHANNEL);
  147. return S_OK;
  148. }
  149. CComPtr <ILocator> pLocator;
  150. m_pCurrentTuneRequest->get_Locator (&pLocator);
  151. CComQIPtr <IATSCLocator> pATSCLocator (pLocator);
  152. if (!pATSCLocator)
  153. {
  154. MESSAGEBOX (this, IDS_CANNOT_IATSCLOCATOR);
  155. return S_OK;
  156. }
  157. if (FAILED (pATSCLocator->put_PhysicalChannel (lPhysicalChannel)))
  158. {
  159. MESSAGEBOX (this, IDS_PUT_PHYSICAL);
  160. return S_OK;
  161. }
  162. return S_OK;
  163. }
  164. LRESULT OnValidateTuneRequest(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  165. {
  166. if (SUCCEEDED (UpdateTuneRequest ()))
  167. {
  168. if (FAILED(m_pTuner->Validate (m_pCurrentTuneRequest)))
  169. {
  170. MESSAGEBOX (this, IDS_NOT_VALID_TUNE_REQUEST);
  171. return S_OK;
  172. }
  173. }
  174. return S_OK;
  175. }
  176. LRESULT OnSubmitTuneRequest(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  177. {
  178. if (SUCCEEDED (UpdateTuneRequest ()))
  179. {
  180. if (FAILED(m_pTuner->put_TuneRequest (m_pCurrentTuneRequest)))
  181. {
  182. MESSAGEBOX (this, IDS_CANNOT_SUBMIT_TUNE_REQUEST);
  183. return S_OK;
  184. }
  185. }
  186. return S_OK;
  187. }
  188. STDMETHOD(Fire)(GUID EventID)
  189. {
  190. #ifdef DEBUG
  191. TCHAR szInfo[MAX_PATH];
  192. CComBSTR bstrEventID;
  193. USES_CONVERSION;
  194. StringFromCLSID (EventID, &bstrEventID);
  195. wsprintf (szInfo, _T("Notification received for %s"), OLE2T (bstrEventID));
  196. ATLTRACE (szInfo);
  197. #endif
  198. if (EventID == EVENTID_TuningChanged)
  199. {
  200. ATLTRACE ("Starting to refresh");
  201. Refresh ();
  202. }
  203. return S_OK;
  204. }
  205. HRESULT Refresh ()
  206. {
  207. //get the tunning spaces
  208. //1. get the current tuning space
  209. CComPtr <ITuningSpace> pTuneSpace;
  210. CComPtr <ITuneRequest> pTuneRequest;
  211. HRESULT hr = m_pTuner->get_TuneRequest (&pTuneRequest);
  212. if ((FAILED (hr)) || (!pTuneRequest))
  213. return E_FAIL;
  214. if (m_pCurrentTuneRequest)
  215. m_pCurrentTuneRequest.Release ();
  216. m_pCurrentTuneRequest = pTuneRequest;
  217. if (!m_pCurrentTuneRequest)
  218. //could be just the first tune request, we will get notification again..
  219. return S_OK;
  220. FillControlsFromTuneRequest (m_pCurrentTuneRequest);
  221. CComPtr <ILocator> pLocator;
  222. m_pCurrentTuneRequest->get_Locator (&pLocator);
  223. CComQIPtr <IATSCLocator> pATSCLocator(pLocator);
  224. if (!pATSCLocator)
  225. return E_FAIL;
  226. FillControlsFromLocator (pATSCLocator);
  227. return S_OK;
  228. }
  229. virtual void OnFinalMessage( HWND hWnd )
  230. {
  231. if (m_pBroadcastEventService)
  232. {
  233. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  234. pConPoint->Unadvise (m_dwEventCookie);
  235. }
  236. }
  237. };
  238. #endif //__ATSCPROPPAGE_H_