#region 调用windows系统dialog 选择文件夹
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

public class OpenDialogFile
{
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;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class OpenDialogDir
{
public IntPtr hwndOwner = IntPtr.Zero;
public IntPtr pidlRoot = IntPtr.Zero;
public String pszDisplayName = null;
public String lpszTitle = null;
public UInt32 ulFlags = 0;
public IntPtr lpfn = IntPtr.Zero;
public IntPtr lParam = IntPtr.Zero;
public int iImage = 0;
}

public class DllOpenFileDialog
{
[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetOpenFileName([In, Out] OpenDialogFile ofn);

[DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool GetSaveFileName([In, Out] OpenDialogFile ofn);

[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern IntPtr SHBrowseForFolder([In, Out] OpenDialogDir ofn);

[DllImport("shell32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern bool SHGetPathFromIDList([In] IntPtr pidl, [In, Out] char[] fileName);

}

public string OpenWindowsDialog()
{
OpenDialogDir ofn2 = new OpenDialogDir();
ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
ofn2.lpszTitle = "Open Project";// 标题
//ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);

char[] charArray = new char[2000];
for (int i = 0; i < 2000; i++)
charArray[i] = '\0';

DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
string fullDirPath = new String(charArray);

fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));

return fullDirPath;//这个就是选择的目录路径。
}
#endregion

Unity调用windows系统dialog 选择文件夹的更多相关文章

  1. Unity调用Windows窗口句柄,选择文件和目录

    T:2019-6-25 10:06:59 C:Scatt Kang using System; using System.Collections; using System.Collections.G ...

  2. Delphi 弹出Windows风格的选择文件夹对话框, 还可以新建文件夹

    Delphi 弹出Windows风格的选择文件夹对话框, 还可以新建文件夹     unit Unit2; interface uses  Windows, Messages, SysUtils, V ...

  3. C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!

    https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...

  4. C#选择文件、选择文件夹、打开文件(或者文件夹)

    1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...

  5. C#选择文件、选择文件夹、打开文件

    1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...

  6. WPF中选择文件和选择文件夹的方法

    最近从winform转WPF,遇到了各种各样的问题.然而网上的关于WPF的资料少之又少,甚至连基本的文件选择操作,百度搜索的首页都没有一个比较好的方法.所以,踩了几个坑之后,我把我得到的方法分享给大家 ...

  7. FTP文件夹打开错误,Windows无法访问此文件夹

    错误提示: Windows 无法访问此文件夹,请确保输入的文件夹是正确的,并且你有权访问此文件夹.    解决方法/步骤如下    1.请确保输入的文件夹是正确的,并且你有权访问此文件夹.可以在浏览器 ...

  8. 使用C#选择文件夹、打开文件夹、选择文件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. Windows下如何将一个文件夹通过Git上传到GitHub上(转)

    在通过windows系统的电脑上写代码,需要将项目上传到GitHub上去.比如在Pycharm上写Django后端,整个项目是一个文件夹的形式,那么怎么才能这个文件夹通过Git命令上传到GitHub上 ...

随机推荐

  1. ASP.NET MVC EF 连接数据库(一)-----Database First

    database first (VS2015 ,Sql Server2014) 1,新建MVC项目 实例:   源码代码:http://note.youdao.com/noteshare?id=1fd ...

  2. Linux下java验证码不显示:Could not initialize class sun.awt.X11FontManager

    一.问题 javaweb项目,登录的时候有个图片验证码的功能.在Windows本地测试能够正常显示,部署到Linux上就不行了.报错如下: org.springframework.web.util.N ...

  3. 最新版windows安装支持输入shell命令的工具cygwin教程

    首先去官网下载自己对应系统32位或64位系统版本安装包:https://cygwin.com/install.html 下载好后按提示一步一步安装,直到这一步: 初次安装,这里是空的,没有下载的镜像链 ...

  4. CSS3制作文字背景图

    文字带上渐变色,或者说让文字透出图片.这些效果 CSS 属性也可以完成. 方法一.利用CSS3属性mix-blend-mode:lighten;实现 使用 mix-blend-mode 能够轻易实现, ...

  5. E203 译码模块(2)

    常用的alu算术运算指令(包括ecall和 ebreak)在regular alu单元处理.regular alu单元为alu单元的一个子单元.regular单元的信息总线共21位,格式如下图所示,其 ...

  6. 其他综合-CentOS 7 使用二进制包搭建lnmp平台

    CentOS 7 使用二进制包搭建lnmp平台 1.实验描述 通过二进制搭建 lnmp 平台,实现 web 环境基本部署 2.实验环境 虚拟机: 系统:CenOS 7.6 内存:2 G+ 数量:1台 ...

  7. 使用类似GeoJson的数据生成物体(建筑等)的功能逻辑

    GeoJson作为一种模型传输格式, 用的最多的就是地图里面的各种简单模型了, 比如下图中很贴切的俄罗斯方块楼: 它的格式大概就是下面这样: { "type": "Fea ...

  8. NLP中的预训练语言模型(二)—— Facebook的SpanBERT和RoBERTa

    本篇带来Facebook的提出的两个预训练模型——SpanBERT和RoBERTa. 一,SpanBERT 论文:SpanBERT: Improving Pre-training by Represe ...

  9. JS高阶---为什么说JS是单线程执行的???

    大纲: [主体] (1)如何证明JS运行是单线程的? 上述代码执行顺序结果为:fn()→timeout →timeout 接下来对上述代码做下修改 执行结果如右图所示 接下来点击确认,关闭弹框,再往后 ...

  10. python批量创建txt文件,以demo.txt内的内容为文件名

    #批量创建txt文件import sys,osa=open("demo.txt")n=0aList=[]for line in a.readlines(): aList.appen ...