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窗口句柄,选择文件和目录的更多相关文章

  1. Unity中调用Windows窗口选择文件

    1.OpenFileName数据接收类,如下: using UnityEngine; using System.Collections; using System; using System.Runt ...

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

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

  3. Unity调用Windows弹框、提示框(确认与否,中文)

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

  4. Unity调用windows系统dialog 选择文件夹

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

  5. windows中操作文件和目录的函数

    1.文件操作函数       CreateFile();//创建或打开文件      ReadFile();//从文件读      WriteFile();//向文件写      SetFilePoi ...

  6. GJM : Unity调用系统窗口选择本地文件

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

  7. Unity调用Windows对话框保存时另存为弹框

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

  8. MT4调用Windows API进行文件读写操作

    /*导入相关函数*/ #import "kernel32.dll" int CreateDirectoryW(string directoryName,int type); int ...

  9. 调用windows的复制文件对话框

    function CopyFileDir(sDirName: String; sToDirName: String): Boolean; var fo: TSHFILEOPSTRUCT; begin ...

随机推荐

  1. oracle数据库之分组查询(转)

    本章内容和大家分享的是数据当中的分组查询.分组查询复杂一点的是建立在多张表的查询的基础之上,(我们在上一节课的学习中已经给大家分享了多表查询的使用技巧,大家可以自行访问:多表查询1  多表查询2)而在 ...

  2. vue路由守卫

    路由守卫 //路由进来之时 beforeRouteEnter(to, from, next) { console.log(this, 'beforeRouteEnter'); // undefined ...

  3. 运行Spark程序的几种模式

    一. local 模式 -- 所有程序都运行在一个JVM中,主要用于开发时测试    无需开启任何服务,可直接运行 ./bin/run-example 或 ./bin/spark-submit 如:  ...

  4. 动手写一个简单版的谷歌TPU

    谷歌TPU是一个设计良好的矩阵计算加速单元,可以很好的加速神经网络的计算.本系列文章将利用公开的TPU V1(后简称TPU)相关资料,对其进行一定的简化.推测和修改,来实际编写一个简单版本的谷歌TPU ...

  5. dshow整体框架前期构思

    主要组成: ------理想在线平台---------- A:网站组成 1.产品方案介绍部分 2.用户注册管理部分 3.模块介绍及购买 4.普通 工单部分,vip在线部分 B:四大平台 1.打分平台 ...

  6. map练习小例题

    "fdgavcbsacdfs" 获取该字符串中,每一个字母出现的次数. 要求打印结果是:a(2)b(1)...; 思路: 对于结果的分析发现,字母和次数之间存在着映射关系.而且这种 ...

  7. CodeForces - 507B - Amr and Pins(计算几何)

    Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r ...

  8. 项目协作管理平台-teambition和tapd--深度体验

    ​ 一.分析目的 通过分析2B产品中的团队协作管理软件的对比分析,用于为公司团队协作软件的选型做产考. 二.竞品归属市场概况 2.1.目标用户群及需求 主要面向企业用户,用于解决企业不同地域以及不同职 ...

  9. HTML5利用FormData对象实现显示进度条的文件上传

    摘自:https://blog.csdn.net/q1056843325/article/details/53759963 自己做是按这个实现的,兼容性还不错 完整简约的解决方案 下面的代码清单是包括 ...

  10. 【踩坑】spring每次请求后session不一样导致无法在服务器保存信息

    根据网上的资料,若想在服务器用session保存一些信息,方法如下: public Xclass Xmethod(HttpServletRequest request, HttpSession ses ...