python win32gui 遍历所有窗口 根据标题获取句柄 关闭这个标题的窗口 遍历窗口 获取句柄

2023-05-16

首先遍历所有窗口句柄,再提取有标题的窗口

符合条件的,关闭窗口

2023年3月6日 星期一 更新
不管是否可见,都关掉

 def winEnumHandler(hwnd, ctx):
            #if win32gui.IsWindowVisible(hwnd):
            if 'License Information' in win32gui.GetWindowText(hwnd):
                print(hwnd, win32gui.GetWindowText(hwnd))
                win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

        win32gui.EnumWindows(winEnumHandler, None)
        def winEnumHandler(hwnd, ctx):
            if win32gui.IsWindowVisible(hwnd):
                if 'License Information' in win32gui.GetWindowText(hwnd):
                    print(hwnd, win32gui.GetWindowText(hwnd))
                    win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

        win32gui.EnumWindows(winEnumHandler, None)

参考
https://stackoverflow.com/questions/55547940/how-to-get-a-list-of-the-name-of-every-open-window

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from win32gui import *
import win32con, os, time, subprocess

p = subprocess.Popen(r"E:\code\dock_project\tampermonkey\run.bat", creationflags=subprocess.CREATE_NEW_CONSOLE )
time.sleep(30)

title_list = []
def foo(hwnd,mouse):
    titles = {}
    # 去掉下面这句就所有都输出了,但是我不需要那么多
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles['title'] = GetWindowText(hwnd)
        titles['hwnd'] = hwnd
        # titles.add(GetWindowText(hwnd))
    if titles:
        if titles.get('title') == 'ping baidu':
            pass
            title_list.append(titles)


EnumWindows(foo, 0)

print(title_list)
for title in title_list:
    print(title.get('title'))
    hwnd = title.get('hwnd')
    print(hwnd)
    #关闭窗口
    PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python win32gui 遍历所有窗口 根据标题获取句柄 关闭这个标题的窗口 遍历窗口 获取句柄 的相关文章

随机推荐

  • 计算机I/O原理

    cpu通过IO命令控制设备 xff0c cpu对设备的控制仅仅可以到达设备控制器 xff0c 无法直接控制设备 设备无法直接和cpu通信 xff0c 设备控制器通过中断机制向cpu反馈信息 即这个一个模型 CPU IO指令 gt 设备控制器
  • 计算机的I/O端口地址表

    PC的I O端口地址表 xff08 I O端口地址表 xff09 http tieba baidu com f kz 61 16042340 I O端口地址表 PC只用了10位地址线 A0 A9 进行译码 xff0c 其寻址的范围为0H 3
  • 利用pthread进行数组求和

    POSIX thread 简称为pthread xff0c Posix线程是一个 POSIX 标准线程 利用多线程可以提高运算速度 利用pthread进行数组求和的程序如下 xff1a include lt stdio h gt inclu
  • 字符串的全排列程序

    include lt iostream gt include lt cstring gt using namespace std void swap char str int i int j char tmp 61 str i str i
  • Google面试总结

    分享 Google面试总结 来源 xff1a 王冠中的日志 终于把Google的面试给搞完了 xff0c 感觉可以算是Tech Interview的顶峰了 这里主要写一下大概流程和内容 xff0c 给大家以后interview一个参考 G的
  • sql server中的注释快捷键

    sql server中的注释快捷键 注释 xff1a Ctrl 43 K Ctrl 43 C xff08 按住Ctrl 然后K C xff09 取消注释 xff1a Ctrl 43 K Ctrl 43 U xff08 按住Ctrl 然后K
  • SpringMVC统一异常处理(返回异常数据而不是跳转到某个页面的方法)

    关于SpringMVC统一异常处理的问题 xff0c 网搜一大把 网上搜的关于如何进行统一异常处理不外乎如下三种方式 xff1a Spring MVC处理异常有3种方式 xff1a 1 使用Spring MVC提供的简单异常处理器Simpl
  • Entity Framework 6.0 Code First

    目录 一 安装 Entity Framework1 安装安 EF NuGet 包2 从包管理器控制台安装 二 创建模型三 创建上下文四 读取和写入数据五 迁移 一 安装 Entity Framework 新建基于 Net Framework
  • C#中的json格式字符串解析

    如题 xff0c 根据json字符串的难易程度 xff0c C 提供的对应解析方法也不同 xff0c 现做简单的归类总结 xff1a 一 xff0c 对于最简单的json类型 xff0c 可以使用如下方法 1 使用JsonReader类 x
  • 12本Python书籍推荐

    Python是用于各种任务和领域的优秀编程语言之一 Python的用户友好性 xff0c 高级特性以及对简单性和增强代码可读性的强调使其成为全球许多开发人员的理想选择 诸如此类的功能使应用程序开发 xff0c 数据科学 xff0c 人工智能
  • VirtualBox因为强制关机,第二天启动获取 VirtualBox COM 对象失败。亲测解决方案

    唯一一次手滑就点了仍要关机 第二天小盒子直接不给启动了 获取 VirtualBox COM 对象失败 应用程序将被中断 Completely failed to instantiate CLSID VirtualBox RPC E SERV
  • Ubuntu/Deepin登陆界面输入密码无限循环进不了桌面的处理方法

    问题 xff1a 今天有用户在不知道做了什么操作 xff0c 在输入密码后就一直停在那无法登陆GUI界面了 本以为是root密码不对 xff0c 尝试了恢复root密码操作无效 然后网上搜了一堆处理方法 切换tty命令界面 因为图形界面卡死
  • 基于Linux的Microsoft Edge浏览器

    关于Edge 近年来随着浏览器市场的变革 xff0c IE的地位越来越低 xff0c 终于微软在Windows 10操作系统中推出了全新的Edge浏览器 xff0c 但是在刚开始的阶段Edge浏览器并不友好 xff0c 很多人都无法适应Ed
  • OpenEuler华为欧拉系统安装教程及联网配置

    OpenEuler简介 openEuler是一款开源操作系统 当前openEuler内核源于Linux xff0c 支持鲲鹏及其它多种处理器 xff0c 能够充分释放计算芯片的潜能 xff0c 是由全球开源贡献者构建的高效 稳定 安全的开源
  • 在Ubuntu中安装Chrome浏览器

    Chrome 简介 Google Chrome是由Google开发的一款设计简单 高效的Web浏览工具 Google Chrome的特点是简洁 快速 GoogleChrome支持多标签浏览 xff0c 每个标签页面都在独立的 沙箱 内运行
  • tomcat 报错 org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method manageApp

    报错 xff1a Caused by java lang IllegalArgumentException More than one fragment with the name log4j was found This is not l
  • Chrome拓展开发之manifest.json

    Chrome拓展开发 Chrome拓展开发之manifest json常用参数manifest编写 Chrome拓展开发之manifest json manifest json是必须存在的 xff0c 它用来配置所有和插件相关的参数 用Ch
  • -bash: *: command not found解决办法

    今天在linux上配置环境时出现 bash command not found错误 xff0c 网上找了一下 xff0c 方法如下 xff1a 如输入 ls 出现 bash ls command not found ipconfig 出现
  • 遍历句柄所有子窗口 win32gui.EnumChildWindows

    The handler span class token keyword is span indeed called span class token keyword for span each child span class token
  • python win32gui 遍历所有窗口 根据标题获取句柄 关闭这个标题的窗口 遍历窗口 获取句柄

    首先遍历所有窗口句柄 xff0c 再提取有标题的窗口 符合条件的 xff0c 关闭窗口 2023年3月6日 星期一 更新 不管是否可见 xff0c 都关掉 span class token keyword def span span cla