Unity3d:代码控制打开windows窗体

  1. // ========================================================
  2. // Module:打开窗体类型
  3. // Author:tan 
  4. // Time:2020/07/26 11:38:38
  5. // ========================================================
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Runtime.InteropServices;
  10. using UnityEngine;
  11. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  12. public class OpenFileName
  13. {
  14.     public int structSize = 0;
  15.     public IntPtr dlgOwner = IntPtr.Zero;
  16.     public IntPtr instance = IntPtr.Zero;
  17.     public String filter = null;
  18.     public String customFilter = null;
  19.     public int maxCustFilter = 0;
  20.     public int filterIndex = 0;
  21.     public String file = null;
  22.     public int maxFile = 0;
  23.     public String fileTitle = null;
  24.     public int maxFileTitle = 0;
  25.     public String initialDir = null;
  26.     public String title = null;
  27.     public int flags = 0;
  28.     public short fileOffset = 0;
  29.     public short fileExtension = 0;
  30.     public String defExt = null;
  31.     public IntPtr custData = IntPtr.Zero;
  32.     public IntPtr hook = IntPtr.Zero;
  33.     public String templateName = null;
  34.     public IntPtr reservedPtr = IntPtr.Zero;
  35.     public int reservedInt = 0;
  36.     public int flagsEx = 0;
  37. }
     
  38. // ========================================================
  39. // Module:打开窗体测试
  40. // Author:tan 
  41. // Time:2020/07/26 11:36:01
  42. // ========================================================
  43. using System.Collections;
  44. using System.Collections.Generic;
  45. using UnityEngine;
  46. using UnityEngine;
  47. using System.Collections;
  48. using System;
  49. using System.Runtime.InteropServices;
  50. public class DllTest
  51. {
  52.     [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
  53.     public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);
  54.     public static bool GetOpenFileName1([In, Out] OpenFileName ofn)
  55.     {
  56.         return GetOpenFileName(ofn);
  57.     }
  58. }

 

  1. OpenFileName ofn = new OpenFileName();
  2.             ofn.structSize = Marshal.SizeOf(ofn);
  3.             ofn.filter = "All Files\0*.*\0\0";
  4.             ofn.file = new string(new char[256]);
  5.             ofn.maxFile = ofn.file.Length;
  6.             ofn.fileTitle = new string(new char[64]);
  7.             ofn.maxFileTitle = ofn.fileTitle.Length;
  8.             ofn.initialDir = Application.dataPath;//默认路径
  9.             ofn.title = "更好图片窗体";
  10.             ofn.defExt = "JPG";//显示文件的类型
  11.             //注意 一下项目不一定要全选 但是0x00000008项不要缺少
  12.             ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值