A walkthrough of Unity C # getsavefilename ()

Source: Internet
Author: User
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!

Related Article

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.