在不同设备和Windows版本下,Explorer的像素/坐标位置的一致性是一个常见的问题。为了解决这个问题,可以使用以下方法:
示例代码:
from pywinauto import Desktop, Application
# 启动Windows资源管理器
app = Application().start("explorer.exe")
# 获取桌面对象
desktop = Desktop()
# 获取Windows资源管理器窗口
explorer_window = desktop['文件资源管理器']
# 获取元素相对于父元素的坐标
element = explorer_window.child_window(class_name='Edit')
relative_position = element.rectangle()
# 输出相对坐标
print(f"元素的相对坐标:{relative_position}")
示例代码:
import win32gui
# 获取Windows资源管理器窗口句柄
explorer_hwnd = win32gui.FindWindow("CabinetWClass", None)
# 获取元素坐标
element_hwnd = win32gui.FindWindowEx(explorer_hwnd, None, "Edit", None)
element_position = win32gui.GetWindowRect(element_hwnd)
# 输出元素坐标
print(f"元素的绝对坐标:{element_position}")
这些方法可以帮助您在不同设备和Windows版本下保持Explorer的像素/坐标位置的一致性。您可以根据自己的需求选择适合的方法来解决问题。