脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python实现关闭第三方窗口的方法

python实现关闭第三方窗口的方法

2021-07-26 00:22saii Python

今天小编就为大家分享一篇python实现关闭第三方窗口的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

背景

最近在测试一款软件的关闭第三方窗口的功能,感觉实现应该挺简单的。所以就尝试了。由于说它的实现是靠c++实现的,本人对c++实在不在行,但是python的第三方库实际上是封装了一套win32的api的 所以我们还是可以依靠python 来实现这个的。

实现

直接贴代码吧 很简单

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- coding: utf-8 -*-
from win32gui import *
import win32gui
import win32con
from time import sleep
 
def foo(hwnd,mouse):
  global config_contents
  if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
    for content in config_contents:
      ads_info = []
      if not '|' in content :
        continue
      else:
        ads_info = content.split('|')
      if GetClassName(hwnd)==ads_info[1] and GetWindowText(hwnd)==ads_info[0]:
        win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
 
 
config_file = open("C:\\1.txt","r")
config_contents = config_file.readlines()
while 1:
  EnumWindows(foo, 0)
  sleep(0.5)

这里我们是直接读取第三方的配置文件,配置文件的内容就写了 窗口标题|窗口类名 的形式。所以我们就直接判断窗口已经窗口类名是否与配置文件一致,如果一致就发送关闭窗口的命令就可以了。

以上这篇python实现关闭第三方窗口的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq744746842/article/details/50185399

延伸 · 阅读

精彩推荐