Alas, this time, the online search has been long, and finally I found the preservation of the dialogue box, according to some of the online summary of the content of some predecessors, made some changes,
First put a:
First, you need to define a 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 Str ing filetitle = null;public int maxfiletitle = 0;public string initialdir = null;public string title = Null;public int FLA GS = 0;public Short fileoffset = 0;public short fileextension = 0;public String defext = null;public IntPtr custdata = Int Ptr.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, it is not all used, only a small part of the fun children's shoes can be personalized to save the dialog box,
Then is the most important delegate Getsavename () method:
public class Dlluse{[dllimport ("Comdlg32.dll", SetLastError = True, Throwonunmappablechar = true, CharSet = CharSet.Auto) ]public static extern bool GetSaveFileName ([In, out] openfilename ofn);}
Stop, the last call can be:
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;//default Path ofn.title = "Save File"; Ofn.defext = ". xls";//Display file type Ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;if (Dlltest.getsavefilename (ofn)) { dosomething (); string savepath = Path.getdirectoryname ( Ofn.file); Process.Start (Savepath); } }
Finally fix Save dialog box Han, 5555, is not easy ah!
That little Buddy has a better way of wanting to share it with me!