admin管理员组文章数量:1530063
import win32con
import win32gui
from pywinauto.application import Application
from cWindow import cWindow
import time
import pyautogui
window_title = u'GIDSAuthTool v2.24'
try:
regex = ".*GIDSAuthTool.*"
cW = cWindow()
cW.find_window_regex(regex)
cW.Maximize()
cW.SetAsForegroundWindow()
app = Application(backend="uia").connect(path=r"C:\\Users\\PENG CAN\Desktop\\授权工具v2.24\\GIDSAuthTool.exe")
# 3.查看一个窗体含有的控件,子窗体,菜单
# print(app[window_title].print_control_identifiers())
# app.window(class_name = window_title).draw_outline(colour ='red')
Gdlg = app.window(title_re=window_title)
# Gdlg.wait("exists ready", timeout=1, retry_interval=3)
except:
app = Application(backend="uia").start("C:\\Users\\PENG CAN\Desktop\\授权工具v2.24\\GIDSAuthTool.exe")
time.sleep(1)
Gdlg = app.window(title_re=window_title)
Gdlg.wait("exists ready", timeout=1, retry_interval=3)
##########################################密码窗口 1stGAC2GAC2019
#print(app.window(title=u"GIDSAuthTool v2.24", auto_id="StartupForm", control_type="Window").exists())
#while(1):
#print(app.window_(title=u"GIDSAuthTool v2.24", class_name='WindowsForms10.Window.8.app.0.141b42a_r9_ad1').exists())
# while(1):
# ()
if (app.window(title=u"GIDSAuthTool v2.24", auto_id="StartupForm", control_type="Window").exists()):
window_title='GIDSAuthTool v2.24'
#3.查看一个窗体含有的控件,子窗体,菜单
#print(app[window_title].print_control_identifiers())
#app.window(class_name = window_title).draw_outline(colour ='red')
Gdlg = app.window(title_re=window_title)
Gdlg.draw_outline(colour="red")
Gdlg.print_control_identifiers()
pyautogui.typewrite(message='GAC2019',interval=0)
Gdlg.print_control_identifiers()
pyautogui.press('enter')
#print(Gdlg.child_window(title="GIDSAuthTool v2.24", auto_id="StartupForm", control_type="Window").exists())
######################2nd 窗口,主界面,#################
if (app.window(title=u"GIDSAuthTool v2.24", auto_id="PinAuthForm", control_type="Window").exists()):
window_title='GIDSAuthTool v2.24'
#3.查看一个窗体含有的控件,子窗体,菜单
#print(app[window_title].print_control_identifiers())
#app.window(class_name = window_title).draw_outline(colour ='red')
Gdlg = app.window_(title_re=window_title)
# Gdlg.wait("exists ready", timeout = 2, retry_interval = 3)
Gdlg.draw_outline(colour="red")
# Gdlg.print_control_identifiers()
#Gdlg.child_window(title="申请码:", auto_id="textBoxApply", control_type="Edit")
Gdlg.child_window(title="申请码:", auto_id="textBoxApply", control_type="Edit").set_edit_text('TJJJJJJJJJJJJJJJJJ4TAVJQIOKPJII6')
#app[window_title].child_window(title="申请码",control_type="Edit").set_edit_text('TJJJJJJJJJJJJJJJJJ4TAVJQIOKPJII6')
#time.sleep(2)
#
# Gdlg.child_window(title="退出(X)",auto_id="btnExit", control_type="Button").click()
Gdlg.child_window(title="清空(C)", auto_id="btnClear", control_type="Button").click()
Gdlg.child_window(title="最小化", control_type="Button").click()
一个将窗口激活的类
import win32gui, win32con
import re, traceback
from time import sleep
class cWindow:
def __init__(self):
self._hwnd = None
def SetAsForegroundWindow(self):
# First, make sure all (other) always-on-top windows are hidden.
# self.hide_always_on_top_windows()
win32gui.SetForegroundWindow(self._hwnd)
def Maximize(self):
win32gui.ShowWindow(self._hwnd, win32con.SW_MAXIMIZE)
def _window_enum_callback(self, hwnd, regex):
'''Pass to win32gui.EnumWindows() to check all open windows'''
if self._hwnd is None and re.match(regex, str(win32gui.GetWindowText(hwnd))) is not None:
self._hwnd = hwnd
def find_window_regex(self, regex):
self._hwnd = None
win32gui.EnumWindows(self._window_enum_callback, regex)
def hide_always_on_top_windows(self):
win32gui.EnumWindows(self._window_enum_callback_hide, None)
def _window_enum_callback_hide(self, hwnd, unused):
if hwnd != self._hwnd: # ignore self
# Is the window visible and marked as an always-on-top (topmost) window?
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowLong(hwnd,
win32con.GWL_EXSTYLE) & win32con.WS_EX_TOPMOST:
# Ignore windows of class 'Button' (the Start button overlay) and
# 'Shell_TrayWnd' (the Task Bar).
className = win32gui.GetClassName(hwnd)
if not (className == 'Button' or className == 'Shell_TrayWnd'):
# Force-minimize the window.
# Fortunately, this seems to work even with windows that
# have no Minimize button.
# Note that if we tried to hide the window with SW_HIDE,
# it would disappear from the Task Bar as well.
win32gui.ShowWindow(hwnd, win32con.SW_FORCEMINIMIZE)
# def main():
# sleep(5)
# try:
# regex = ".*无标题.*"
# cW = cWindow()
# cW.find_window_regex(regex)
# cW.Maximize()
# cW.SetAsForegroundWindow()
# except:
# f = open("log.txt", "w")
# f.write(traceback.format_exc())
# print(traceback.format_exc())
# main()
本文标签: 窗口PythonprintcontrolidentifiersGdlg
版权声明:本文标题:python 取得特定窗口,并激活 Gdlg.print_control_identifiers() 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726538387a1074502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论