1 回答

TA貢獻1824條經(jīng)驗 獲得超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)
任何簡化請告訴我!謝謝!
添加回答
舉報