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. android实现简单计算器

    前台代码如下 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  2. Python学习笔记(快捷键)

    增加多行缩进: Ctrl + ]  (右中括号) 减少多行缩进:Ctrl + [  (左中括号) 添加多行注释:Alt + 3 取消多行注释:Alt + 4 在Python Shell里重复上一条命令 ...

  3. Oracle GoldenGate部署系列

    在之前,为了某个项目,研究ogg 如何安装部署,已经对接大数据产品. 因为网上的很多资料都讲得不仔细,或者是版本对应不上,所以在部署时,遇到了非常多的困难. 作者根据自己的经验,录制了OGG整套部署和 ...

  4. CentOS 7 部署 nginx-1.14.2

    参考:http://www.linuxe.cn/post-168.html 链接:https://pan.baidu.com/s/1NzHIY7mYgHJ6yMF_rdd0ZQ 提取码:n8o9 下载 ...

  5. SQL SERVER Study

    1. SQL SERVER Install    可以免费试用天.最新的是2014版本.   2. Attach, Detach 可以添加或去掉已有的数据库文件.     数据库文件的格式是: .md ...

  6. luogu P2731 骑马修栅栏 Riding the Fences

    入度为奇数的点,搜他. 最好邻接矩阵... #include<cstdio> #include<iostream> #define R register int using n ...

  7. HDU-1068-GirlsandBoys(最大独立集,二分图匹配)

    链接:https://vjudge.net/problem/HDU-1068#author=0 题意: 学校对n个学生(男女都有)进行的调查了,发现了某些学生暗生情愫,现在需要你选出一个最大的集合,这 ...

  8. 洛谷P2664 树上游戏

    https://www.luogu.org/problemnew/show/P2664 #include<cstdio> #include<algorithm> #includ ...

  9. mirror与repository的关系

    mirror与repository的关系 mirror管理的两个repository的关系,本来是访问repoA, 但是repoB mirrorOf repoA, 就会去repoB上去找. https ...

  10. openstack修改增加网卡及更改ip

        1.neutron更改及mysql数据库更改网卡及ip:     neutron port-update ae22c84b-22a9-4618-b046-1eb61379bcea  --all ...