博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
打开文件夹
阅读量:6232 次
发布时间:2019-06-21

本文共 2675 字,大约阅读时间需要 8 分钟。

using System;using System.Collections;using System.Collections.Generic;using System.Runtime.InteropServices;using UnityEngine;//unity3d调用win32打开对话框[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct OpenFileName{    public int structSize;    public IntPtr dlgOwner;    public IntPtr instance;    public string filter;    public string customFilter;    public int maxCustFilter;    public int filterIndex;    public string file;    public int maxFile;    public string fileTitle;    public int maxFileTitle;    public string initialDir;  //打开路径     null    public string title;    public int flags;    public short fileOffset;    public short fileExtension;    public string defExt;    public IntPtr custData;    public IntPtr hook;    public string templateName;    public IntPtr reservedPtr;    public int reservedInt;    public int flagsEx;}public class OpenPDF:MonoBehaviour{    [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]    private static extern bool GetOpenFileName([In, Out] OpenFileName ofn);    OpenFileName ofn;    void Start()    {        ofn = new OpenFileName();        ofn.structSize = Marshal.SizeOf(ofn);        ofn.filter = "PDF文件(*.pdf)\0*.pdf;";        ofn.file = new string(new char[256]);        ofn.maxFile = ofn.file.Length;        ofn.fileTitle = new string(new char[64]);        ofn.maxFileTitle = ofn.fileTitle.Length;        ofn.initialDir = "C:\\";        ofn.title = "打开课件";        ofn.defExt = "PDF";        ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;   //OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR        }    public void OpenFile()    {        StartCoroutine(SelectFile());    }    IEnumerator SelectFile()    {        yield return 1;        List
fliePath = GetFilePath(); for (int i = 0; i < fliePath.Count; i++) { Debug.Log(fliePath[i]); } } ///
/// 支持同时选择多个文件 /// ///
public List
GetFilePath() { List
fliePath = new List
(); if (GetOpenFileName(ofn)) { string[] filePath = ofn.file.Split('\0');// ‘\0’可表示C++中的NULL for (int i = 0; i < filePath.Length; i++) { if (!string.IsNullOrEmpty(filePath[i])&&i!=0) { fliePath.Add(filePath[0]+ filePath[i]); } } } else { Debug.Log("取消选择"); } return fliePath; }}

 

转载于:https://www.cnblogs.com/Jason-c/p/10621150.html

你可能感兴趣的文章
百度内页排名的第二个秘诀
查看>>
python--集合概念和实战(二)
查看>>
Android开发环境错误处理
查看>>
高性能的开源http加速器Varnish
查看>>
MySQL执行计划解析
查看>>
Mysql Date 函数
查看>>
博客分类导航
查看>>
实战HMM-Viterbi角色标注地名识别
查看>>
Delphi 与 DirectX 之 DelphiX(58): TDIB.DoTile();
查看>>
如何打开记事本并显示指定内容 - 回复 "苦苦苦" 的问题
查看>>
android4.x新特征总结
查看>>
TClientDataSet[22]: 数组字段与 ObjectView
查看>>
Oracle Data Guard(1)
查看>>
我的友情链接
查看>>
实现iOS图片等资源文件的热更新化(三):动态的资源文件夹
查看>>
OK6410-使用DirecetFB支持Qt4.7.0
查看>>
python获取linux系统信息、性能阀值、短信网关发送的例子
查看>>
微信公众号实现回复图文消息
查看>>
单点登录方案的比较和选择
查看>>
Android 涂鸦最佳实践
查看>>