def save_file():
import win32con
import win32gui
target_path = r'C:\Users\administered\Desktop\新建文件夹\xxxx.html'
target_path = r'C:\Users\administered\Desktop\9315.pdf'
hwnd = win32gui.FindWindow("#32770", "另存为") # 对话框
# 输入文件名
a1 = win32gui.FindWindowEx(hwnd, None, "DUIViewWndClassName", None)
a2 = win32gui.FindWindowEx(a1, None, "DirectUIHWND", None)
a3 = win32gui.FindWindowEx(a2, None, "FloatNotifySink", None)
a4 = win32gui.FindWindowEx(a3, None, "ComboBox", None)
hwnd_filename = win32gui.FindWindowEx(a4, None, "Edit", None)
win32gui.SendMessage(hwnd_filename, win32con.WM_SETTEXT, None, target_path)
# 点击保存方式1
button = win32gui.FindWindowEx(hwnd, 0, 'Button', None) # 确定按钮Button
win32gui.SendMessage(hwnd, win32con.WM_COMMAND, 1, button) # 按button
# 点击保存方式2
# hwnd_save = win32gui.FindWindowEx(hwnd,None,"Button",None)
# win32gui.PostMessage(hwnd_save, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
# win32gui.PostMessage(hwnd_save, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
def read_file():
import win32con
import win32gui
target_path = r'C:\Users\administered\Desktop\9315.pdf'
title = "打开"
dialog = win32gui.FindWindow("#32770", title) # 一级窗口
ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, "ComboBoxEx32", None) # 二级
comboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, "ComboBox", None) # 三级
# 编辑按钮
edit = win32gui.FindWindowEx(comboBox, 0, "Edit", None) # 四级
# 打开按钮
button = win32gui.FindWindowEx(dialog, 0, "Button", "打开( & O)") # 四级
# 往编辑当中,输入文件路径 。
win32gui.SendMessage(edit, win32con.WM_SETTEXT, None, target_path) # 发送文件路径
win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button) # 点击打开按钮
python 打开文件窗口和另存为文件窗口,win32con,win32gui
于 2024-06-12 10:33:42 首次发布