[通过python打开特定大小的.exe文件

问题描述 投票:0回答:1

我正在尝试创建一个按钮,该按钮可以使用win32process打开特定大小的程序。我写的代码以某种方式不起作用..我该如何进行这项工作?

from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import *
from PIL import ImageTk,Image
import win32process


window=Tk()

def openfile():
    window.filename = askopenfilename(title="Open file", filetypes=(("exe files", "*.exe"),("all files", "*.*")))  
    startupinfo = win32process.STARTUPINFO()
    startupinfo.dwX = 10
    startupinfo.dwY = 20
    startupinfo.dwXSize = 600
    startupinfo.dwYSize = 100

    win32process.CreateProcess(
        None,
        window.filename,
        None,
        None,
        False,
        0,
        None,
        None,
        startupinfo
    )

OpeButton = Button(window, text="Open", command=openfile)#COMMAND=OPEN
OpeButton.pack()
OpeButton.place(relx = 0.52, rely = 0.5)

window.overrideredirect(1)
window.mainloop()
python winapi process window size
1个回答
0
投票

您未设置dwFlagsSTARTUPINFO字段,因此dwX / dwYdwXSize / dwYSize字段将被忽略。您需要添加这些标志才能使用这些字段:

startupinfo.dwFlags = win32process.STARTF_USEPOSITION | win32process.STARTF_USESIZE

但是,这仍然不能保证目标窗口将实际位于指定的位置和大小。由目标进程自行决定是否将履行STARTUPINFO

© www.soinside.com 2019 - 2024. All rights reserved.