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.

301 lines
8.7 KiB

  1. // NP_CommonPage.h : Declaration of the CNP_CommonPage
  2. #ifndef __NP_COMMONPAGE_H_
  3. #define __NP_COMMONPAGE_H_
  4. #include "resource.h" // main symbols
  5. #include "misccell.h"
  6. #include "TreeWin.h"
  7. #include "LastErrorWin.h"
  8. //BUG: C4003: resolution
  9. #undef SubclassWindow
  10. EXTERN_C const CLSID CLSID_NP_CommonPage;
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CNP_CommonPage
  13. class ATL_NO_VTABLE CNP_CommonPage :
  14. public CComObjectRootEx<CComSingleThreadModel>,
  15. public CComCoClass<CNP_CommonPage, &CLSID_NP_CommonPage>,
  16. public IPropertyPageImpl<CNP_CommonPage>,
  17. public CDialogImpl<CNP_CommonPage>,
  18. public IBroadcastEvent
  19. {
  20. public:
  21. CNP_CommonPage():
  22. m_treeWinControl(this)
  23. {
  24. m_dwTitleID = IDS_TITLENP_CommonPage;
  25. m_dwHelpFileID = IDS_HELPFILENP_CommonPage;
  26. m_dwDocStringID = IDS_DOCSTRINGNP_CommonPage;
  27. }
  28. enum {IDD = IDD_NP_COMMONPAGE};
  29. DECLARE_REGISTRY_RESOURCEID(IDR_NP_COMMONPAGE)
  30. DECLARE_PROTECT_FINAL_CONSTRUCT()
  31. BEGIN_COM_MAP(CNP_CommonPage)
  32. COM_INTERFACE_ENTRY(IPropertyPage)
  33. COM_INTERFACE_ENTRY(IBroadcastEvent)
  34. END_COM_MAP()
  35. BEGIN_MSG_MAP(CNP_CommonPage)
  36. CHAIN_MSG_MAP(IPropertyPageImpl<CNP_CommonPage>)
  37. COMMAND_HANDLER(IDC_BUTTON_SEEK_UP, BN_CLICKED, OnClickedButton_seek_up)
  38. COMMAND_HANDLER(IDC_BUTTON_SEEK_DOWN, BN_CLICKED, OnClickedButton_seek_down)
  39. COMMAND_HANDLER(IDC_BUTTON_AUTO_PROGRAM, BN_CLICKED, OnClickedButton_auto_program)
  40. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  41. //MESSAGE_HANDLER(m_NotifyMessage, OnDShowNotify)
  42. COMMAND_HANDLER(IDC_BUTTON_SCAN_DOWN, BN_CLICKED, OnClickedButton_scan_down)
  43. COMMAND_HANDLER(IDC_BUTTON_SCAN_UP, BN_CLICKED, OnClickedButton_scan_up)
  44. COMMAND_HANDLER(IDC_BUTTON_SUBMIT_LOCATOR, BN_CLICKED, OnClickedButton_submit_locator)
  45. REFLECT_NOTIFICATIONS ()
  46. END_MSG_MAP()
  47. // Handler prototypes:
  48. typedef IPropertyPageImpl<CNP_CommonPage> PPGBaseClass;
  49. STDMETHOD(SetObjects)(ULONG nObjects, IUnknown** ppUnk)
  50. {
  51. // Use SetObjects to perform basic sanity checks on the objects whose properties will be set
  52. // This page can only handle a single object
  53. // and that object must support the IBDA_NetworkProvider interface.
  54. // We return E_INVALIDARG in any other situation
  55. HRESULT hr = E_INVALIDARG;
  56. if (nObjects == 1) // Single object
  57. {
  58. CComQIPtr<IBDA_NetworkProvider> pNP(ppUnk[0]); // Must support IBDA_NetworkProvider
  59. if (pNP)
  60. hr = PPGBaseClass::SetObjects(nObjects, ppUnk);
  61. }
  62. return hr;
  63. }
  64. STDMETHOD(Activate)(HWND hWndParent, LPCRECT prc, BOOL bModal)
  65. {
  66. // If we don't have any objects, this method should not be called
  67. // Note that OleCreatePropertyFrame will call Activate even if a call to SetObjects fails, so this check is required
  68. if (!m_ppUnk)
  69. return E_UNEXPECTED;
  70. // Use Activate to update the property page's UI with information
  71. // obtained from the objects in the m_ppUnk array
  72. // We update the page to display the Name and ReadOnly properties of the document
  73. // Call the base class
  74. HRESULT hr = PPGBaseClass::Activate(hWndParent, prc, bModal);
  75. if (!m_ppUnk[0])
  76. return E_UNEXPECTED;
  77. //if already advised, unadvise
  78. if (m_pBroadcastEventService)
  79. {
  80. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  81. if (pConPoint)
  82. pConPoint->Unadvise (m_dwEventCookie);
  83. m_pBroadcastEventService.Release ();
  84. }
  85. IBroadcastEvent* pEvent = NULL;
  86. //register for events
  87. hr = CBDAMiscellaneous::RegisterForEvents (
  88. m_ppUnk[0],
  89. static_cast<IBroadcastEvent*>(this),
  90. &pEvent,
  91. m_dwEventCookie
  92. );
  93. if (SUCCEEDED (hr))
  94. m_pBroadcastEventService.Attach (pEvent);
  95. m_pTuner = m_ppUnk[0];
  96. if (!m_pTuner)
  97. return E_FAIL;
  98. //make sure the tree is initialized
  99. RefreshFromNP ();
  100. RefreshControls ();
  101. return S_OK;
  102. }
  103. STDMETHOD(Apply)(void)
  104. {
  105. //ATLTRACE(_T("CNP_CommonPage::Apply\n"));
  106. for (UINT i = 0; i < m_nObjects; i++)
  107. {
  108. // Do something interesting here
  109. }
  110. m_bDirty = FALSE;
  111. return S_OK;
  112. }
  113. void SendError (
  114. TCHAR* szMessage,
  115. HRESULT hrErrorCode
  116. )
  117. {
  118. TCHAR szText[MAX_PATH];
  119. m_lastHRESULT = hrErrorCode;
  120. wsprintf (szText, _T("%ld - When...%s"), m_lastHRESULT, szMessage);
  121. SetDlgItemText (IDC_STATIC_HRESULT, szText);
  122. //now flash the graphedit window so,
  123. //the user will notice he's in trouble
  124. //we used to flash the window so the user will notice that smtg is wrong
  125. //but it turned out that the user is actually confused with this
  126. /*FLASHWINFO flashInfo;
  127. flashInfo.cbSize = sizeof (FLASHWINFO);
  128. flashInfo.hwnd = ::GetParent (::GetParent (::GetParent(m_hWnd)));
  129. flashInfo.dwFlags = FLASHW_ALL;
  130. flashInfo.uCount = 3;//3 times
  131. flashInfo.dwTimeout = 500;//half of second
  132. FlashWindowEx (&flashInfo);*/
  133. }
  134. HRESULT
  135. PutTuningSpace (
  136. ITuningSpace* pTuneSpace
  137. )
  138. {
  139. ASSERT (m_pTuner);
  140. return m_pTuner->put_TuningSpace (pTuneSpace);
  141. }
  142. private:
  143. //======================================================================
  144. // Will query the NP filter and set all controls according to its props
  145. //
  146. //
  147. //======================================================================
  148. HRESULT RefreshFromNP ()
  149. {
  150. if (!m_pTuner)
  151. return E_FAIL;
  152. return m_treeWinControl.RefreshTree (m_pTuner);
  153. }
  154. void RefreshControls ()
  155. {
  156. //now set all controls according to what found
  157. TCHAR szText[MAX_PATH];
  158. HRESULT hr = m_pTuner->get_SignalStrength (&m_lSignalStrength);
  159. if (FAILED (hr))
  160. {
  161. //We got an error
  162. SendError (_T("Calling IScanningTuner::get_SignalStrength"), hr);
  163. //BUGBUG - add a special case for error
  164. return;
  165. }
  166. wsprintf (szText, _T("%ld"), m_lSignalStrength);
  167. SetDlgItemText (IDC_STATIC_SIGNAL_STRENGTH, szText);
  168. SendError (_T(""), m_lastHRESULT);
  169. }
  170. //
  171. private:
  172. //member variables
  173. //couple interfaces we need from NP
  174. CComQIPtr <IScanningTuner> m_pTuner;
  175. CComQIPtr <IMediaEventEx> m_pEventInterface;
  176. CComPtr <IBroadcastEvent> m_pBroadcastEventService;
  177. DWORD m_dwEventCookie;
  178. static UINT m_NotifyMessage;
  179. CTreeWin m_treeWinControl;
  180. CLastErrorWin m_lastErrorControl;
  181. HRESULT m_lastHRESULT;
  182. LONG m_lSignalStrength;
  183. HWND GetSafeTreeHWND ();
  184. HWND GetSafeLastErrorHWND ();
  185. LRESULT OnClickedButton_seek_up(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  186. {
  187. if (!m_pTuner)
  188. return E_FAIL;
  189. m_pTuner->SeekUp ();
  190. return 0;
  191. }
  192. LRESULT OnClickedButton_seek_down(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  193. {
  194. if (!m_pTuner)
  195. return E_FAIL;
  196. m_pTuner->SeekDown ();
  197. return 0;
  198. }
  199. LRESULT OnClickedButton_auto_program(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  200. {
  201. if (!m_pTuner)
  202. return E_FAIL;
  203. m_pTuner->AutoProgram ();
  204. return 0;
  205. }
  206. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  207. {
  208. m_treeWinControl.SubclassWindow (GetSafeTreeHWND ());
  209. m_lastErrorControl.SubclassWindow (GetSafeLastErrorHWND ());
  210. //RefreshControls ();
  211. return 0;
  212. }
  213. //received notifications from Network Provider
  214. LRESULT OnDShowNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  215. {
  216. RefreshFromNP ();
  217. RefreshControls ();
  218. return 0;
  219. }
  220. LRESULT OnClickedButton_scan_down(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  221. {
  222. //scan for 1000 miliseconds
  223. m_pTuner->ScanDown (1000);
  224. return 0;
  225. }
  226. LRESULT OnClickedButton_scan_up(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  227. {
  228. //scan for 1000 miliseconds
  229. m_pTuner->ScanUp (1000);
  230. return 0;
  231. }
  232. LRESULT OnClickedButton_submit_locator(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  233. {
  234. m_treeWinControl.SubmitCurrentLocator ();
  235. return 0;
  236. }
  237. STDMETHOD(Fire)(GUID EventID)
  238. {
  239. #ifdef DEBUG
  240. TCHAR szInfo[MAX_PATH];
  241. CComBSTR bstrEventID;
  242. USES_CONVERSION;
  243. StringFromCLSID (EventID, &bstrEventID);
  244. wsprintf (szInfo, _T("Notification received for %s"), OLE2T (bstrEventID));
  245. ATLTRACE (szInfo);
  246. #endif
  247. if (EventID == EVENTID_SignalStatusChanged)
  248. {
  249. ATLTRACE ("Starting to refresh");
  250. RefreshControls ();
  251. }
  252. return S_OK;
  253. }
  254. virtual void OnFinalMessage( HWND hWnd )
  255. {
  256. if (m_pBroadcastEventService)
  257. {
  258. CComQIPtr <IConnectionPoint> pConPoint(m_pBroadcastEventService);
  259. pConPoint->Unadvise (m_dwEventCookie);
  260. }
  261. }
  262. };
  263. #endif //__NP_COMMONPAGE_H_