• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            沒畫完的畫

            喂馬 劈柴 BBQ~
            posts - 37, comments - 55, trackbacks - 0, articles - 0
              C++博客 ::  :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Transparent Flash Control

            Posted on 2008-09-11 22:13 沒畫完的畫 閱讀(4294) 評(píng)論(4)  編輯 收藏 引用 所屬分類: Windows COM

            在網(wǎng)頁(yè)中只需要加入以下代碼

            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="600" height="60"> 
            <param name="movie" value="test.swf"> 
            <param name="quality" value="high"> 
            <param name="wmode" value="transparent"> 
            <embed src="***.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="60"></embed> 
            </object> 
            就可以實(shí)現(xiàn) Flash 背景透明

            在VC中要實(shí)現(xiàn) Flash 背影透明播放,Google了一下找到一個(gè) Demo
            原文URL:http://www.codeproject.com/KB/COM/flashcontrol.aspx

            需要自己實(shí)現(xiàn)一個(gè)OLE容器,以前很少接觸COM,現(xiàn)在要實(shí)現(xiàn)的是一個(gè)OLE容器,先汗一下!!!!
            想到一個(gè)問(wèn)題:自己實(shí)現(xiàn)一個(gè)OLE容器跟使用直接使用FlashOcx 控件有何不同?
            -- 未解決

            Part 1
            實(shí)現(xiàn)一個(gè)ActiveX對(duì)象的OLE容器需要繼承幾個(gè)接口
            IOleClientSite
            IOleInPlaceSiteWindowless
            IOleInPlaceFrame
            IStorage
            (具體做什么,需要找資料惡補(bǔ)一下~~~~ ActiveX, OLE容器……)

            在DEMO里實(shí)現(xiàn)了一個(gè)OLE容器類叫 COleContainerWnd
            template<CLASS T>
            class COleContainerWnd : virtual public IOleClientSite,
                                     virtual public IOleInPlaceSiteWindowless, 
                                     virtual public IOleInPlaceFrame,
                                     virtual public IStorage

            是個(gè)模板類,T是留給 ActiveX 的接口

            Part 2
            把 flash.ocx 引進(jìn)來(lái),因?yàn)槔锩姘薋lash播放器的相關(guān)接口定義,它就是我們要放到容器里的 ActiveX 對(duì)象了
            #import "flash.ocx" named_guids 

            Part 3
            CFlashWnd派生類
            class CFlashWnd: public COleContainerWnd<ShockwaveFlashObjects::IShockwaveFlash>,
                                             public ShockwaveFlashObjects::_IShockwaveFlashEvents,
                                             public ShockwaveFlashObjects::IServiceProvider
            再汗一下,CFlashWnd 是個(gè)容器,還要實(shí)現(xiàn) public ShockwaveFlashObjects::IServiceProvider 接口作甚?

            至于要繼承 ShockwaveFlashObjects::_IShockwaveFlashEvents 接口的目的是為了接收 Flash 動(dòng)畫發(fā)過(guò)來(lái)的 fscommand() 事件,在 Flash的AS(動(dòng)作腳本)中調(diào)用 FsCommand(),就會(huì)
            觸發(fā)這個(gè)事件了
            (這是一個(gè)精通 Flash 的同學(xué)告訴我的!!)

            CFlashWnd 對(duì)象的創(chuàng)建
            g_flashWnd = new CFlashWnd;
            g_flashWnd->Create(ShockwaveFlashObjects::CLSID_ShockwaveFlash,
            WS_EX_LAYERED, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS,
            g_hWnd, g_hInst); 

            Create() 函數(shù)的第一個(gè)參數(shù):Flash 播放對(duì)象的ClassID
            Create() 函數(shù)的第二個(gè)參數(shù):窗體的擴(kuò)展風(fēng)格 WS_EX_LAYERED ,據(jù)說(shuō)加了這個(gè)風(fēng)格才能實(shí)現(xiàn)透明 Flash ,為啥?
            ……

            Part 4
            CFlashWnd::Create() 的內(nèi)幕
            注冊(cè)了窗口類,然后就 CreateWindows  了

            值得注意的是

            OleCreate() 函數(shù)用來(lái)創(chuàng)建一個(gè) IOleObject 對(duì)象的實(shí)例,需要 把 Ole 容器 的 IOleClientSite 和 IStorage 作為參數(shù)傳給它
                hr = OleCreate(m_CLSID, IID_IOleObject, OLERENDER_DRAW,
                    0, (IOleClientSite *)this, (IStorage *)this, (void **)&m_lpO);

            不解的是,virtual public IOleInPlaceSiteWindowless 跟 virtual public IOleInPlaceFrame 不用理了?

                hr = OleSetContainedObject(m_lpO, TRUE);

            OleSetContainedObject () 函數(shù)通知 IOleObject 對(duì)象跟它說(shuō),你已經(jīng)被嵌到 OLE 容器里了

            hr = m_lpO->QueryInterface(__uuidof(T), (void **)&m_lpControl);
            然后用 IOleObject 的 QueryInterface 獲取 IShockwaveFlash 接口(那個(gè) T, 就是 ShockwaveFlashObjects::IShockwaveFlash 了)

                hr = m_lpO->QueryInterface(IID_IViewObjectEx, (void **)&m_lpViewObjectEx);
            同樣的方法,也得到了 IViewObjectEx  的接口
            IViewObjectEx 用來(lái)干嘛的??

            要?jiǎng)?chuàng)建一個(gè)無(wú)窗口的控件,OLE容器需要  IOleInPlaceObjectWindowless 接口來(lái)分派消息給對(duì)象, 因?yàn)?對(duì)象本身沒有自己所屬的窗體
            另外,IOleInPlaceObject 接口需要重出那個(gè)對(duì)象

            hr = m_lpO->DoVerb(OLEIVERB_SHOW, NULL, (IOleClientSite *)this0, NULL, NULL);
            IOleObject::DoVerb() 用來(lái)顯示對(duì)象和將對(duì)象置為運(yùn)行的狀態(tài)

            這樣,F(xiàn)lash 播放對(duì)象就建好了.....

            Part 5.
            透明窗體的重畫

            1、創(chuàng)建窗體時(shí)加上 WS_EX_LAYERED 屬性
            2、用 CreateDIBSection() 創(chuàng)建一個(gè) 32位的DIB塊, 然后把它 Select 到 DC 里面, It will be an offscreen plain to render window contents to. (這句不知如何譯....)
            3、描繪窗體的內(nèi)容, preserving the alpha channel. (同上..)
            4、調(diào)用 UpdateLayeredWindow() 函數(shù)重畫窗體

            描繪 Flash 播放的內(nèi)容,用 OleDraw() 函數(shù), 在 IViewObject::Draw()  中調(diào)用
            hr = OleDraw(lpV, DVASPECT_TRANSPARENT, hdcDraw, &rTotal); 

            lpV – IViewObject 
            interface of flash player control 
            hdcDraw – offscreen plain 
            rTotal – client rectangle of the container window 

            DVASPECT_TRANSPARENT drawing aspect tells the object to draw it's content using alpha blending.

            DVASPECT_TRANSPARENT drawing aspect tells the object to draw it's content using alpha blending.

            While implementing this, I have met a serious bug in Flash Player Control 8. This bug is only in this version. Players 7 and 9 are free of it. The bug is in the way Flash Control fills the alpha channel of a 32 bit device context. If at least 1 of 255 alpha values is applied to pixel, the colors are mixed correctly, but the resulting alpha channel is set to 255, even if it was initially zero. This makes it impossible to create semitransparent windows. So I had to develop a solution to fix this bug. The solution is quite simple:

            These equations are used by Flash Player Control for alpha blending:

            R' = Rdst * (1 – alpha) + Rsrc * alpha
            G' = Gdst * (1 – alpha) + Gsrc * alpha
            B' = Bdst * (1 – alpha) + Bsrc * alpha

            If I draw the contents of Flash onto black surface I get

            R'black = Rsrc * alpha
            G'black = Gsrc * alpha
            B'black = Bsrc * alpha

            If I draw the contents of Flash onto white surface I get

            R'white = 255 * (1 – alpha) + Rsrc * alpha
            G'white = 255 * (1 – alpha) + Rsrc * alpha
            B'white = 255 * (1 – alpha) + Rsrc * alpha

            Here is the system of equations:

            R'black = Rsrc * alpha
            R'white = 255 * (1 – alpha) + Rsrc * alpha

            where alpha and Rsrc are unknown. After solving it you will get:

            (255-Alpha) = R'white – R'black

            Alpha = 255 – (R'white – R'black)

            So, the solution is found. Now, we can draw contents of flash player twice and then correct the corrupted alpha channel.

            Part 6. Events
            Flash Player 對(duì)象的事件是用IDispatch來(lái)處理的,在創(chuàng)建后得到一個(gè) IConnectionPointContainer 去獲取 DIID__IShockwaveFlashEvents 的 連接點(diǎn)(connection point)
            hr = m_lpControl->QueryInterface(IID_IConnectionPointContainer,
            (
            void**)&m_lpConCont);
            if (FAILED(hr))
            return FALSE;
            hr 
            = m_lpConCont->FindConnectionPoint(
            ShockwaveFlashObjects::DIID__IShockwaveFlashEvents, 
            &m_lpConPoint);
            if (FAILED(hr))
            return FALSE;
            hr 
            = m_lpConPoint->Advise(
            (ShockwaveFlashObjects::_IShockwaveFlashEvents
            *)this,
            &m_dwConPointID);
            if (FAILED(hr))
            return FALSE;

            Part 7. DirectDraw
            為了提交重畫的性能,所以使用 DirectDraw 接口
            Flash對(duì)象通過(guò) ShockwaveFlashObjects::IServiceProvider::raw_RemoteQueryService 這個(gè)接口來(lái)訪問(wèn)它
            (需要找一下 FlashObject 接口的文檔了解一下)


            (眼睛睜不開,需要先睡一會(huì)………………)






            Feedback

            # re: Transparent Flash Control   回復(fù)  更多評(píng)論   

            2008-09-12 10:24 by true
            很認(rèn)真的完成了此文,頂一個(gè)!

            # re: Transparent Flash Control   回復(fù)  更多評(píng)論   

            2008-09-12 15:37 by 賈春雨
            有點(diǎn)暈啊! 真地很厲害。

            # re: Transparent Flash Control   回復(fù)  更多評(píng)論   

            2009-12-15 15:45 by 楊嚴(yán)
            可是 為什么不能直接運(yùn)行呢。。出了好多調(diào)試錯(cuò)誤。

            # re: Transparent Flash Control   回復(fù)  更多評(píng)論   

            2010-08-29 21:52 by disala
            @楊嚴(yán)
            看清楚啦~
            他們用了什么函數(shù)?
            有dx函數(shù)存在啊,你的vs環(huán)境配置了沒有?
            99久久亚洲综合精品成人| 奇米影视7777久久精品| 久久久久久A亚洲欧洲AV冫 | 2021国产精品久久精品| 狠狠色丁香久久婷婷综合蜜芽五月| 久久国语露脸国产精品电影| 国产精品久久久久久影院| 久久久久综合国产欧美一区二区| 99精品国产99久久久久久97| 日韩精品国产自在久久现线拍| 性做久久久久久久久久久| 77777亚洲午夜久久多喷| 久久精品人妻一区二区三区| 久久99精品久久久久婷婷| 人妻无码久久精品| 97久久精品无码一区二区天美| 青青草原综合久久| 精品无码久久久久国产动漫3d| 久久这里只精品国产99热| 国产精品99久久久精品无码| 九九久久精品国产| 韩国三级大全久久网站| 亚洲中文字幕无码久久精品1| 国内精品伊人久久久久影院对白| 日韩乱码人妻无码中文字幕久久| 亚洲午夜精品久久久久久浪潮| 91精品国产91久久久久久青草| 久久精品国产亚洲av日韩| 伊人久久大香线蕉综合网站| 久久久精品国产亚洲成人满18免费网站 | 欧美一级久久久久久久大| 99精品国产在热久久无毒不卡| 亚洲国产一成人久久精品| 综合久久精品色| 欧美伊人久久大香线蕉综合69| 久久久青草青青国产亚洲免观| 国内精品久久久久| 18岁日韩内射颜射午夜久久成人| 久久精品国产一区| 久久亚洲国产欧洲精品一| 久久国产精品99久久久久久老狼|