zoukankan      html  css  js  c++  java
  • Unity 3D调用System.Windows.Forms.dll 提示 could not register the window class ,win32 error 0

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using System.IO; 
    using UnityEngine.UI;
    using System;
    using System.Threading;
    using System.Linq;
    
    public class WindowFormsShowModelPath : MonoBehaviour
    { 
        string str_path = "";
        string modelname = "";
    
        private void Start()
        { 
            OopsWindowsThreadStart(); 
    
            System.Windows.Forms.MessageBox.Show("start..."); 
    
            ThreadRunning = false;
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.P))
            {
                OopsWindowsThreadStart();
    
                System.Windows.Forms.OpenFileDialog Dialog = new System.Windows.Forms.OpenFileDialog();
                Dialog.Filter = "文件(*.FBX)|*.FBX";
    
                if (Dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    str_path = Path.GetDirectoryName(Dialog.FileName); 
    
                    modelname = Path.GetFileNameWithoutExtension(Dialog.FileName); 
    
                    System.Windows.Forms.MessageBox.Show(str_path + "\" + modelname); 
                }
                else
                {   
                    str_path = "";
                    modelname = "";
                    System.Windows.Forms.MessageBox.Show(null...); 
                }
                ThreadRunning = false;
            }
        }
    
    
        #region Close Window Oops
    
        private System.Threading.Thread CloseOops;
        private bool ThreadRunning = true;
        private void OopsWindowsThreadStart()
        {
            CloseOops = new System.Threading.Thread(ClearOopsWindows) { IsBackground = true };
            ThreadRunning = true;
            CloseOops.Start();
        }
        private void ClearOopsWindows()
        {
            while (ThreadRunning)
            {
                FindAndCloseWindow();
            }
        }
    
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE = 0xF060;
    
        public static void FindAndCloseWindow()
        {
            IntPtr lHwnd = FindWindow(null, "Oops");
            if (lHwnd != IntPtr.Zero)
            {
                SendMessage(lHwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
            }
        }
        #endregion
    }
    

      

    支持个人观看使用,如商用或转载,请告知! -----萧朗(QQ:453929789 Email:xiaolang_xl@sina.com)
  • 相关阅读:
    async
    subing用法
    vue中子组件调用父组件的方法
    Python—创建目录
    Python—访问限制
    Python—实例方法,实例数据(类属性,实例属性)
    Python—对象,类
    tail命令
    head命令
    pwd命令
  • 原文地址:https://www.cnblogs.com/XiaoLang0/p/14592813.html
Copyright © 2011-2022 走看看