![python根据窗口标题找句柄,将窗口前置活动
[编程语言教程]](https://www.zixueka.com/wp-content/uploads/2024/01/1706709672-5dc6d7f991ffa69.jpg)
import time, threading, copy
import win32api, win32con
import win32gui
import win32gui
def zhaojb(aa):
mu=0
jh=[]
hwnd_title = dict()
def get_all_hwnd(hwnd,mouse):
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)})
win32gui.EnumWindows(get_all_hwnd, 0)
for h,t in hwnd_title.items():
if t is not "":
if aa in t:
jh.append(h)
if len(jh)==0:
print("找不到相应的句柄")
else:
return jh
ab=zhaojb("SM")
jbid=ab[0]#有可能找到多个
print(jbid)
win32gui.SetForegroundWindow(jbid)#将相应的窗口前置为活动窗口
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 »
python根据窗口标题找句柄,将窗口前置活动