Unity C # GetSaveFileName () application,

Source: Internet
Author: User

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!

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.