Flex [original] Air calls the local EXE file to complete the screenshot Function

Source: Internet
Author: User

Air calls the local EXE file to complete the Function

 

The local EXE function is called here, mainly including two knowledge points: first, how to call the local EXE file (in fact, this is a kind of local function call on the desktop platform, for example, in addition to the EXE call, you can also call Python and other files.ArticleThe second is to retrieve bitmap data from the system clipboard.

1. Demo Structure

 

2. The screenshot class encapsulates the local call interface.

 Package  {  Import Flash. desktop. Clipboard;  Import  Flash. desktop. clipboardformats;  Import  Flash. desktop. nativeprocess;  Import  Flash. desktop. nativeprocessstartupinfo;  Import  Flash. display. bitmapdata;  Import  Flash. Events. event;  Import  Flash. Events. eventdispatcher;  Import Flash. Events. nativeprocessexitevent;  Import  Flash. filesystem. file;  Public   Class Screenshot Extends  Eventdispatcher {  Public   Static   Const Shot_complete: String = "shot_complete" ;  Private VaR _ shotcompleteevent: event = Null ;  Private VaR _ file: file = Null  ;  Private VaR _ nativeprocessstartupinfo: nativeprocessstartupinfo = Null  ;  Private VaR _ process: nativeprocess = Null  ;  Private VaR _ bitmapdata: bitmapdata = Null  ; Public Function screenshot (): Void  {_ File = File. applicationdirectory. resolvepath ("snapshot.exe" ); _ Nativeprocessstartupinfo = New  Nativeprocessstartupinfo (); _nativeprocessstartupinfo.exe cutable = _ File; _ Process = New  Nativeprocess (); _ shotcompleteevent = New Event (shot_complete );}  Public Function Shot (): Void  {_ Process. Start (_ nativeprocessstartupinfo); _ process. addeventlistener (nativeprocessexitevent. Exit, onexit );}  Private Function onexit (E: nativeprocessexitevent ): Void  {  If  (Clipboard. generalclipboard. hasformat (clipboardformats. bitmap_format) {_ bitmapdata =Clipboard. generalclipboard. getdata (clipboardformats. bitmap_format) as bitmapdata; dispatchevent (_ shotcompleteevent );}}  Public  Function get bitmapdata (): bitmapdata {  Return _ Bitmapdata? _ Bitmapdata as bitmapdata: Null  ;}}} 

 

3. Demo test class:

<? XML version = "1.0" encoding = "UTF-8"?> <S: Drawing wedapplication xmlns: FX = "http://ns.adobe.com/mxml/2009" Xmlns: S = "Library: // ns.adobe.com/flex/spark"Xmlns: MX = "Library: // ns.adobe.com/flex/mx" Applicationcomplete = "Applicationcompletehandler (event)"> <FX: SCRIPT> <! [CDATA [  Import  MX. Events. flexevent;  Private VaR SS: screenshot = New  Screenshot ();  Protected Function applicationcompletehandler (Event: flexevent ): Void {Stage. addeventlistener (keyboardevent. key_down, onkdown); SS. addeventlistener (screenshot. shot_complete, oncomplete );}  Protected Function openexe_clickhandler (Event: mouseevent ): Void  {Ss. Shot ();}  Private Function onkdown (E: keyboardevent ): Void  {  If (E. altkey & E. ctrlkey & E. keycode = 65) {Ss. Shot ();}}  Protected Function oncomplete (Event: Event ): Void  {Bimg. Source = SS. bitmapdata;}] > </FX: SCRIPT> <s: hgroup> <s: button id = "openexe" label = "openexe" Click = "openexe_clickhandler (event)"/> <s: bitmapimage id = "bimg"/> </S: hgroup> </S: windowedapplication>

4. Results

 

Demo source code:

http://files.cnblogs.com/loveFlex/FlexAir%E8%B0%83%E7%94%A8%E6%9C%AC%E5%9C%B0exe%E6%96%87%E4%BB%B6.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.