# -*- coding:utf-8 -*- # title : # description : # author :Python超人 # date :2023-09-01 # link :https://gitcode.net/pythoncr/ # python_version :3.8 # ============================================================================== import math 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) scale = 1.25 x, y, w, h = (math.ceil(rect[0] * scale), math.ceil(rect[1] * scale), math.floor(rect[2] * scale - rect[0] * scale), math.floor(rect[3] * scale - rect[1] * scale)) area_infos = f"""# EV录屏 ({x}, {y}, {w}, {h}) Area.rect.h : {h} Area.rect.w : {w} Area.rect.x : {x} Area.rect.y : {y} """ print(area_infos) 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__': # 使用方法: # 1、运行 win_pos.py,找到 EV录屏 区域 -> EV录屏 (183, 70, 1536, 863) set_pycharm_win_pos() # 2、打开 C:\Users\Administrator\AppData\Local\EVCapture\conf\Admin.conf # 修改: # Area.rect.h : 863 # Area.rect.w : 1536 # Area.rect.x : 183 # Area.rect.y : 70 # rect = get_win_pos(None) # rect = (rect[0] * 1.25, # rect[1] * 1.25, # rect[2] * 1.25, # rect[3] * 1.25) # print("Pycharm 窗口", rect)