提交 050ef716 编写于 作者: 三月三net's avatar 三月三net

Python超人-宇宙模拟器

上级 fe05f3b6
# -*- coding:utf-8 -*-
# title :
# description :
# author :Python超人
# date :2023-09-01
# link :https://gitcode.net/pythoncr/
# python_version :3.8
# ==============================================================================
import win32con
import win32gui
import win32api
def get_hwnd(window_name="宇宙模拟器(universe sim)"):
if window_name is None:
hwnd = win32gui.GetForegroundWindow()
else:
hwnd = win32gui.FindWindow(None, window_name)
classname = win32gui.GetClassName(hwnd)
title = win32gui.GetWindowText(hwnd)
print(f" -> classname:{classname}, title:{title}, hwnd:{hwnd}")
return hwnd
def get_win_pos(window_name="宇宙模拟器(universe sim)"):
"""
获取窗口位置
@param window_name:
@return:
"""
hwnd = get_hwnd(window_name)
rect = win32gui.GetWindowRect(hwnd)
# (146, 56, 1375, 747)
return rect
def set_win_pos(window_name, pos):
"""
设置窗口位置
@param window_name:
@param pos:
@return:
"""
hwnd = get_hwnd(window_name)
win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, pos[0], pos[1], pos[2] - pos[0], pos[3] - pos[1],
win32con.SWP_SHOWWINDOW)
def set_pycharm_win_pos():
"""
设置 Pycharm 窗口的位置
@return:
"""
border = {"t": 0, "r": 7, "b": 7, "l": 7}
# 获取宇宙模拟器窗口的位置
rect = get_win_pos()
print("宇宙模拟器窗口", rect)
rect = (rect[0] - border["l"],
rect[1] - border["t"],
rect[2] + border["r"],
rect[3] + border["b"])
# 依据 宇宙模拟器窗口 对 Pycharm 窗口的位置和大小进行调整
set_win_pos(None, rect)
print("Pycharm 窗口", rect)
if __name__ == '__main__':
set_pycharm_win_pos()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册