win32gui 选择两个 windows 同名

win32gui selecting two windows with the same name

我正在使用 pywinauto 创建 python 代码以自动执行将两个 Minecraft 客户端设置为分屏的过程。

准备好所有内容后,最后一步是让 Minecraft 的一个实例为 0x0x1920x540,另一个为 0x540x1920x540。但是因为两个实例的名称完全相同,所以我只能 select 并移动一个,有没有办法同时 select 并在上方和下方排列?

from pywinauto.application import Application
from pywinauto import taskbar
from pywinauto import keyboard
import pywinauto
import win32gui
import time

app = Application(backend="uia").start('D:\Games\Minecraft\MinecraftLauncher.exe')
dlg_spec = app.window(title='Minecraft Launcher')
time.sleep(3)
keyboard.SendKeys("{TAB}")
keyboard.SendKeys("{ENTER}")
time.sleep(3)
keyboard.SendKeys("{TAB}")
time.sleep(0.3)
keyboard.SendKeys("{TAB}")
time.sleep(0.3)
keyboard.SendKeys("{TAB}")
time.sleep(0.3)
keyboard.SendKeys("{ENTER}")
keyboard.SendKeys("{TAB}")
keyboard.SendKeys("{TAB}")
keyboard.SendKeys("{TAB}")
keyboard.SendKeys("{ENTER}")
time.sleep(10)


app = Application(backend="uia").start('border_stripper.exe')
dlg_spec = app.window(title='Border Stripper')
app.Dialog['Minecraft 1.11.2ListItem2'].select()
app.Dialog.Button1.click()
app.Dialog['Minecraft 1.11.2ListItem0'].select()
app.Dialog.Button1.click()

hwnd = win32gui.FindWindow(None, "Minecraft 1.11.2")
win32gui.MoveWindow(hwnd, 0, 0, 1920, 540, True)
#hwnd2 doesn't do anything because both windows appear as "Minecraft 1.11.2"
hwnd2 = win32gui.FindWindow(None, "Minecraft 1.11.2(2)")
win32gui.MoveWindow(hwnd2, 0, 540, 1920, 540, True)

将默认的 Minecraft window 大小设置为 1920x520 将使两个 windows 出现在屏幕的上半部分,因此只需要将一个移动到下半部分。