• <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>

            woaidongmao

            文章均收錄自他人博客,但不喜標題前加-[轉貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數據加載中……

            VC++ 項目中使用 FLEX

            1, http://hi.baidu.com/qinpc/blog/item/58253df3f9a04654352acc36.html

            復雜的界面有多層窗口組成,當windows在窗口改變大小的時候是先重畫父窗口,然后重畫子窗口,子父窗口重畫的過程一般無法在一個刷新周期內完成,所以會呈現閃爍。我們知道父窗口上被子窗口擋住的部分其實沒必要重畫的。

             

            解決方法:給窗口加個風格 WS_CLIPCHILDREN ,這樣父窗口上被子窗口擋住的部分就不會重畫了。如果同級窗口之間有重疊,那么需要再加上 WS_CLIPSIBLINGS 風格

             

            我趕緊到項目中把Flash對話框的窗口風格加上WS_CLIPCHILDREN,編譯后運行,成功了!感謝作者,讓我終于睡了一個安穩覺。

             

            四、DEBUG狀態是總是報Assertion失敗。

            這個問題困擾了我一整天。我的系統上安裝了Flex SDK,因此,注冊的Flash控件是調試版。不知什么原因,在每次關閉對話框之后,系統總是報cmdtarget.cpp文件中的控件引用值不為1錯誤,從而造成斷言失敗。

            我以為是代碼的問題,重建了一個項目,什么代碼都沒寫。運行,關閉,斷言錯誤。因為之前的VC出現了一個奇怪的問題:打開對話框命令總是出現非法操作。反復重裝VC都不能解決,最后在網上看到可能是安裝的visio 2003沖突,卸載visio 2003后問題解決。我開始懷疑是不是我之前的折騰把系統搞亂掉了。我又重裝了一次VC,再次編譯運行,問題再次出現。我都快瘋了。

            在沒瘋之前,我決定到同事的電腦上試一下。生成的程序運行沒有問題。把我生成的代碼拷貝過去運行,沒有問題。我突然意識到,是不是Flash控件的問題。卸載重裝后,問題解決。我的天!

            (待續。。。)

            同大多數的ActiveX控件一樣,VCFlash實現了一個CWnd的包裝:CShockwaveFlash,該類實現了Flash ActiveX控件的所有功能。在AS3問世之前,Flash同宿主之間的通訊只有FSCommand一種方式,而且是異步的,更沒有返回值可言。因為項目中需要VCFlash提供大量的數據庫查詢,返回結果通過XML進行傳遞。因此,FSCommand無疑是不方便的。

            AS3推出的外部API調用方式:ExternalInterface,極大的簡化了編程方式。ExternaleInterface是同步的調用,并可以返回調用結果。需要說明的是,同步調用是以犧牲性能為代價的,因為這涉及到大量的CPU周期占用)。我曾經在Flex項目中,利用ExternalInterface實現了IFrameFlash的嵌入調用,從而達到在Flash中顯示HTML的問題。

            CShockwaveFlashExternalInterface提供了一個事件接收器(event sink):FlashCallFlashCall事件只有一個參數:request,而且我們會發現,在Flash中通過ExternalInterface的調用,是通過XML的方式進行封裝,然后傳遞到request中的。為了獲得調用的方法名和參數,你必須解析request封裝的XML包。

            不過奇怪的是,處理FlashCall事件的是一個void方法。要返回數據,你需要調用SetReturnValue方法。返回的數據也必須是XML格式,且必須符合Flash的規范。如果要返回XML結果集,把XML封裝到<string></string>中,然后在Flash中通過new XML(str)的方式動態生成。

             

            二、屏蔽Flash的右鍵菜單

            這是個惱人的問題,我不希望用戶在軟件界面中彈出Flash右鍵菜單。在VC中,雖然Flash控件提供了SetMenu方法,通過傳入FALSE屏蔽大部分的菜單項,但遺憾的是,關于設置菜單無法去掉。

            為了實現這個功能,我查閱了大量的資料。按照一般的想法,右鍵菜單的生成應該經過某種消息處理的流程。我先是重載了CShockwaveFlash類的WndProc方法,并在其中跟蹤消息流,結果造成IDE死機。我做出了一個錯誤的決定,我認為這個消息一定可以在其它地方截獲,于是我又費了很大的周折,特意實現了自己的CControlSite類,結果依然讓人失望。

            后來下載了一個Delphi下的TShockwaveFlashEx組件,才發現該組件是通過截獲組件的WM_RBUTTONDOWN消息實現的菜單屏蔽。這就是說,讓用戶的右鍵消息干脆不傳到Flash控件中去。簡單而直接的方法。

            VC中實現起來更簡單些。直接從CShockwaveFlash派生自己的類(不建議直接修改CShowwaveFlash類),然后捕獲WM_RBUTTONDOWN消息,直接在消息處理函數中注釋掉父類的方法調用。然后修改Flash對象的類型為你的派生類即可。

            甚至可以更簡單些。直接在對話框中響應WM_MOUSEACTIVATE消息,然后在處理函數中判斷message參數的值,如果是WM_RBUTTONDOWN,則返回MA_ACTIVATEANDEAT(激活控件,吃掉消息。http://msdn2.microsoft.com/en-us/library/ms645612.aspx)。

             

            三、調整窗口大小時防止Flash控件閃爍

            DialogWM_SIZE響應中,把Flash控件布滿整個窗口。可是這個簡單的實現卻造成了Flash界面的頻繁閃爍。在DelphiTShockwaveFlashEx組件中,作者是通過覆蓋組件的CreateWnd方法實現的,在對話框Resize事件中,調用這個重載的CreateWnd方法。

            可是,在VC中如何實現呢?為此,我在google上苦苦搜索了好幾天。關于ActiveX控件閃爍的問題,網上有很多的解決方案。很多方案都是建議同時重載控件和對話框擦除背景事件,然后寫一些代碼防止控件重繪自身。也有一些方法是通過GDI的思路,在內存中通過bitblt的方式避免閃爍。看到最后很傷心,怎么會這么麻煩呢。

            2.  http://anirudhs.chaosnet.org/blog/2008.03.13.html (Flex C++ Bridge)

            Ely Greenfield's Flex Ajax Bridge is a beautiful piece of work. It impressed me so much that I translated the javascript part of it to C++. Just like FABridge for javascript, the Flex C++ bridge allows you to do most of the things you can do with actionscript via C++. Of course, the syntax is not as pretty as it would be in javascript but it does let you develop C++ applications with a Flex UI.

            What?

            Nothing explains it like code. Take a look at the following C++ snippet1:

            //addeventlistener to call a cpp function

            oRootObj.Call("getbutton1").Call("addEventListener", "click", SampleCallback);

             

            //where SampleCallback is:

            void SampleCallback(CASObject& obj, CFlexBridge* pBridge)

            {

                CASObject oRootObj;

                pBridge->Root(oRootObj);

                oRootObj.Call("getpanel1").Call("settitle", "Title from CPP");

            }

             

            //c++ way of saying Alert.show("StaticClassCalled")

            pBridge->ClassRef("mx.controls.Alert").Call("show", "StaticClassCalled");

             

            //create a datagrid and add it to the flex app

            CASObject oDGrid = pBridge->Create("mx.controls.DataGrid");

            oRootObj.Call("addChild", oDGrid);

            Flex C++ Bridge is a C++ library that lets you communicate with Flex in a manner more suited for the normal C++ programmer, i.e, you can communicate to flex from c++ by writing code like shown above.

            Once you put the Flex Ajax bridge into a Flex application, it is exposed to scripting in the browser. You can use a slightly modified version of the same FABridge.as2 (or even the same one) on the actionscript side and the flex application is exposed to the Flex C++ Bridge.

            Flex is for the web, AIR is for the desktop. What is this for?

            This is for C++ applications that need an awesome UI but do not want to re-write their existing c++ code and libraries to actionscript / javascript. It's a normal desktop application, you can interact with all your favorite C++ libraries and APIs and still have all the rich expressiveness that flex can deliver.

            You could do all this before as well, but the bridge makes it really easy to use Flex from C++. A lot of the reasons for FABridge applies to this as well, but this is outside the browser realm so those reasons have to be filtered to suit that particular fact.

            Where can I get it from?

            The project is licensed under MPL 1.1 and both the C++ and actionscript source code is available at code.google.com.

            It's open source, so feel free to participate and contribute to it.

            Sample Applications

            Note: The source (both flex and cpp) is available for all the examples.

            AdvancedDataGrid that supports Excel formulae computation:

            clip_image001

            Here, each individual cells in the ADG are editable. You can type in any Excel formula into it and hit the "Compute" button. The application invokes Excel using COM, computes the results and populates the result into the ADG.

            Scan images right into flexbook:

            clip_image001

            When the Scan button is clicked, a TWAIN dialog pops up letting you use your scanner to scan images directly into the pages of the flexbook component.

            Sample app showing two flash player instances each with a flex application:

            clip_image001

            The bridge supports multiple flash player instances. It can talk to each instance in a different manner. If you look at the screenshot, both the instances are loading the same swf file. But the C++ code for one instance adds a datagrid and removes an element shown in the pie chart.

            How does it work?

            The flash player ActiveX control is added to a MFC dialog. Now the content in the flash player can talk to the C++ application via ExternalInterface. ExternalInterface.call("fnname") will dispatch a FlashCall message on the C++ side which will have the arguments passed to call() in XML. This XML has to be parsed to understand what the message was from the actionscript side.

            All this complexity is hidden by the bridge. The bridge talks with the actionscript side of Ely's FABridge and facilitates calling and referencing to actionscript objects, classes and methods.

            There are multiple worker threads waiting to process incoming or outgoing flash requests so that the main MFC thread does not block. The bridge can even support multiple flash player instances each with it's own bridge back to the C++ application.

            Also, Actionscript exceptions are serialized and thrown on the C++ side.

            C++ Syntax Rules

            To start off, you need the root object which is the main application object of your flex application. Now you can access the public methods and properties of your application.

            Getters and setters are treated differently: A property "width" will be translated to "getwidth" for retrieving the value and "setwidth" for setting the value. Ely's FABridge had camel casing here, but that has been removed so that constants like MOUSE_DOWN don't confuse the bridge.

            The "Call" method shown in the snippets above take a string as the first argument that is the name of the method or property (suitably modified using above defined rules) and the arguments for it. Common types like string, int, reference to an AS object, custom anonymous AS object etc are converted internally to an ASObject thanks to copy constructors and operator overloads.

            For more examples of the syntax, take a look at the Worker() method in ASWorkSample.cpp.

            FABridge did not originally have support for accessing methods and variables of static classes. This was added by Devin Garner and I have incorporated his code into FABridge.as along with some of my changes.

            Fine Print

            Currently, it supports only Windows since it embeds the internet explorer flash ActiveX control in a MFC dialog.

            But it's an open source project and I hope I'll get contributors to help me make it more platform agnostic.

            I'd love to know what you guys think about this and how it's being used.

            CategoryFlexCPPBridge Comment(s)

             


            [1] Now, this is a better way to communicate rather than saying m_Shockwave.CallFunction("asfnname") where asfnname has to be exposed by using ExternalInterface.addCallback on the actionscript side.
            [2] Minor changes to support passing of primitives from me and additional support for accessing static classes, variables and methods thanks to Devin Garner)

             

            3.

            關鍵字: flex win32 vc++ vc externalinterface
            項目中要實現Flex打開文件夾選擇框(Flex做為桌面程序的UI),沒辦法,如果不用AIR只能在下面加一層Container了。網上搜來搜去差不多都是講FSCommand怎樣與VC++交互,可是FSCommand不能及時返回值呀。經過一番摸索,終于調通了ExternalInterfaceVC++中的處理流程,看代碼。
             
            Cpp
            代碼
            void CMyBicapDlg::OnFlashCallShockwaveflash1(LPCTSTR request)  

                // TODO: Add your control notification handler code here 
                // "<invoke name='%s' returntype='xml'><arguments><string>%s</string></arguments></invoke>" 
                 
                // parse request 
                TiXmlDocument request_xml; 
                request_xml.Parse(request); 
                const char* request_name = request_xml.RootElement()->Attribute("name"); 
                 
                if (strcmp(request_name,"savedVideosDirectory") == 0 || strcmp(request_name,"bufferDirectory") == 0 || strcmp(request_name,"preferredExportDirectory") == 0) 
                { 
                    // choose path 
                    CoInitialize(NULL); 
                    BROWSEINFO bi; 
                    bi.hwndOwner = this->GetSafeHwnd(); 
                    bi.pidlRoot = NULL; 
                    bi.pszDisplayName = NULL; 
                    bi.lpszTitle = NULL; 
                    bi.ulFlags = BIF_BROWSEFORCOMPUTER|BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT; 
                    bi.lpfn = NULL; 
                    LPCITEMIDLIST pidl = SHBrowseForFolder(&bi); 
                    if(pidl != NULL) 
                    { 
                        TCHAR tpath[MAX_PATH] = _T(""); 
                        BOOL bresult = SHGetPathFromIDList(pidl, tpath); 
                        if (bresult) 
                        { 
                            std::string re_value = "<string>"; 
                            re_value = re_value+tpath+"</string>"; 
                            m_FlashPlayer.SetReturnValue(re_value.c_str()); 
                        } 
                    } 
             
                    CoUninitialize(); 
                } 
                 

             
            首先,需要在項目中嵌入Flash player插件,網上有很多例子。另外Flex也要寫好代碼,這里略掉。
            添加一個ExternalInterface的事件處理函數,對于Flash player來講就是FlashCall事件(跟FSCommand不同的),這里的事件處理函數是void CMyBicapDlg::OnFlashCallShockwaveflash1(LPCTSTR request)。沒有返回值(下面會講到),參數是一個XML格式的字符串。格式是"<invoke name='%s' returntype='xml'><arguments><string>%s</string></arguments></invoke>",去查查幫助就知道了。
            處理request:標準C++沒有處理XML的庫,我去下載了tinyxml,小巧好用。下面就是按照個人需要處理request了,我這里是,打開一個文件夾選擇對話框然后選擇一個路徑。
            返回值。事件處理函數是沒有返回值的,但是flash player提供了一個方法:m_FlashPlayer.SetReturnValue(re_value.c_str());,專門傳遞返回值,格式是<string>%s</string>(也可以是別的AS結構,具體看幫助)。
            需要提醒的是,在處理期間要blockFlexExternalInterface.call是有返回值的,如果不阻塞Flex,可能返回就是NULL,呵呵,不知道深層原因。另外,反過來調用格式也是一樣的。
            調試環境:win xp, VC++6.0, Flex builder 2.0

             

            posted on 2010-12-08 15:44 肥仔 閱讀(2617) 評論(3)  編輯 收藏 引用 所屬分類: Flash & Flex

            評論

            # re: VC++ 項目中使用 FLEX  回復  更多評論   

            A kind of important information about this good post. The very good custom writings and the ability to buy an essay just about this post is offered by term paper writing services.
            2012-03-18 17:53 | NITA31JEFFERSON
            日本精品久久久久影院日本| 国产精品久久久久影院嫩草| 亚洲欧美日韩精品久久| 久久亚洲精品成人AV| 久久亚洲精品无码VA大香大香| 国内精品久久久久久久久电影网| 久久99免费视频| 久久精品国产亚洲av瑜伽| 国产精品永久久久久久久久久| 91久久精品国产91性色也| 久久九九亚洲精品| 天天爽天天爽天天片a久久网| 91久久香蕉国产熟女线看| 99久久国产亚洲高清观看2024| 亚洲一区中文字幕久久| 久久久久99精品成人片| 久久久久久免费视频| 久久久久无码精品国产不卡| 国产精品岛国久久久久| 丁香久久婷婷国产午夜视频| 色婷婷狠狠久久综合五月| 亚洲精品蜜桃久久久久久| 91精品国产综合久久精品| 精品久久久久久久久久中文字幕| 香蕉久久永久视频| 国产V亚洲V天堂无码久久久| 国内精品久久久久影院优| 久久久久亚洲AV成人网人人软件| 国产精品久久久久久久app| 国产成人久久精品一区二区三区 | 国产成人精品久久一区二区三区av | 青青草原综合久久| 亚洲国产成人乱码精品女人久久久不卡| 久久香综合精品久久伊人| 国产激情久久久久影院小草| 亚洲综合精品香蕉久久网| 国产韩国精品一区二区三区久久| 久久丝袜精品中文字幕| 久久91精品国产91久久户| 久久青青草视频| 国产精自产拍久久久久久蜜|