Unity调用Windows窗口句柄,选择文件和目录
T:2019-6-25 10:06:59
C:Scatt Kang
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
[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 WindowsExplorer
{
[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);
/// <summary>
/// 调用WindowsExploer 并返回所选文件夹路径
/// </summary>
/// <param name="dialogtitle">打开对话框的标题</param>
/// <returns>所选文件夹路径</returns>
public static string GetPathFromWindowsExplorer(string dialogtitle = "请选择下载路径" )
{
string res;
OpenDialogDir ofn2 = new OpenDialogDir();
ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
ofn2.lpszTitle = dialogtitle;// 标题
ofn2.ulFlags = 0x00000040; // 新的样式,带编辑框
IntPtr pidlPtr = WindowsExplorer.SHBrowseForFolder(ofn2);
char[] charArray = new char[2000];
for (int i = 0; i < 2000; i++)
charArray[i] = '\0';
WindowsExplorer.SHGetPathFromIDList(pidlPtr, charArray);
res = new String(charArray);
res = res.Substring(0, res.IndexOf('\0'));
return res;
}
}
Unity调用Windows窗口句柄,选择文件和目录的更多相关文章
- Unity中调用Windows窗口选择文件
1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...
- Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug
问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...
- Unity调用Windows弹框、提示框(确认与否,中文)
Unity调用Windows弹提示框 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- Unity调用windows系统dialog 选择文件夹
#region 调用windows系统dialog 选择文件夹 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public ...
- windows中操作文件和目录的函数
1.文件操作函数 CreateFile();//创建或打开文件 ReadFile();//从文件读 WriteFile();//向文件写 SetFilePoi ...
- GJM : Unity调用系统窗口选择本地文件
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- Unity调用Windows对话框保存时另存为弹框
Unity开发VR之Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- MT4调用Windows API进行文件读写操作
/*导入相关函数*/ #import "kernel32.dll" int CreateDirectoryW(string directoryName,int type); int ...
- 调用windows的复制文件对话框
function CopyFileDir(sDirName: String; sToDirName: String): Boolean; var fo: TSHFILEOPSTRUCT; begin ...
随机推荐
- Search index
问题:查找字符串b在a中的起始位置,如果b不为a的子串,则返回-1 示例: 输入:a = "well", b = "el" 输出:1 输入:a=" ...
- Noip2016day2 组合数问题problem
题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...
- cogs 721. [SDOI2007] 线性方程组
721. [SDOI2007] 线性方程组 ★★ 输入文件:gaess.in 输出文件:gaess.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 已知 n 元 ...
- 剑指Offer的学习笔记(C#篇)-- 矩形覆盖
题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 一 . 解题思路 这个貌似就是普通的跳台阶问题. 二 . 代 ...
- django更换数据库时提示"django.db.utils.InternalError: (1366, "Incorrect string value: '\\xE7\\x94\\xA8\\xE6\\x88\\xB7' for column 'name' at row 1")"
问题提出 昨天在运行django时,初始化使用的是自带的数据库,后来更换mysql数据库,数据库同步之后,打开mysql无法添加数据,插入数据时,提示django.db.utils.InternalE ...
- python序列化模块 json&&pickle&&shelve
#序列化模块 #what #什么叫序列化--将原本的字典.列表等内容转换成一个字符串的过程叫做序列化. #why #序列化的目的 ##1.以某种存储形式使自定义对象持久化 ##2.将对象从一个地方传递 ...
- 长春理工大学第十四届程序设计竞赛(重现赛)J.Printout
链接:https://ac.nowcoder.com/acm/contest/912/J 题意: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字社,小r一看价格:总打印页数 ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- php:判断 是否开启 SSL,CURL,ZIP,GD2,MYSQL,是否安装MEMCACHED
对于php的开发环境,通常需要去先判断下一些扩展和服务时不时已经可用~ 看过的欢迎拍砖,给意见~~ <?php /** * 判断 是否开启 SSL,CURL,ZIP,GD2,MYSQL,是否安装 ...
- hadoop分布式存储(1)-hadoop基础概念
hadoop是一种用于海量数据存储.管理.分析的分布式系统.需要hadoop需要储备一定的基础知识:1.掌握一定的linux操作命令 2.会java编程.因此hadoop必须安装在有jdk的linux ...