唉喲,這次厲害咯,網上搜羅了好久,終於被我找到漢化的儲存對話方塊了,根據網上的一些前輩總結的內容,做了一些修改,
先放個:
首先需要定義一個OpenFileName的類:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public class OpenFileName{public int structSize = 0;public IntPtr dlgOwner = IntPtr.Zero;public IntPtr instance = IntPtr.Zero;public String filter = null;public String customFilter = null;public int maxCustFilter = 0;public int filterIndex = 0;public String file = null;public int maxFile = 0;public String fileTitle = null;public int maxFileTitle = 0;public String initialDir = null;public String title = null;public int flags = 0;public short fileOffset = 0;public short fileExtension = 0;public String defExt = null;public IntPtr custData = IntPtr.Zero;public IntPtr hook = IntPtr.Zero;public String templateName = null;public IntPtr reservedPtr = IntPtr.Zero;public int reservedInt = 0;public int flagsEx = 0;}
當然,也不是都用到了,只用到了一小部分,有性趣的童鞋可以個人化一下儲存對話方塊,
然後是最重要的委託GetSaveName()方法:
public class DllUse{[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);}
擋擋擋,最後調用一下即可:
public static void OpenDialog(Action<Stream> onSave) { OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Excel (*.xls)\0*.xls\0\0"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = UnityEngine.Application.dataPath;//預設路徑ofn.title = "儲存檔案"; ofn.defExt = ".xls";//顯示檔案的類型ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;if (DllTest.GetSaveFileName(ofn)) { dosomething();string Savepath = Path.GetDirectoryName (ofn.file); Process.Start (Savepath); } }
終於搞定儲存對話方塊漢化了,5555,也是不容易啊!
那位小夥伴有更好的方法希望可以分享給我啊!