Unity C # GetSaveFileName () application,
This article is original, reproduced please indicate the source: http://www.cnblogs.com/AdvancePikachu/p/6944870.html
Sorry, this time it was amazing. After searching for it online for a long time, I finally found the Save dialog box for Chinese. I made some changes according to the content summarized by some predecessors on the Internet,
Put one first:
First, you need to define an OpenFileName class:
[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;}
Of course, I didn't use it either. I only used a small part of it. Interesting kids shoes can be personalized and saved in the dialog box,
Then the most important delegate is the GetSaveName () method:
public class DllUse{[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);}
Block, and finally call the following code:
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 [2, 256]); ofn. maxFile = ofn. file. length; ofn. fileTitle = new string (new char [64]); ofn. maxFileTitle = ofn. fileTitle. length; ofn. initialDir = UnityEngine. application. dataPath; // default path ofn. title = "save file"; ofn. defExt = ". xls "; // display the file type ofn. flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllTest. getSaveFileName (ofn) {dosomething (); string Savepath = Path. getDirectoryName (ofn. file); Process. start (Savepath );}}
The "save" dialog box is finished in Chinese, and "5555" is not easy!
That friend has a better way to share it with me!