• 关闭ShowDialog的模态窗口


     [DllImport("user32.dll")]
            private static extern IntPtr FindWindow(string a, string b);
    
            [DllImport("user32.dll")]
            private static extern IntPtr PostMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
    
       Timer timer = new Timer();
                timer.Tick += (obj, arg) =>
                    {
                        //1、尝试关闭ColorDialog
                        IntPtr ptr1 = FindWindow(null, "颜色");
                        if (ptr1 != IntPtr.Zero)
                        {
                            PostMessage(ptr1, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("ColorDialog已关闭");
                        }
                        //2、尝试关闭FolderBrowserDialog
                        IntPtr ptr2 = FindWindow(null, "浏览文件夹");
                        if (ptr2 != IntPtr.Zero)
                        {
                            PostMessage(ptr2, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("FolderBrowserDialog已关闭");
                        }
                        //3、尝试关闭FontDialog
                        IntPtr ptr3 = FindWindow(null, "字体");
                        if (ptr3 != IntPtr.Zero)
                        {
                            PostMessage(ptr3, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("FontDialog已关闭");
                        }
                        //4、尝试关闭OpenFileDialog
                        IntPtr ptr4 = FindWindow(null, "打开");
                        if (ptr4 != IntPtr.Zero)
                        {
                            PostMessage(ptr4, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("OpenFileDialog已关闭");
                        }
                        //5、尝试关闭SaveFileDialog
                        IntPtr ptr5 = FindWindow(null, "另存为");
                        if (ptr5 != IntPtr.Zero)
                        {
                            PostMessage(ptr5, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("SaveFileDialog已关闭");
                        }
                        //6、尝试关闭MessageBox
                        IntPtr ptr6 = FindWindow(null, "测试消息");
                        if (ptr6 != IntPtr.Zero)
                        {
                            PostMessage(ptr6, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("MessageBox已关闭");
                        }
                        //7、尝试关闭自定义窗口(Show)
                        IntPtr ptr7 = FindWindow(null, "自定义窗口(Show)");
                        if (ptr7 != IntPtr.Zero)
                        {
                            PostMessage(ptr7, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("自定义窗口(Show)已关闭");
                        }
                        //8、尝试关闭自定义窗口(ShowDialog)
                        IntPtr ptr8 = FindWindow(null, "自定义窗口(ShowDialog)");
                        if (ptr8 != IntPtr.Zero)
                        {
                            PostMessage(ptr8, 0x0010, IntPtr.Zero, IntPtr.Zero);
                            SetInfoBar("自定义窗口(ShowDialog)已关闭");
                        }
                    };
                timer.Interval = 5000;
                timer.Enabled = true;
                timer.Start();
    
  • 相关阅读:
    用 Python 脚本实现对 Linux 服务器的监控
    linux系统常用命令
    一小时学会用Python Socket 开发可并发的FTP服务器!!
    Python获取程序运行目录和脚本目录
    哪些情况会导致OOM
    如何查看端口状态
    wait(),sleep(),notify(),join()
    cookie和session的区别与会话跟踪技术
    TCP的可靠性
    OSI和TCP/IP的对比+IP地址分类
  • 原文地址:https://www.cnblogs.com/xiangxiong/p/6477653.html
Copyright © 2020-2023  润新知