Unity调用windows系统dialog 选择文件夹
#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 选择文件夹的更多相关文章
- Unity调用Windows窗口句柄,选择文件和目录
T:2019-6-25 10:06:59 C:Scatt Kang using System; using System.Collections; using System.Collections.G ...
- Delphi 弹出Windows风格的选择文件夹对话框, 还可以新建文件夹
Delphi 弹出Windows风格的选择文件夹对话框, 还可以新建文件夹 unit Unit2; interface uses Windows, Messages, SysUtils, V ...
- C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!
https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...
- C#选择文件、选择文件夹、打开文件(或者文件夹)
1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...
- C#选择文件、选择文件夹、打开文件
1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...
- WPF中选择文件和选择文件夹的方法
最近从winform转WPF,遇到了各种各样的问题.然而网上的关于WPF的资料少之又少,甚至连基本的文件选择操作,百度搜索的首页都没有一个比较好的方法.所以,踩了几个坑之后,我把我得到的方法分享给大家 ...
- FTP文件夹打开错误,Windows无法访问此文件夹
错误提示: Windows 无法访问此文件夹,请确保输入的文件夹是正确的,并且你有权访问此文件夹. 解决方法/步骤如下 1.请确保输入的文件夹是正确的,并且你有权访问此文件夹.可以在浏览器 ...
- 使用C#选择文件夹、打开文件夹、选择文件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Windows下如何将一个文件夹通过Git上传到GitHub上(转)
在通过windows系统的电脑上写代码,需要将项目上传到GitHub上去.比如在Pycharm上写Django后端,整个项目是一个文件夹的形式,那么怎么才能这个文件夹通过Git命令上传到GitHub上 ...
随机推荐
- EF CodeFirst 使用T4模板
实用等级:★★★★★ 首先,定义一个接口,代表一个领域实体.在定义一个实体集成这个接口,面向接口编程的各种好处就不提了. /// <summary> /// 代表一个领域实体 /// &l ...
- git和小乌龟在windows下安装
一:所需软件 (1):git 下载地址:https://git-scm.com/download (2):TortoiseGit 下载地址:https://tortoisegit.org/downlo ...
- Hyper-V + CentOS7 安装教程(视频)
(双击全屏播放) 一.前言 为什么选择Hyper-V? windowns自带,免费 基础环境 二.虚拟机配置 下载CentOS7镜像 https://www.centos.org/download/ ...
- redis笔记1
存储结构 字符类型 散列类型 列表类型 集合类型 有序集合 可以为每个key设置超时时间: 可以通过列表类型来实现分布式队列的操作 支持发布订阅的消息模式 提供了很多命令与redis进行交互 数据缓存 ...
- 我的第一次diy装机记录——小白的配置篇
工欲善其事,必先利其器 相对于IT人来说,电脑是个好东西,应该是第二个除了手机陪伴我们最长的东西.今年4月份来的杭州,留下了那款陪我征战4年的笔记本,没有电脑,下班后的夜晚索然无味,身心的需求也日渐强 ...
- Python 定时调度
APScheduler APScheduler是基于Quartz的一个Python定时任务框架,实现了Quartz的所有功能,使用起来十分方便.提供了基于日期.固定时间间隔以及crontab类型的任务 ...
- 其他综合-Cobbler无人值守安装系统 CentOS 7
Cobbler 无人值守安装系统 CentOS 7 1.实验描述 1.1 概述 作为运维,在公司经常遇到一些机械性重复工作要做,例如:为新机器装系统,一台两台机器装系统,可以用光盘.U盘等介质安装,1 ...
- K8s集群中设置harbor仓库认证
一,获取harbor的登陆用户名和密码(demo_user/demo_pwd) 二,使用kubectl命令生成secret(不同的namespace要分别生成secret,不共用) kubectl c ...
- BCD解密
#include<stdio.h> int main(void) { int num; scanf_s("%d", &num); printf( * + num ...
- Flask框架之功能详解
1|0浏览目录 配置文件 路由系统 视图 请求相关 响应 模板渲染 session 闪现 中间件 蓝图(blueprint) 特殊装饰器 1|1配置文件 知识点 给你一个路径 "settin ...