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()