MFC里创建FLASH控件,并从内存流中载入SWF

来源:互联网 发布:在线浏览器代理软件 编辑:程序博客网 时间:2024/04/30 08:58
1,在stdafx.h里引用如下头文件
#include <atlbase.h>extern CComModule _Module;     #include <atlcom.h>#include <oleacc.h>#include <comdef.h>#pragma comment(lib,"atl")#pragma comment(lib,"User32.lib")#import "c:\WINDOWS\system32\Macromed\Flash\Flash32_11_5_502_135.ocx"using namespace ShockwaveFlashObjects;
 
<p>#pragma pack(push, 1)</p><p>typedef struct _FLASH_STREAM_HEADER{    DWORD m_dwSignature;    DWORD m_dwDataSize;} FLASH_STREAM_HEADER, *PFLASH_STREAM_HEADER;</p><p>#pragma pack(pop)</p>
<pre class="cpp" name="code"> 
BOOL CFlashTest::InitInstance(){...CoInitialize(NULL);AtlAxWinInit();}
<pre class="cpp" name="code">2创建FLASH控件并从内存流中载入CRect rc;GetClientRect(&rc);static CWnd wnd;BOOL bRet = wnd.CreateControl("ShockwaveFlash.ShockwaveFlash","flash",WS_CHILD|WS_VISIBLE,rc,this,0x223);CComPtr<IShockwaveFlash> spFlash;LPUNKNOWN pUnknow = wnd.GetControlUnknown();pUnknow->QueryInterface(__uuidof(IShockwaveFlash),(void **)&spFlash);HRSRC hRes = FindResource(NULL,(LPCTSTR)IDR_SWF1,"SWF");if (hRes){DWORD dwResourceDataSize = SizeofResource(NULL,hRes);HGLOBAL hResourceLoaded = ::LoadResource(NULL, hRes);IStream *spStream;HRESULT hResult = ::CreateStreamOnHGlobal(NULL, TRUE, &spStream);FLASH_STREAM_HEADER fsh = {0x55665566, dwResourceDataSize};ULARGE_INTEGER uli = {sizeof (fsh) + dwResourceDataSize};hResult = spStream->SetSize(uli);hResult = spStream->Write(&fsh, sizeof (fsh), NULL);hResult = spStream->Write(reinterpret_cast<void*>(hResourceLoaded), dwResourceDataSize, NULL);uli.QuadPart = 0;hResult = spStream->Seek(*reinterpret_cast<PLARGE_INTEGER>(&uli), STREAM_SEEK_SET, NULL);CComPtr<IPersistStreamInit> spPersistStreamInit; spFlash.QueryInterface(&spPersistStreamInit);spPersistStreamInit->Load(spStream);}




<pre>
</pre><pre class="cpp" name="code">
	
				
		
原创粉丝点击