python 打开文件窗口和另存为文件窗口,win32con,win32gui

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)  # 点击打开按钮

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值