1.OpenFileName数据接收类,如下:

using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenFileName
{
public int structSize = ;
public IntPtr dlgOwner = IntPtr.Zero;
public IntPtr instance = IntPtr.Zero;
public String filter = null;
public String customFilter = null;
public int maxCustFilter = ;
public int filterIndex = ;
public String file = null;
public int maxFile = ;
public String fileTitle = null;
public int maxFileTitle = ;
public String initialDir = null;
public String title = null;
public int flags = ;
public short fileOffset = ;
public short fileExtension = ;
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 = ;
public int flagsEx = ;
}

2.系统函数调用类, 如下:

public class LocalDialog
{
//链接指定系统函数 打开文件对话框
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
public static bool GetOFN([In, Out] OpenFileName ofn)
{
return GetOpenFileName(ofn);
} //链接指定系统函数 另存为对话框
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);
public static bool GetSFN([In,Out] OpenFileName ofn)
{
return GetSaveFileName(ofn);
}
}

3.测试入口类,如下:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices; public class DialogTest : MonoBehaviour { void OnGUI()
{
if (GUI.Button(new Rect(,,,),"Open"))
{
OpenFileName openFileName = new OpenFileName();
openFileName.structSize = Marshal.SizeOf(openFileName);
openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx";
openFileName.file = new string(new char[]);
openFileName.maxFile = openFileName.file.Length;
openFileName.fileTitle = new string(new char[]);
openFileName.maxFileTitle = openFileName.fileTitle.Length;
openFileName.initialDir = Application.streamingAssetsPath.Replace('/','\\');//默认路径
openFileName.title = "窗口标题";
openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; if (LocalDialog.GetSaveFileName(openFileName))
{
Debug.Log(openFileName.file);
Debug.Log(openFileName.fileTitle);
}
}
}
}

Unity中调用Windows窗口选择文件的更多相关文章

  1. Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug

    问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...

  2. unity 实现调用Windows窗口/对话框交互

    Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...

  3. C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。

    一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...

  4. C#中调用Windows API的要点 .

    介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...

  5. Unity中调用DLL库

    DLL -- Dynamic Link Library(动态链接库文件),这里以Window平台为例. Unity支持的两种语言生成的DLL库(C++.C#),这里以C#为例,C++网上可以搜索很详细 ...

  6. java程序员图文并茂细说Unity中调用Android的接口

    http://bbs.csdn.net/topics/391876421 最近做一个项目,为同事提供接口,能使他在Unity中调用Android中的函数来实现QQ登陆并获取用户信息.按照一些书上和一些 ...

  7. (转)C#在父窗口中调用子窗口的过程(无法访问已释放的对象)

    C#在父窗口中调用子窗口的过程: 1. 创建子窗口对象 2. 显示子窗口对象   笔者的程序中,主窗体MainFrm通过菜单调用子窗口ChildFrm.在窗体中定义了子窗口对象,然后在菜单项点击事件中 ...

  8. C#中调用Windows API时的数据类型对应关系

    原文 C#中调用Windows API时的数据类型对应关系 BOOL=System.Int32 BOOLEAN=System.Int32 BYTE=System.UInt16 CHAR=System. ...

  9. [原创]C/C++语言中,如何在main.c或main.cpp中调用另一个.c文件

    C/C++语言中,如何在main.cpp中调用另一个.c文件主要有5种思路: 1.在VS2012 IDE中,将被引用的.c文件后缀名全部修改为.h,然后通过IDE的解决方案资源管理器中鼠标右键单击“头 ...

随机推荐

  1. HTML5学习(2)语义化

    什么是语义化? 1.每一个HTML元素都有具体的含义,例: a元素:超链接,p元素:段落 2.所有的元素与展示效果无关 元素内容展示到页面中的效果,应该由CSS决定. 因为浏览器带有默认的CSS样式, ...

  2. window10 上的mysql8.0.13的数据库服务丢失后,找回方法

    1.由于mysql8 的 话是默认有一个配置文件的,所以在执行 初始化mysql8 mysqld --initialize #执行这个的原因是:因为之前使用的是Mysql8中自带的那个默认的配置文件 ...

  3. Whctf - OLDDRIVER - Writeup

    Whctf - OLDDRIVER - Writeup 转载请标明出处http://www.cnblogs.com/WangAoBo/p/7541536.html 题目: 分析: 给了10组RSA的加 ...

  4. 自定义ViewPager,避免左右滑动时与水平滑动控件冲突

    import android.content.Context;import android.support.v4.view.ViewPager;import android.util.Attribut ...

  5. C#中如何将字符串或者字符串数组写入文本文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. Flask 教程 第十七章:Linux上的部署

    本文翻译自The Flask Mega-Tutorial Part XVII: Deployment on Linux 这是Flask Mega-Tutorial系列的第十七部分,我将把Microbl ...

  7. IntelliJ IDEA 2017.3尚硅谷-----设置字体大小行间距

  8. 树链剖分-Hello!链剖-[NOIP2015]运输计划-[填坑]

    This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...

  9. opencv:图像轮廓发现

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  10. js中yyyymmdd hh:mm:ss字符转换为Date

    var dateString="20190102 10:30:35"; var pattern = /(\d{4})(\d{2})(\d{2})/; var formatedDat ...