環境:python3.6+win7
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import win32gui
from win32.lib import win32con
from win32gui import *
#設置無重複的集
titles = set()
def foo(hwnd,mouse):
#判斷是不是窗口、是不是可用的、是不是可見的
if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
#把得到的結果賦值給a
a=win32gui.GetWindowText(hwnd)
#打出
print(win32gui.GetWindowText(hwnd))
#不爲空時
if a!='':
#當'Program Manager'不在a內時:
if 'Program Manager' not in a:
if '開始' not in a:
if '管理員' not in a:
#關閉窗口
win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
#最小化窗口
#win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
#把所有的窗口添加到titles集內
titles.add(GetWindowText(hwnd))
# 將軟件窗口置於最前
#win32gui.SetForegroundWindow(hwnd)
if __name__ == '__main__':
#枚舉所有窗體,同時調用foo函數
EnumWindows(foo, 0)
lt = [t for t in titles if t]
lt.sort()
for t in lt:
print(t)
以上代碼的缺點:
無法關閉“360安全衛士”彈出的廣告窗口!
誰有沒有辦法搞定“360安全衛士”的彈出窗口廣告?太噁心了,我寧可付費,也不要廣告!
懇請“360安全衛士”推出付費和免費兩個版本吧!拜託了!
轉載:
https://www.jb51.net/article/62140.htm
http://blog.sina.com.cn/s/blog_3fe961ae0102uzh8.html
參考:
http://www.cnblogs.com/klb561/p/9392560.html
https://www.programcreek.com/python/example/10639/win32gui.EnumWindows
https://www.2cto.com/kf/201605/506365.html