ArticleDirectory
- What?
- Flex is for the Web, air is for the desktop. What is this?
- Where can I get it from?
- Sample applications
- How does it work?
- C ++ syntax rules
- Fine print
1, http://hi.baidu.com/qinpc/blog/item/58253df3f9a04654352acc36.html
ComplexInterfaceThere are multiple layers of windows. When Windows changes the size of the window, it first re-draws the parent window and then re-draws the Child Window, the process of re-painting the child parent window is generally not completed in a refresh cycle, so it will flash. We know that there is no need to reproduce the blocked part of the quilt window in the parent window.
Solution: Add ws_clipchildren style to the window so that the blocked part of the quilt window in the parent window will not be re-painted. If there are overlapping windows at the same level, you need to add the ws_clipsiblings style.
4. the debug status always reports assertion failure. Code VC VC VC Program
In the project, add ws_clipchildren to the window style of the flash dialog box. Compile and run the program! Thanks to the author, I finally got a good night's sleep. This problem has plagued me for a whole day. The flex SDK is installed on my system. Therefore, the registered flash control is a debug version. For some reason, after the dialog box is closed, the system always reports that the reference value of the control in the preview target. cpp file is not 1, which causes the assertion to fail. I thought it was a problem. I rebuilt a project and did not write any code. Run, close, and assertion error. This is because of a strange problem: the opening of the dialog box command always shows invalid operations. Repeated reinstalls cannot be solved. The installed Visio 2003 conflict may be found on the Internet. The problem is solved after you uninstall Visio 2003. I began to wonder if I had messed up the system. I re-installed it again, re-compiled and run it, and the problem appeared again. I am going crazy. Before I went crazy, I decided to try it on my colleague's computer. The generated operation is correct. Copy the generated code and run it. No problem. I suddenly realized that it was not a problem with the flash control. Solve the problem after uninstalling and reinstalling. My day! (To be continued ...)
Like most ActiveX controls, VC A cwnd packaging: cshockwaveflash is implemented for flash, which implements all functions of the Flash ActiveX control. Before the advent of as3, there was only one fscommand Method for communication between flash and the host, which was asynchronous and there was no return value. Because the project requires VC A large number of database queries are provided for flash, and the returned results are passed through XML. Therefore, fscommand is undoubtedly inconvenient. The external API calling method (externalinterface) introduced by as3 greatly simplifies programming. Externaleinterface is a synchronous call and can return the call result. It should be noted that synchronous calling is at the cost of performance because it involves a large number of CPU cycles ). I used externalinterface In the flex project to implement IFRAME embedded calling in flash to display HTML in flash. Cshockwaveflash provides an event sink: flashcall for externalinterface. The flashcall event has only one parameter: request. In flash, externalinterface calls are encapsulated in XML and then transmitted to the request. To obtain the method name and parameters, you must parse the XML package encapsulated by the request. However, it is strange that a void method is used to handle flashcall events. To return data, you must call the setreturnvalue method. The returned data must also be in XML format and must comply with Flash specifications. If you want to return an XML result set, encapsulate the XML into <string> </string>, and then dynamically generate it in Flash using the new XML (STR) method.
2. Right-click the flash shielding menu This is an annoying problem. I don't want users Interface In the pop-up Flash right-click menu. In VC In, although the flash control provides the setmenu method to block most menu items by passing false, it is a pity that the "about" and "Settings" menus cannot be removed. To achieve this function, I have read a lot of materials. According to the general idea, the right-click menu should be generated through a message processing process. I first overloaded the wndproc METHOD OF THE cshockwaveflash class and tracked the message stream. As a result, the IDE crashed. I made a wrong decision. I thought the message could be intercepted elsewhere, so I paid a lot of twists and turns and deliberately implemented my own ccontrolsite class, the results are still disappointing. After downloading a tshockwaveflashex component in Delphi, we found that the component is blocked by intercepting the wm_rbuttondown message of the component. This means that the user's right-click message is not transmitted to the Flash control. Simple and Direct Method. In VC Is easier to implement. Directly derive your own class from cshockwaveflash (You are not advised to directly modify the cshowwaveflash class), capture the wm_rbuttondown message, and comment out the method call of the parent class in the message processing function. Then, modify the type of the flash object to your derived class. It can be even simpler. Directly respond to the wm_mouseactivate message in the dialog box, and then judge the value of the Message Parameter in the processing function. If it is wm_rbuttondown, The ma_activateandeat is returned. Http://msdn2.microsoft.com/en-us/library/ms645612.aspx ).
3. Adjust the window size to prevent flash control flashing In the wm_size response of dialog, The Flash control is filled with the entire window. However, this simple implementation causes flash Interface . In the tshockwaveflashex component of Delphi, the author overwrites the createwnd method of the component and calls the createwnd method of this overload in the resize event of the dialog box. However VC How to implement it? For this reason, I searched Google for several days. There are many solutions for ActiveX Control flickering on the Internet. In many scenarios, we recommend that you reload the control and dialog box to erase background events, and then write some code to prevent the control from re-painting itself. There are also some ways to avoid flickering in the memory through the bitblt approach through the idea of GDI. At last, I was very sad. How could it be so troublesome. 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 wocould 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: Voi D Samplecallback (Casobject & OBJ, Cflexbridge * Pbridge ){ Casobjec T 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 Casobjec T 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 abve.
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?
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 cocould 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 of the browser realm so those reasons have to be filtered to suit that participates 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 participant 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:
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:
When the scan button is clicked, A Twain diain pops up letting you use your before to scan images directly into the pages of the flexbook component.
Sample app showing two Flash Player instances each with a flex application:
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 ininitialized ated 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.
Externalinterface of a flex-Win32 communication instance
Keywords: Flex Win32 VC ++ VC externalinterface
In the project, to enable flex to open the folder selection box (Flex is used as the UI of the desktop program), there is no way. If you do not need air, you can only add a container layer below. Online searches are similar to how fscommand interacts with VC ++, but fscommand cannot return values in a timely manner. After some exploration, I finally completed the externalinterface processing process in VC ++ and checked the code.
CPP Code
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 ();
}
}
First, you need to embed the Flash Player Plug-in the project. There are many examples on the Internet. In addition, you need to write the code for flex, Which is omitted here.
Add an externalinterface event processing function. For Flash Player, It is a flashcall event (different from fscommand). The event processing function here is void cmybicapdlg: onflashcallshockwaveflash1 (lpctstr request ). No return value (as described below). The parameter is a string in XML format. The format is "<invoke name = '% s' returntype = 'xml'> <arguments> <string> % S </string> </arguments> </invoke> ", check the help information.
Request Processing: Standard C ++ does not have a library for XML processing. I downloaded tinyxml, which is small and easy to use. The following shows how to process the request according to your individual needs. Here I am, open a folder selection dialog box and select a path.
Return Value. The event handler function does not return values, but Flash Player provides a method: m_flashplayer.setreturnvalue (re_value.c_str (); specifically, it passes the returned values, the format is <string> % S </string> (it can also be another as structure. For more information, see help ).
Note that flex needs to be block during processing, and externalinterface. Call has a returned value. If Flex is not blocked, null may be returned. In addition, the call format is the same.
Debugging environment: Win XP, VC ++ 6.0, flex builder 2.0