1 回答
TA贡献1824条经验 获得超8个赞
在做了更多研究后,我遇到了 DWM,DWM 提供了一种可以查找窗口属性以从中获取更多信息的方法。其中一个选项称为斗篷,它可以很好地过滤掉所有窗口中的后台进程。我的代码如下。
def winEnumHandler(hwnd, ctx):
# DWM
isCloacked = ctypes.c_int(0)
ctypes.WinDLL("dwmapi").DwmGetWindowAttribute(hwnd, 14, ctypes.byref(isCloacked), ctypes.sizeof(isCloacked))
# Variables
title = win32gui.GetWindowText(hwnd)
# Append HWND to list
if win32gui.IsWindowVisible(hwnd) and title != '' and isCloacked.value == 0:
app = ApplicationWindow(hwnd, title)
applications.append(app)
DWM 过滤:此处
从该链接获取更多信息后,最终解决方案显示了所有真实的窗口:
class TITLEBARINFO(ctypes.Structure):
_fields_ = [("cbSize", ctypes.wintypes.DWORD), ("rcTitleBar", ctypes.wintypes.RECT),
("rgstate", ctypes.wintypes.DWORD * 6)]
def winEnumHandler(hwnd, ctx):
# Title Info Initialization
title_info = TITLEBARINFO()
title_info.cbSize = ctypes.sizeof(title_info)
ctypes.windll.user32.GetTitleBarInfo(hwnd, ctypes.byref(title_info))
# DWM Cloaked Check
isCloaked = ctypes.c_int(0)
ctypes.WinDLL("dwmapi").DwmGetWindowAttribute(hwnd, 14, ctypes.byref(isCloaked), ctypes.sizeof(isCloaked))
# Variables
title = wg.GetWindowText(hwnd)
# Append HWND to list
if wg.IsWindowVisible(hwnd) and title != '' and isCloaked.value == 0:
if not (title_info.rgstate[0] & wc.STATE_SYSTEM_INVISIBLE):
app = ApplicationWindow(hwnd, title)
applications.append(app)
任何简化请告诉我!谢谢!
添加回答
举报