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