user32.dll是Windows用户界面相关应用程序接口,用于包括Windows处理,基本用户界面等特性,如创建窗口和发送消息。

[DllImport("user32.dll", EntryPoint = "FindWindow")]
    public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
    public  static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", EntryPoint = "SendMessage")]
    public  static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

/// <summary>
        /// 是否找到窗口 是true ,否false
        /// </summary>
        /// <param name="title">窗口标题</param>
        /// <param name="btnName">按钮名称</param>
        private bool  closeWindows_User32(string title,string btnName)
        {
            bool b = false;
            const int BM_CLICK = 0xF5;
            const int WM_CLOSE = 0x0010;
            IntPtr maindHwnd = DataAccess.FindWindow(null, title); //程序句柄
            if (maindHwnd != IntPtr.Zero)
            {
                IntPtr childHwnd = DataAccess.FindWindowEx(maindHwnd, IntPtr.Zero, null, btnName); //获得按钮的句柄
                if (childHwnd != IntPtr.Zero)
                {
                    DataAccess.SendMessage(childHwnd, BM_CLICK, 0, 0); //发送点击按钮的消息
                    b = true;
                }
                else
                {
                    b = false;
                }
            }
            else
            {
                b = false;
            }
            return b;
        }
        /// <summary>
        /// 关闭所有不必要的窗口 (如果你的程序调用其它程序时弹窗口,你弹出的窗口捕捉到,用此方法自动关闭它)
        /// </summary>
        /// <returns></returns>
        private bool CloseUser32()
        {
            bool b = false;
            while (closeWindows_User32("Macromedia FlashPaper", "确定"))
            {
                closeWindows_User32("Macromedia FlashPaper", "确定");
            }
            while (closeWindows_User32("Microsoft Office Word", "是(&Y)"))
            {
                closeWindows_User32("Microsoft Office Word", "是(&Y)");
            }
            while (closeWindows_User32("Microsoft Office Word", "确定"))
            {
                closeWindows_User32("Microsoft Office Word", "确定");
            }
            while (closeWindows_User32("文件正在使用", "确定"))
            {
                closeWindows_User32("文件正在使用", "确定");
            }
            while (closeWindows_User32("FlashPaper打印机错误。", "确定"))
            {
                closeWindows_User32("FlashPaper打印机错误。", "确定");
            }
            while (closeWindows_User32("另存为", "取消"))
            {
                closeWindows_User32("另存为", "取消");
            }
            while (closeWindows_User32("Microsoft Office Word", "打开(&O)"))
            {
                closeWindows_User32("Microsoft Office Word", "打开(&O)");
            }
            //if (closeWindows_User32("FlashPaper打印机错误。", "确定") == false && closeWindows_User32("Microsoft Office Word", "是(&Y)") == false && closeWindows_User32("文件正在使用", "确定") == false)
            //{
            //    b = true;
            //}
         
            
          
            return b;
        }

user32.dll接口 捕捉windows信息窗口,和关闭信息窗口相关推荐

  1. [原创]关于打开新窗口和关闭老窗口的2个方法!

    第1种方法 如当前要打开的窗口为about.htm     <script language =javascript >          function openwin()       ...

  2. python怎么打开一个窗口_python – 使按钮一次只打开一个窗口(通过关闭Toplevel窗口启用按钮)...

    我希望NewWinButton一次只创建一个新窗口,这意味着如果 if NewWin.winfo_exists() == 1: NewWinButton.config(state='disabled' ...

  3. python关闭当前窗口_如何打开一个新窗口并关闭当前窗口?

    我想问一下,当我在标题中写到,如何打开一个新窗口并(完全)关闭当前窗口?在 有两个.py文件.它们彼此独立,也就是说,它们都可以独立运行.在 在我的app.py有一个按钮.如果单击该按钮,我希望关闭当 ...

  4. 2.6 子窗口赋值给父窗口并关闭子窗口 我的程序猿之路:第十六章

    <s:textfield id="innovationName" cssClass="txt validate[maxSize[50]]"title=&q ...

  5. C#通过Windows API捕获窗,获取窗口文本(FindWindow、GetWindowText),附录:Windows窗口消息大全、Windows API大全

    文章目录 一.前言 二.使用Spy++工具分析窗口 三.C#通过Windows API捕获窗口,获取窗口文本 四.附录:Windows窗口消息 五.Windows API大全 1.API之网络函数 2 ...

  6. C# 通过窗口标题关闭窗口和弹出窗口的进程

    最近闲来无事玩玩游戏,这游戏有个毛病就是不定时掉线,每次掉线都不知道,所以浪费了大把时间. 作为C#初学者这我能忍么,写个软件监控一下掉线,顺便学习历练一下. 搜遍所有代码站点也没有找到符合自己需求的 ...

  7. window.open window.showModelDialog 打开一个新窗口/子窗口中调用父窗口的方法

    window.open 只打开一个窗口是将 oNewWindow   =   window   .   open   (   sURL   ,   sName   ,   sFeatures   , ...

  8. 关闭子窗口父窗口刷新

    一.方法一:使用window.open()方法. 在父窗口中的html代码: <a class="btn btn-primary "  id="addnews&qu ...

  9. java 父窗口关闭_javascrpt控制父窗口关闭,子窗口也关闭(转)

    var__winRoot__=top||parent||window;//祖先窗口对象var__winParent__=__winRoot__;//父窗口对象(默认为祖先窗口)var__winTree ...

最新文章

  1. linux 大量的TIME_WAIT解决办法
  2. AI服务器的设计与实现
  3. (linux中alias的用法)给一些常用的长命令取别名
  4. Socket 基础解析使用ServerSocket建立聊天服务器
  5. Python3 数据结构:列表List中的方法
  6. C++语法:构造函数以及析构函数
  7. SQL Server事务日志备份,截断和缩减操作
  8. MongoDB DBA 实践2-----MongoDB CRUD操作
  9. Byobu(tmux)的使用与定制
  10. 区块链共识算法的分类 POW POS DPOS PBFT的区别
  11. 第九章(三)多阶段决策问题
  12. 力扣刷题思考:347. 前 K 个高频元素
  13. 团队开发如何评估工作量
  14. 鹿先森博客原先森博客(sey.ink)
  15. Is the American Dream Really Dead?
  16. 香港云服务器网站打开缓慢,香港云服务器搭建的网站卡慢怎么办?火星直播
  17. 一些在线编程练习或调试网站
  18. Python GUI编程之PyQt5入门到实战
  19. java注解看这一篇就够了
  20. python在日常工作中的具体应用_python在实际工作中的应用有哪些

热门文章

  1. 分享腾讯官方二维码生成接口地址
  2. 对比学习系列(四)---BYOL
  3. Ubuntu20.04安装打印机
  4. 在MOSS 2007中自定义DataView Webpart的数据显示样式
  5. codeblock主题颜色配置
  6. 程序员修炼之道(通俗版)——第一章
  7. 电大计算机基础上机考试题库,中央电大计算机基础考试题库大全
  8. 中国需要多少个PPG?
  9. 测试mysql连接服务器,配置云服务器的mysql连接,navicat测试远程连接
  10. 维修服务行业薪酬体系设计案例