UIFlash.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. #include "stdafx.h"
  2. #include "UIFlash.h"
  3. #include <atlcomcli.h>
  4. #define DISPID_FLASHEVENT_FLASHCALL ( 0x00C5 )
  5. #define DISPID_FLASHEVENT_FSCOMMAND ( 0x0096 )
  6. #define DISPID_FLASHEVENT_ONPROGRESS ( 0x07A6 )
  7. namespace DuiLib
  8. {
  9. CFlashUI::CFlashUI(void)
  10. : m_dwRef(0)
  11. , m_dwCookie(0)
  12. , m_pFlash(NULL)
  13. , m_pFlashEventHandler(NULL)
  14. {
  15. CDuiString strFlashCLSID=_T("{D27CDB6E-AE6D-11CF-96B8-444553540000}");
  16. OLECHAR szCLSID[100] = { 0 };
  17. #ifndef _UNICODE
  18. ::MultiByteToWideChar(::GetACP(), 0, strFlashCLSID, -1, szCLSID, lengthof(szCLSID) - 1);
  19. #else
  20. _tcsncpy(szCLSID, strFlashCLSID, lengthof(szCLSID) - 1);
  21. #endif
  22. ::CLSIDFromString(szCLSID, &m_clsid);
  23. }
  24. CFlashUI::~CFlashUI(void)
  25. {
  26. if (m_pFlashEventHandler)
  27. {
  28. m_pFlashEventHandler->Release();
  29. m_pFlashEventHandler=NULL;
  30. }
  31. ReleaseControl();
  32. }
  33. LPCTSTR CFlashUI::GetClass() const
  34. {
  35. return DUI_CTR_FLASH;
  36. }
  37. LPVOID CFlashUI::GetInterface( LPCTSTR pstrName )
  38. {
  39. if( _tcscmp(pstrName, DUI_CTR_FLASH) == 0 ) return static_cast<CFlashUI*>(this);
  40. return CActiveXUI::GetInterface(pstrName);
  41. }
  42. HRESULT STDMETHODCALLTYPE CFlashUI::GetTypeInfoCount( __RPC__out UINT *pctinfo )
  43. {
  44. return E_NOTIMPL;
  45. }
  46. HRESULT STDMETHODCALLTYPE CFlashUI::GetTypeInfo( UINT iTInfo, LCID lcid, __RPC__deref_out_opt ITypeInfo **ppTInfo )
  47. {
  48. return E_NOTIMPL;
  49. }
  50. HRESULT STDMETHODCALLTYPE CFlashUI::GetIDsOfNames( __RPC__in REFIID riid, __RPC__in_ecount_full(cNames ) LPOLESTR *rgszNames, UINT cNames, LCID lcid, __RPC__out_ecount_full(cNames) DISPID *rgDispId )
  51. {
  52. return E_NOTIMPL;
  53. }
  54. HRESULT STDMETHODCALLTYPE CFlashUI::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
  55. {
  56. switch(dispIdMember)
  57. {
  58. case DISPID_FLASHEVENT_FLASHCALL:
  59. {
  60. if (pDispParams->cArgs != 1 || pDispParams->rgvarg[0].vt != VT_BSTR)
  61. return E_INVALIDARG;
  62. return this->FlashCall(pDispParams->rgvarg[0].bstrVal);
  63. }
  64. case DISPID_FLASHEVENT_FSCOMMAND:
  65. {
  66. if( pDispParams && pDispParams->cArgs == 2 )
  67. {
  68. if( pDispParams->rgvarg[0].vt == VT_BSTR &&
  69. pDispParams->rgvarg[1].vt == VT_BSTR )
  70. {
  71. return FSCommand(pDispParams->rgvarg[1].bstrVal, pDispParams->rgvarg[0].bstrVal);
  72. }
  73. else
  74. {
  75. return DISP_E_TYPEMISMATCH;
  76. }
  77. }
  78. else
  79. {
  80. return DISP_E_BADPARAMCOUNT;
  81. }
  82. }
  83. case DISPID_FLASHEVENT_ONPROGRESS:
  84. {
  85. return OnProgress(*pDispParams->rgvarg[0].plVal);
  86. }
  87. case DISPID_READYSTATECHANGE:
  88. {
  89. return this->OnReadyStateChange(pDispParams->rgvarg[0].lVal);
  90. }
  91. }
  92. return S_OK;
  93. }
  94. HRESULT STDMETHODCALLTYPE CFlashUI::QueryInterface( REFIID riid, void **ppvObject )
  95. {
  96. *ppvObject = NULL;
  97. if( riid == IID_IUnknown)
  98. *ppvObject = static_cast<LPUNKNOWN>(this);
  99. else if( riid == IID_IDispatch)
  100. *ppvObject = static_cast<IDispatch*>(this);
  101. else if( riid == __uuidof(_IShockwaveFlashEvents))
  102. *ppvObject = static_cast<_IShockwaveFlashEvents*>(this);
  103. if( *ppvObject != NULL )
  104. AddRef();
  105. return *ppvObject == NULL ? E_NOINTERFACE : S_OK;
  106. }
  107. ULONG STDMETHODCALLTYPE CFlashUI::AddRef( void )
  108. {
  109. ::InterlockedIncrement(&m_dwRef);
  110. return m_dwRef;
  111. }
  112. ULONG STDMETHODCALLTYPE CFlashUI::Release( void )
  113. {
  114. ::InterlockedDecrement(&m_dwRef);
  115. return m_dwRef;
  116. }
  117. HRESULT CFlashUI::OnReadyStateChange (long newState)
  118. {
  119. if (m_pFlashEventHandler)
  120. {
  121. return m_pFlashEventHandler->OnReadyStateChange(newState);
  122. }
  123. return S_OK;
  124. }
  125. HRESULT CFlashUI::OnProgress(long percentDone )
  126. {
  127. if (m_pFlashEventHandler)
  128. {
  129. return m_pFlashEventHandler->OnProgress(percentDone);
  130. }
  131. return S_OK;
  132. }
  133. HRESULT CFlashUI::FSCommand (_bstr_t command, _bstr_t args)
  134. {
  135. if (m_pFlashEventHandler)
  136. {
  137. return m_pFlashEventHandler->FSCommand(command,args);
  138. }
  139. return S_OK;
  140. }
  141. HRESULT CFlashUI::FlashCall( _bstr_t request )
  142. {
  143. if (m_pFlashEventHandler)
  144. {
  145. return m_pFlashEventHandler->FlashCall(request);
  146. }
  147. return S_OK;
  148. }
  149. void CFlashUI::ReleaseControl()
  150. {
  151. //GetManager()->RemoveTranslateAccelerator(this);
  152. RegisterEventHandler(FALSE);
  153. if (m_pFlash)
  154. {
  155. m_pFlash->Release();
  156. m_pFlash=NULL;
  157. }
  158. }
  159. bool CFlashUI::DoCreateControl()
  160. {
  161. if (!CActiveXUI::DoCreateControl())
  162. return false;
  163. //GetManager()->AddTranslateAccelerator(this);
  164. GetControl(__uuidof(IShockwaveFlash),(LPVOID*)&m_pFlash);
  165. RegisterEventHandler(TRUE);
  166. return true;
  167. }
  168. void CFlashUI::SetFlashEventHandler( CFlashEventHandler* pHandler )
  169. {
  170. if (m_pFlashEventHandler!=NULL)
  171. {
  172. m_pFlashEventHandler->Release();
  173. }
  174. if (pHandler==NULL)
  175. {
  176. m_pFlashEventHandler=pHandler;
  177. return;
  178. }
  179. m_pFlashEventHandler=pHandler;
  180. m_pFlashEventHandler->AddRef();
  181. }
  182. LRESULT CFlashUI::TranslateAccelerator( MSG *pMsg )
  183. {
  184. if(pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST)
  185. return S_FALSE;
  186. if( m_pFlash == NULL )
  187. return E_NOTIMPL;
  188. // 当前Web窗口不是焦点,不处理加速键
  189. BOOL bIsChild = FALSE;
  190. HWND hTempWnd = NULL;
  191. HWND hWndFocus = ::GetFocus();
  192. hTempWnd = hWndFocus;
  193. while(hTempWnd != NULL)
  194. {
  195. if(hTempWnd == m_hwndHost)
  196. {
  197. bIsChild = TRUE;
  198. break;
  199. }
  200. hTempWnd = ::GetParent(hTempWnd);
  201. }
  202. if(!bIsChild)
  203. return S_FALSE;
  204. CComPtr<IOleInPlaceActiveObject> pObj;
  205. if (FAILED(m_pFlash->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID *)&pObj)))
  206. return S_FALSE;
  207. HRESULT hResult = pObj->TranslateAccelerator(pMsg);
  208. return hResult;
  209. }
  210. HRESULT CFlashUI::RegisterEventHandler( BOOL inAdvise )
  211. {
  212. if (m_pFlash==NULL)
  213. return S_FALSE;
  214. HRESULT hr=S_FALSE;
  215. CComPtr<IConnectionPointContainer> pCPC;
  216. CComPtr<IConnectionPoint> pCP;
  217. hr=m_pFlash->QueryInterface(IID_IConnectionPointContainer,(void **)&pCPC);
  218. if (FAILED(hr))
  219. return hr;
  220. hr=pCPC->FindConnectionPoint(__uuidof(_IShockwaveFlashEvents),&pCP);
  221. if (FAILED(hr))
  222. return hr;
  223. if (inAdvise)
  224. {
  225. hr = pCP->Advise((IDispatch*)this, &m_dwCookie);
  226. }
  227. else
  228. {
  229. hr = pCP->Unadvise(m_dwCookie);
  230. }
  231. return hr;
  232. }
  233. void CFlashUI::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  234. {
  235. if (_tcscmp(pstrName, _T("homepage")) == 0)
  236. {
  237. }
  238. else if (_tcscmp(pstrName, _T("autonavi"))==0)
  239. {
  240. }
  241. else
  242. CActiveXUI::SetAttribute(pstrName, pstrValue);
  243. }
  244. };