ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks

          #

          功能描述:在Flex中嵌套框架,并且進(jìn)行數(shù)值傳遞
          1、編輯Flex框架組件iFrame.mxml
          <?xml version="1.0" encoding="utf-8"?>
              <mx:Script>
              <![CDATA[
                  import flash.external.ExternalInterface;
                  import flash.geom.Point;
                  import flash.net.navigateToURL;
                  private var __source: String;
                  /**
                   * Move iframe through ExternalInterface. The location is determined using localToGlobal()
                   * on a Point in the Canvas.
                   **/
                  private function moveIFrame(): void
                  {
                      var localPt:Point = new Point(0, 0);
                      var globalPt:Point = this.localToGlobal(localPt);
                      ExternalInterface.call("moveIFrame", globalPt.x, globalPt.y, this.width, this.height);
                  }
                  /**
                   * The source URL for the IFrame. When set, the URL is loaded through ExternalInterface.
                   **/
                  public function set source(source: String): void
                  {
                      if (source)
                      {
                          if (! ExternalInterface.available)
                          {
                              throw new Error("ExternalInterface is not available in this container. Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required.");
                          }
                          __source = source;
                          ExternalInterface.call("loadIFrame", source);
                          moveIFrame();
                      }
                  }
                  public function get source(): String
                  {
                      return __source;
                  }
                  /**
                   * Whether the IFrame is visible.
                   **/
                  override public function set visible(visible: Boolean): void
                  {
                      super.visible=visible;
                      if (visible)
                      {
                          ExternalInterface.call("showIFrame");
                      }
                      else
                      {
                          ExternalInterface.call("hideIFrame");
                      }
                  }
              ]]>
              </mx:Script>
          </mx:Canvas>
          2、放置到要使用框架的Flex中index.mxml,并寫入引用哪個frame.html
          <ui:IFrame id="iFrame" source="frame.html" visible="true" width="100%" height="300"/>
          3、在引用框架的Flex生成頁index.html里加入:
               <1. wmode set to opaque
               在調(diào)用swf的后面加上"wmode","opaque"
               例如:"pluginspage", "
                     "wmode","opaque"
               <2. the moveIFrame,hideIFrame,showIFrame,loadIFrame methods
               <script language="JavaScript" type="text/javascript">

          <!--
          // -----------------------------------------------------------------------------
          // Globals
          // Major version of Flash required
          var requiredMajorVersion = 9;
          // Minor version of Flash required
          var requiredMinorVersion = 0;
          // Minor version of Flash required
          var requiredRevision = 28;
          // -----------------------------------------------------------------------------
          // -->
          function moveIFrame(x,y,w,h) {
              var frameRef=document.getElementById("myFrame");
              frameRef.style.left=x;
              frameRef.style.top=y;
              var iFrameRef=document.getElementById("myIFrame");
                iFrameRef.width=w;
                iFrameRef.height=h;
          }
          function hideIFrame(){
              document.getElementById("myFrame").style.visibility="hidden";
          }

          function showIFrame(){
              document.getElementById("myFrame").style.visibility="visible";
          }
          function loadIFrame(url){
                document.getElementById("myFrame").innerHTML = "<iframe id='myIFrame' src='" + url + "'frameborder='0'></iframe>";
          }
          //要調(diào)用的內(nèi)容,加載前三個就可以了,后面這個函數(shù)是用來調(diào)用返回值
          function getEditorText(){
                return document.getElementById("myIFrame").contentWindow.GetEditorText1();
          }
          </script>
               <3. the 'myFrame' div
                   在</body>這前寫入:
                   <div id="myFrame" style="position:absolute;background-color:transparent;border:0         px;visibility:hidden;"></div>
          4、在Flex頁面index.mxml輸入的函數(shù)值,調(diào)用index.html中的'getEditorText'函數(shù),并且寫入到text1.text中
               text1.text=ExternalInterface.call('getEditorText',param1,param2,param3,...)
               getEditorText:函數(shù)名稱
               param:參數(shù)值
          5、在生成頁中取得框架中的函數(shù)
               框架內(nèi)的frame.html,放置在head之間:
              function GetEditorText1(){
               return getHTML(params);
               index.html生成頁的調(diào)用,設(shè)置在head之間:
               function getEditorText(){
                return document.getElementById("myIFrame").contentWindow.GetEditorText1();
               }
              
          后記:實(shí)際中在這里只是調(diào)用一個層放在對應(yīng)位置而已,當(dāng)我們在Flex中做申縮動作時,層也要跟著改變,我是如此處理的:
               設(shè)置move或show事件,當(dāng)move或show時則調(diào)用:iFrame.source = "frame.html"
          參考:

          具體的一個例子——使用IFrame這個框架的一個頁面的代碼如下:

          <!-- saved from url=(0014)about:internet -->
          <html lang="en">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title></title>
          <script src="AC_OETags.js" language="javascript"></script>
          <style>
          body { margin: 0px; overflow:hidden }
          </style>


          <script>
          <!--
          function moveIFrame(x,y,w,h) {
          // alert("move to " + x + "," + y + ", " + w + "/" + h);
              var frameRef=document.getElementById("myFrame");
              frameRef.style.left=x;
             frameRef.style.top=y;
              frameRef.width=w;
              frameRef.height=h;
          }

          function hideIFrame(){
          // alert("hide");
              document.getElementById("myFrame").style.visibility="hidden";
          }

          function showIFrame(){
          // alert("show");
              document.getElementById("myFrame").style.visibility="visible";
          }

          function navigateTo(url) {
          // alert("nav to " + url);
          // alert("from " + document.getElementById("myFrame").location);
          document.getElementById("myFrame").src = url;
          }

          -->
          </script>


          <script language="VBScript">
          <!--

          // Catch FS Commands in IE, and pass them to the corresponding JavaScript function.
          Sub flexapp_FSCommand(ByVal command, ByVal str)
              call flexapp_DoFSCommand(command, str)
          end sub

          // -->
          </script>
          </head>
          <body style="margin:0px">

          <object onMouseDown="document.body.focus();"
             classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
            

          codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,14

          ,0'
             width='100%' height='100%'
             id='flexapp' name='flexapp'>
             <param name='flashvars' value=''>
             <param name='src' value='EXPIframe.swf'>
             <param name="wmode" value="opaque">
             <embed pluginspage='http://www.macromedia.com/go/getflashplayer' width='100%'

          height='100%'
                 flashvars=''
                 src='EXPIframe.swf'
                 name='flexapp'
                 wmode="opaque"
                 swLiveConnect="true"
             />
          </object>

          <iframe id="myFrame" name="myFrame"
              frameborder="0"
              style="position:absolute;background-

          color:transparent;border:0px;visibility:hidden;"></iframe>

          </body>
          </html>

          posted @ 2012-03-08 22:48 ivaneeo 閱讀(2559) | 評論 (1)編輯 收藏

          瀏覽-選擇文件-點(diǎn)擊 “上傳 ”后,效果如下:

          彈出透明UI遮罩層 并顯示上傳這個過程 我這里設(shè)置太透明了 效果不是很立體

          曾祥展

          文件結(jié)構(gòu)如圖:

          曾祥展

           

          說明:用到“高山來客”的大文件上傳組件 http://www.cnblogs.com/bashan/archive/2008/05/23/1206095.html

          以及Newtonsoft.Json.dll Json字符串反序列化為對象 http://james.newtonking.com/projects/json-net.aspx

          jquery.blockUI.js 彈出透明遮罩層 http://malsup.com/jquery/block/

          jquery.form.js   表單驗(yàn)證Ajax提交 

          參照了“螞蟻飛了”的文章 多謝多謝 http://blog.csdn.net/jetsteven

           

           

          HTML:

          <form id="uploadForm" runat="server" enctype="multipart/form-data">   <div id="uploadfield"  style="width:600px; height:500px">    <input id="File1" type="file" runat="server" />    <asp:Button ID="Button1" runat="server"  Text="上傳" onclick="Button1_Click" />     <p>文件上傳進(jìn)度條</p>     <p>文件上傳進(jìn)度條</p>     <p>文件上傳進(jìn)度條</p>     <p>文件上傳進(jìn)度條</p>     <p>文件上傳進(jìn)度條</p>     <p>文件上傳進(jìn)度條</p>      <p>文件上傳進(jìn)度條</p>    </div>                    <div id="ui"  style="display:none"  >      <div id="output" > </div>        <div id="progressbar"class="ui-progressbar ui-widget ui-widget-content ui-corner-all" style="width:296px; height:20px;"></div>    <input id="btn_cancel" type="button" value="取消上傳" />   </div> </form>
           
          js:
           
          var inte; $(function() { $('#uploadForm').submit(function() {     return false; });  $('#uploadForm').ajaxForm({ //這里調(diào)用jquery.form.js表單注冊方法     beforeSubmit: function(a, f, o) {//提交前的處理         o.dataType = "json";         $('#uploadfield').block({ message: $('#ui'), css: { width: '300px', border: '#b9dcfe 1px solid',padding: '0.5em 0.2em'  }         });         inte = self.setInterval("getprogress()", 500);     } });  $('#btn_cancel').click(function() {     var uploadid = $("#UploadID").val();     $.ajax({         type: "POST",         dataType: "json",         async: false, //ajax的請求時同步 只有一個線程         url: "upload_ajax.ashx",         data: "UploadID=" + uploadid + "&cancel=true",         success: function(obj) {             $("#output").html(obj.msg);             inte = self.clearInterval(inte);             $('#uploadfield').unblock();                            }     }); }); });  function getprogress() { var uploadid = $("#UploadID").val() $.ajax({     type: "POST",     dataType: "json",     async: false,     url: "upload_ajax.ashx",     data: "UploadID=" + uploadid,     success: function(obj) {     var p = obj.msg.Readedlength / obj.msg.TotalLength * 100;     var info = "<FONT color=Green> 當(dāng)前上傳文件:</FONT>" + obj.msg.CurrentFile;     info += "<br><FONT color=Green>" + obj.msg.FormatStatus + ":</FONT>" + obj.msg.Status;     info += "<br><FONT color=Green>文件大小:</FONT>" + obj.msg.TotalLength;     info += "<br><FONT color=Green>速度:</FONT>" + obj.msg.FormatRatio;     info += "<br><FONT color=Green>剩余時間:</FONT>" + obj.msg.LeftTime;       $("#output").html(info);     $("#progressbar").progressbar({ value: 0 }); //初始化     $("#progressbar").progressbar("option", "value", p);     $("#progressbar div").html(p.toFixed(2) + "%");     $("#progressbar div").addClass("percentText");     if (obj.msg.Status == 4) {         inte = self.clearInterval(inte);         $('#uploadfield').unblock();      }            } }); }
           
          交互過程代碼:
           
          <%@ WebHandler Language="C#" Class="progressbar" %>  using System; using System.Web;  using BigFileUpload;//大文件引用命名空間 using Newtonsoft.Json;//對象到JSON的相互轉(zhuǎn)換 using System.Text.RegularExpressions;//正則  public class progressbar : IHttpHandler {      private string template = "{{statue:'{0}',msg:{1}}}";    public void ProcessRequest(HttpContext context)    {        context.Response.ContentType = "text/plain";        try       {        string guid = context.Request["UploadID"];        string cancel =context.Request["cancel"];     UploadContext c = UploadContextFactory.GetUploadContext(guid);       if (!string.IsNullOrEmpty(cancel))     {                    c.Abort=true;                    throw new Exception("用戶取消");        }        string json = Newtonsoft.Json.JsonConvert.SerializeObject(c);                    WriteResultJson(1, json, context,template);                 }catch (Exception err)        {            WriteResultJson(0, err.Message, context);        }    }      public static void WriteResultJson(int resultno, string description, HttpContext context) {     WriteResultJson(resultno, description, context, "{{statue:'{0}',msg:'{1}'}}"); }  public static void WriteResultJson(int resultno, string description, HttpContext context, string template) {     description = ClearBR(ReplaceString(description, "'", "|", false));     context.Response.Write(string.Format(template, resultno, description)); }  public static string ClearBR(string str) {     Regex r = null;     Match m = null;     r = new Regex(@"(\r|\n)", RegexOptions.IgnoreCase);     for (m = r.Match(str); m.Success; m = m.NextMatch())     {         str = str.Replace(m.Groups[0].ToString(), @"\n");     }     return str; }  public static string ReplaceString(string SourceString, string SearchString, string ReplaceString, bool IsCaseInsensetive) {     return Regex.Replace(SourceString, Regex.Escape(SearchString), ReplaceString, IsCaseInsensetive ? RegexOptions.IgnoreCase : RegexOptions.None); }    public bool IsReusable    {        get       {         return false;        }    }  }         
          轉(zhuǎn)
          http://www.cnblogs.com/jcomet/archive/2010/03/24/1693467.html
          posted @ 2012-02-29 20:42 ivaneeo 閱讀(594) | 評論 (0)編輯 收藏

          原理簡單的不能再簡單,就是替換變量,用轉(zhuǎn)義字符替換你的字符串,把整個js變成一個字符串,然后隨便加密替換,最后用eval來解釋他。最后把整個js文件壓縮下,沒有注釋,沒有換行,沒有空格,一般人都會看到吐血。

          說了半天不夠爽,總不能讓大家手動加密和替換吧,以下是我的御用在線加密工具,jQuery就是用其中一個加密和壓縮的:

          http://www.javascriptobfuscator.com/Default.aspx

          http://dean.edwards.name/packer/

          這2網(wǎng)站只提供加密,不提供解密,其實(shí)你解密了看得人也很痛苦,沒有注釋,沒有格式,全是abcd這樣無意義的變量,真有心想學(xué)你js的人,那就讓他學(xué)吧。你如果真的變態(tài),那你不妨兩邊混合加密幾次,保準(zhǔn)沒人看得懂,不過估計(jì)瀏覽器解釋起來也挺費(fèi)勁的。

          特別友情提醒:meebe.net

          1.加密后記著留住你原本的js文件,不要到時候改bug都改不了了。

          2.加密后如果出現(xiàn)運(yùn)行不了,請把你加密前的文件每次函數(shù)結(jié)束都加上";",因?yàn)槿コ龘Q行后,瀏覽器解釋器沒碰到";"有時候會報(bào)錯。如果加密后有錯,請務(wù)必多加幾個";"在每個語句結(jié)束或者定義結(jié)束的時候。


          轉(zhuǎn)自 meebe.net

          posted @ 2012-02-28 22:41 ivaneeo 閱讀(575) | 評論 (0)編輯 收藏

          Step 1 – Install Visual Studio 2008

          1. If you don’t have it, get the express edition here: http://www.microsoft.com/Express/VC/
          2. Run through the installer, not much else to do.

          Step 2 – Install wxWidgets

          1. Download wxWidgets (select the wxMSW installer file) from here:
            http://www.wxwidgets.org/downloads/
          2. I choose to install to c:\dev\wxwidgets\wxWidgets-2.8.10 but you can choose a different path if you want.

          Step 3 – Create an environment variable for the wxWidgets path.

          1. Click the Start icon.
          2. Right click on Computer and choose Properties.
          3. Click Advanced system settings.
          4. Click the Environment variables button.
          5. Under System Variables, click New.
          6. Enter the Variable name: WXWIN
          7. Enter the Variable Value: C:\Dev\wxWidgets-2.8.10
          8. Click OK, click OK, click OK (yes three times).

          Step 4 – Compile the wxWidgets Libraries.

          1. Browse to the following folder: C:\Dev\wxWidgets-2.8.10\build\msw
          2. Located the file called wx.dsw and open it with Visual Studio. (I just double-clicked on it.)
          3. Choose “Yes to all” when Visual Studio prompts you to convert the project.
          4. Build the project.
          5. Wait for the build to complete. It took approximately two minutes on my Lenovo T61p (dual core, 4 GB, Windows 7 64 bit). You should a line like this when it finishes successfully.
            ========== Build: 20 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
          6. Close Visual Studio.

          Step 5 – Create a new project

          1. In Visual Studio 2008, go to File | New Project.
          2. Select Visual C++ | Empty Project.
          3. Give the project a name and click OK. I named this wxTest.

          Step 6 – Create/Copy your source to this project.

          1. Right-click on the Project name and choose Open Folder in Windows Explorer. This will open to the home folder of your project. (Don’t right click the Solution name, make sure to right click the project under the solution name.)
          2. Open a second Windows Explore window.
          3. In the second window, browse to the wxWidgets sample directory and open the Minimal folder: C:\Dev\wxWidgets-2.8.10\samples\Minimal
            Note: You can choose other projects but you may want to start with Minimal and move on from there.
          4. Copy only the minimal.cpp and minimal.rc files to your project directory (the rest are not needed).
          5. Close the second window pointing to the C:\Dev\wxWidgets-2.8.10\samples\Minimal directory, it is not needed anymore.
          6. From the explorer window open to your project directory, use ctrl+click to highlight both the minimal.cpp and minimal.rc files.
          7. Drag both highlighted files into the Visual Studio Window and drop them over the project name.
            The minimal.cpp file should automatically be placed under the Source files section of your project.
            The minimal.rc file should automatically be placed under the Resource files section of your project.

          Step 7 – Customize the project properties

          1. Right-click on the wxTest project and select Properties. (Don’t right click the Solution name, make sure to right click the project under the solution name.)
          2. In the top left of the properties window there is a Configuration drop down menu. Select All Configurations.
          3. Click to expand Configuration Properties.
          4. Click to expand C/C++.

            Note: If you don’t see a C/C++ section, then you don’t have any source files.  You need at least one C++ source file for this section to show up.

          5. Click to highlight General.
          6. Enter the following in Additional Include Directories.
            $(WXWIN)\include;$(WXWIN)\lib\vc_lib\mswd
          7. Click to highlight Preprocessor.
          8. Enter the following in Preprocessor Definitions.
            WIN32;__WXMSW__;_WINDOWS;_DEBUG;__WXDEBUG__
          9. Click to expand Linker.
          10. Click to highlight General.
          11. Enter the following in Additional Library Directories.
            $(WXWIN)\lib\vc_lib
          12. Click to highlight Input.
          13. Enter the following in Additional Dependencies.
            wxmsw28d_core.lib wxbase28d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib

            Note: Not all of these libraries are required for this project, however, I list all of these because you may use some of them at some point. If you don’t think one is needed, remove it and recompile and if you don’t get errors, you were right, you probably didn’t need it.

          14. Click to expand Resources. (If you don’t see a Resources option, then you don’t have any files under resources so that is normal. Did you skip Step 5 because you probably should have added a resource in Step 5.)
          15. Click to highlight General.
          16. Enter the following in Preprocessor Definitions.
            _DEBUG;__WXMSW__;__WXDEBUG__;_WINDOWS;NOPCH
          17. Enter the following in Additional Include Directories.
            $(WXWIN)\include;$(WXWIN)\lib\vc_lib\mswd

          You are now ready to build your wxWidgets application using Visual Studio 2008 on Windows 7.

          Build your project and if you get any errors, go through it again, you probably missed a step (or I did, since I have already been caught with one step left out).

          posted @ 2012-02-17 15:43 ivaneeo 閱讀(548) | 評論 (0)編輯 收藏

          最近發(fā)現(xiàn)bootstrap toolkit非常好用,現(xiàn)在收集一下sample網(wǎng)站:
          1.http://twitter.github.com/bootstrap/(首先主站,可惜要fq)
          2.http://webdesigntutsplus.s3.amazonaws.com/tuts/195_bootstrap/demo/main.html (也是一個簡單的列子,可以作為參考)
          3.http://www.breakingnews.com/ (新聞類網(wǎng)站,做的漂亮呀。。。)
          4.http://www.mobile-loft.com/  (整體風(fēng)格簡潔)
          5.http://demo.newfies-dialer.org/ (ajax登錄的例子)
          posted @ 2012-02-14 00:26 ivaneeo 閱讀(1351) | 評論 (0)編輯 收藏

          void ConvertGBKToUtf8(CString& strGBK) {
              int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
              unsigned short * wszUtf8 = new unsigned short[len+1];
              memset(wszUtf8, 0, len * 2 + 2);
              MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);

              len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
              char *szUtf8=new char[len + 1];
              memset(szUtf8, 0, len + 1);
              WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);

              strGBK = szUtf8;
              delete[] szUtf8;
              delete[] wszUtf8;
          }

          void ConvertUtf8ToGBK(CString& strUtf8) {
              int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
              unsigned short * wszGBK = new unsigned short[len+1];
              memset(wszGBK, 0, len * 2 + 2);
              MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, wszGBK, len);

              len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
              char *szGBK=new char[len + 1];
              memset(szGBK, 0, len + 1);
              WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);

              strUtf8 = szGBK;
              delete[] szGBK;
              delete[] wszGBK;
          }
          posted @ 2012-02-09 12:58 ivaneeo 閱讀(1158) | 評論 (0)編輯 收藏

          背景

                  luacom是一個非常強(qiáng)大的模塊,它使我們可以應(yīng)用各種com組件,比如Word,但是,有一個問題,中文文件名它不識別。為什么呢?因?yàn)閏om內(nèi)部是 unicode的,于是luacom要求所有輸入都是utf-8的,而且luacom的輸出也是utf-8的。這可腫么辦啊?

          iconv

                  GNU有個libiconv庫,要是有這個我們就不怕了! luaforge上搜索下,果然有l(wèi)ua-iconv,安裝!

                  luarocks install lua-iconv  不好意思,出錯啦!出錯的原因有兩個:

          • 我們沒有安裝libiconv庫
          • lua-iconv沒有提供用cl編譯的方法

          自己編譯lua-iconv

          1. 下載編譯好的Windows版的 libiconv
          2. 下載 lua-iconv 源代碼
          3. 解壓 libiconv-1.9.1.bin.woe32.zip 文件,并將include目錄添加為vs2008的包含文件目錄,將lib目錄添加為vs2008的庫文件目錄中(參見上一篇文章
          4. 解壓lua-iconv的源代碼
          5. vs2008新建一個空的Win32 DLL工程(參見上一篇文章),命名為luaiconv,將 luaiconv.c 文件添加到工程中
          6. 修改源代碼:int luaopen_iconv(lua_State *L)  -> __declspec(dllexport) int luaopen_luaiconv(lua_State *L)
            • 注意:最后生成的dll文件名,必須和 luaopen_luaiconv 中的 luaiconv 一樣(參見上一篇文章
          7. 項(xiàng)目屬性 -> 鏈接器 -> 輸入 -> 附加庫文件 : lua51.lib iconv.lib charset.lib
          8. 編譯生成release版的 luaiconv.dll 文件
          9. 將luaiconv.dll文件,以及libiconv-1.9.1.bin.woe32.zip解壓出來的 iconv.dll(知道我為什么要改luaopen_iconv函數(shù)名了吧)和charset.dll文件一起拷貝到 luaforwindows的clibs目錄中

          測試

          1. require "luacom"  
          2. require "luaiconv"  
          3.   
          4. function createIconv(to, from)  
          5.     local cd = iconv.new(to, from)  
          6.     return function(txt)  
          7.         return cd:iconv(txt)  
          8.     end  
          9. end  
          10.   
          11. L = createIconv("utf-8", "gbk")  
          12.   
          13. -- 注意:運(yùn)行本文件會修改 C:\你好word.docx 文件,請注意備份  
          14.   
          15. wordApp = assert(luacom.CreateObject("Word.Application"))  
          16. wordApp.Visible = true  
          17.   
          18. wordDocPath = L"C:\\你好word.docx"  
          19. if not pcall(function() wordDoc = wordApp.Documents:Open(wordDocPath) end) then  
          20.     wordDoc = wordApp.Documents:Add()  
          21. end  
          22.   
          23. wordApp.Selection:TypeText(L"你好word")  
          24. wordDoc:SaveAs2(wordDocPath, wdFormatDocument)  

          以上測試代碼,第一次運(yùn)行時會創(chuàng)建 C:\你好word.docx 文件,以后再運(yùn)行時會打開這個文件,每次運(yùn)行都會輸入 “你好word” 文字。如果你是Word 2003,那么,請將docx改為doc即可。

          參考文獻(xiàn)

          http://hi.baidu.com/nivrrex/blog/item/17c231adad9e8a0f4b36d6ca.html

          這位大哥自己用VC的函數(shù)寫了轉(zhuǎn)換函數(shù),不過沒有封裝成庫,而且我覺得寫得不夠簡潔,用iconv庫比較好,還不容易出錯

          http://www.cppblog.com/darkdestiny/archive/2009/04/25/81055.html

          這位大哥,自己用iconv實(shí)現(xiàn)了轉(zhuǎn)換,也沒有封裝成庫。我的“L”函數(shù)也是從他這借來的,非常感謝!不過,我認(rèn)為它這個相比我這個有兩個弱點(diǎn):

          1、每次調(diào)用L函數(shù),都要經(jīng)過 iconv 打開、轉(zhuǎn)換、關(guān)閉的過程,而我對一種形式的轉(zhuǎn)換只需要打開一次(lua-iconv實(shí)現(xiàn)的^_^)

          2、如果要實(shí)現(xiàn)反向轉(zhuǎn)換,即utf-8到gbk,那么還得修改模塊,而我這里就不用了(當(dāng)然也是lua-iconv實(shí)現(xiàn)的^_^)

          libiconv的說明
          posted @ 2012-02-09 01:48 ivaneeo 閱讀(641) | 評論 (0)編輯 收藏

          Cocos2d-x 已經(jīng)提供了對 Lua 的基本支持,但除了 Lua 的基本庫外,并沒有捆綁一些常用庫,例如 LuaSocket。

          經(jīng)過一番嘗試,終于搞定了此問題 :)

          獲得 LuaSocket 源代碼后,在 cocos2d-x 項(xiàng)目的 libs/lua 目錄中建立子目錄 exts/luasocket,并將 luasocket-2.0.2/src 目錄中所有的 *.c/*.h 文件拷貝到 libs/lua/exts/luasocket 目錄中。

          在 libs/lua/exts 目錄中建立文件:

          lualoadexts.h

          #ifndef __LUALOADEXTS_H_ #define __LUALOADEXTS_H_  #include "lauxlib.h"  void luax_initpreload(lua_State *L);  #endif // __LUALOADEXTS_H_ 

          lualoadexts.c

          #include "lualoadexts.h"  // luasocket #include "luasocket.h" #include "mime.h"  static luaL_Reg luax_preload_list[] = {     {"socket.core", luaopen_socket_core},     {"mime.core", luaopen_mime_core},     {NULL, NULL} };  void luax_initpreload(lua_State *L) {     luaL_Reg* lib = luax_preload_list;     luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload",                    sizeof(luax_preload_list)/sizeof(luax_preload_list[0])-1);     for (; lib->func; lib++) {         lua_pushstring(L, lib->name);         lua_pushcfunction(L, lib->func);         lua_rawset(L, -3);     }     lua_pop(L, 1); } 

          最后,打開 libs/lua/cocos2dx_support/LuaEngineImpl.cpp 文件,在 CCLuaScriptModule::CCLuaScriptModule() 構(gòu)造函數(shù)最后載入 Lua 標(biāo)準(zhǔn)庫和擴(kuò)展庫的代碼:

          CCLuaScriptModule::CCLuaScriptModule() {     d_ownsState = true;     d_state = lua_open();     luaL_openlibs(d_state);     int nOpen = tolua_Cocos2d_open(d_state);     CC_UNUSED_PARAM(nOpen);     nOpen = tolua_SimpleAudioEngine_open(d_state);     CC_UNUSED_PARAM(nOpen);      // init standard libraries     luaL_openlibs(d_state);     // init more libraries     luax_initpreload(d_state); } 

          LuaScoket 除了 C 代碼,還有一部分是 Lua 代碼,所以需要將 luasocket-2.0.2/src/*.lua 復(fù)制到項(xiàng)目中,然后用下列 Lua 代碼進(jìn)行測試:

          local socket = require("socket") print("socket module:", socket) print("socket.connect function:", socket.connect) print("socket.bind function:", socket.bind)  print("\n") print("io module:", io) 
          posted @ 2012-02-08 00:03 ivaneeo 閱讀(4043) | 評論 (0)編輯 收藏

          將 Lua 源代碼直接放入最終產(chǎn)品,顯然不是個理想選擇。利用 LOOP 提供的 Precompiler 工具,可以將 Lua 模塊編譯為 C 代碼。

          準(zhǔn)備工作

          LOOP 是一個 Lua 的 OOP 框架,Precompiler 則是 LOOP 中包含的一個工具。要安裝 LOOP,得先安裝 LuaRocks

          $ wget http://luarocks.org/releases/luarocks-2.0.5.tar.gz $ tar zxf luarocks-2.0.5.tar.gz $ cd luarocks-2.0.5 $ ./configure $ make $ sudo make install 

          然后安裝 LOOP:

          $ sudo luarocks install loop 

          OK,現(xiàn)在準(zhǔn)備工作完成了,接下來就是編譯 Lua 模塊為 C 代碼。

          編譯

          我們的框架中有一個 display.lua 模塊,下面的代碼可以將這個模塊編譯出來:

          $ precompiler.lua -o luaqeeplayscripts -l "?.lua" -b -p qeeplay qeeplay/display.lua 

          最后會得到 luaqeeplayscripts.c/.h 文件。其中定義了函數(shù):

          qeeplay int luaopen_qeeplay_display(lua_State *L); 

          在上述命令行中,各個參數(shù)的意義如下:

          -o: 指定輸出文件名,例如 -o luaqeeplayscripts 會輸出 luaqeeplayscripts.c/.h  -l: 指定推斷 lua 模塊名的模式,設(shè)定為 -l "?.lua" 就會以 lua 源文件名稱作為模塊名。     例如 display.lua 就是 display 模塊。如果 display.lua 文件在 qeeplay 子目錄中,     那么 qeeplay/display.lua 的模塊名就是 qeeplay.display。  -b: 編譯為字節(jié)碼  -p: 函數(shù)定義的前綴,一般指定一個可以方便以后對生成的 .c/.h 文件進(jìn)行再處理 

          如果要將多個 lua 文件編譯為一個 C 代碼,可以添加更多的文件名到命令行中,例如:

          $ precompiler.lua -o luasocketscripts -l "?.lua" -b -p socket \     socket.lua \     socket/url.lua \     socket/tp.lua \     socket/smtp.lua \     socket/mime.lua \     socket/ltn12.lua \     socket/http.lua \     socket/ftp.lua 

          會創(chuàng)建 luasocketscripts.c/.h 文件,其中定義下列函數(shù):

          socket int luaopen_socket(lua_State *L); socket int luaopen_socket_url(lua_State *L); socket int luaopen_socket_tp(lua_State *L); socket int luaopen_socket_smtp(lua_State *L); socket int luaopen_socket_mime(lua_State *L); socket int luaopen_socket_ltn12(lua_State *L); socket int luaopen_socket_http(lua_State *L); socket int luaopen_socket_ftp(lua_State *L); 

          載入編譯好的 C 代碼

          利用前一篇文章中的 lualoadexts.c/lualoadexts.h,做一些修改即可:

          luaqeeplayscripts.c

          #include "lualoadexts.h"  // qeeplay #include "luaqeeplayscripts.h"  static luaL_Reg luax_preload_list[] = {     {"qeeplay.display", luaopen_qeeplay_display},     {NULL, NULL} };  void luax_initpreload(lua_State *L) {     .... } 

          如果有更多模塊需要載入,只需要 include 相應(yīng)的頭文件,并修改 luax_preload_list 定義即可。

          posted @ 2012-02-08 00:01 ivaneeo 閱讀(1103) | 評論 (0)編輯 收藏

          今天在flex里通過addEventListener函數(shù)給控件動態(tài)加載click事件偵聽函數(shù)時,除了事件本身傳遞的Event類型參數(shù)外,還需要傳遞更多的參數(shù),在網(wǎng)上找了一段代碼,用起來還不錯,張貼到這里。

          package
          {
              public class EventArgExtend
              {
                  public function EventArgExtend()
                  {
                  }
                 
                  public static function create(f:Function,... arg):Function
                  {
                         var F:Boolean=false;
                         var _f:Function=function(e:*,..._arg)
                         {
                             _arg=arg
                             if(!F)
                             {
                                 F=true
                                 _arg.unshift(e)
                             }
                             f.apply(null,_arg)
                         };
                         return _f;
                    }
                    public static function toString():String
                    {
                         return "Class JEventDelegate";
                    }
              }
          }

          =========================================== 使用的方式:
          txtShow.addEventListener(MouseEvent.CLICK,EventArgExtend.create(clickHandler,1,"str"));

                      private function clickHandler(e:Event,...arg):void
                      {
                          Alert.show(arg[0].toString());
                          Alert.show(arg[1].toString());
                      }


          還有另外一個方法,沒有封裝效果,不過代碼更加容易理解:

          var sayHello:String = "歡迎光臨www.FlashJ.cn -Flash,Ria技術(shù)博客";
          btn1.addEventListener(MouseEvent.CLICK,function (e:MouseEvent){clickHandlerWithArg(e,sayHello)});
          function clickHandlerWithArg(e:MouseEvent,arg:String):void
          {
          var out:String= e.target + "發(fā)出事件(有參數(shù)) :" + arg;
          trace(out);
          }
          posted @ 2011-12-16 17:43 ivaneeo 閱讀(473) | 評論 (0)編輯 收藏

          僅列出標(biāo)題
          共67頁: First 上一頁 9 10 11 12 13 14 15 16 17 下一頁 Last 
          主站蜘蛛池模板: 铜梁县| 宾阳县| 元谋县| 淳化县| 黎平县| 始兴县| 松原市| 会理县| 通渭县| 海安县| 玉林市| 建水县| 西充县| 洛阳市| 溆浦县| 灵川县| 宿迁市| 广州市| 汶上县| 吉安市| 大余县| 深水埗区| 惠安县| 手机| 迭部县| 五河县| 英德市| 凤凰县| 丰原市| 六安市| 荣昌县| 湟中县| 响水县| 永川市| 宁南县| 双江| 淮北市| 清镇市| 蓝田县| 泰顺县| 耒阳市|