python-tools-windows/PVZZZB_C1.py

47 lines
1.1 KiB
Python
Raw Normal View History

# 植物大战僵尸v2.2 杂交版辅助
import win32gui #pip install pywin32
import psutil
import win32gui
import win32process
import psutil
def get_visible_windows():
"""获取所有可见窗口的标题和PID"""
results = []
def foreach_window(hwnd, _):
if win32gui.IsWindowVisible(hwnd):
title = win32gui.GetWindowText(hwnd)
if title:
_, pid = win32process.GetWindowThreadProcessId(hwnd)
results.append((title, pid))
return True
win32gui.EnumWindows(foreach_window, None)
return results
def get_window_handle(title):
"""根据窗口标题获取窗口句柄"""
hwnd = win32gui.FindWindow(None, title)
if hwnd == 0:
print("窗口未找到")
else:
print(f"窗口句柄: {hwnd}")
return hwnd
# 调用函数获取所有可见窗口的应用信息
visible_windows = get_visible_windows()
for title, pid in visible_windows:
print(f"窗口标题: {title}, 进程ID: {pid}")
# 假设我们要找的窗口标题是"My Application"
window_title = "植物大战僵尸v2.2 "
get_window_handle(window_title)