forked from Starry-Wind/StarRailAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_width.py
57 lines (46 loc) · 1.91 KB
/
get_width.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
Author: Night-stars-1 [email protected]
Date: 2023-05-23 17:39:27
LastEditors: Night-stars-1 [email protected]
LastEditTime: 2023-05-30 23:56:43
Description:
Copyright (c) 2023 by Night-stars-1, All Rights Reserved.
'''
import ctypes
import pygetwindow as gw
from PIL import ImageGrab
from utils.config import init_config_file, modify_json_file, normalize_file_path, CONFIG_FILE_NAME
from utils.log import log
def get_width():
window = gw.getWindowsWithTitle('崩坏:星穹铁道')[0]
hwnd = window._hWnd
# 获取活动窗口的大小
window_rect = window.width, window.height
user32 = ctypes.windll.user32
desktop_width = user32.GetSystemMetrics(0)
desktop_height = user32.GetSystemMetrics(1)
#单显示器屏幕宽度和高度:
img = ImageGrab.grab()
width, height=img.size
scaling = round(width/desktop_width*100)/100
"""
# 获取当前显示器的缩放比例
dc = win32gui.GetWindowDC(hwnd)
dpi_x = win32print.GetDeviceCaps(dc, win32con.LOGPIXELSX)
dpi_y = win32print.GetDeviceCaps(dc, win32con.LOGPIXELSY)
win32gui.ReleaseDC(hwnd, dc)
scale_x = dpi_x / 96
scale_y = dpi_y / 96
log.info(f"Real : {width} x {height} {dc} x {dc}")
"""
# 计算出真实分辨率
real_width = int(window_rect[0])
real_height = int(window_rect[1])
borderless = True if real_width*scaling == 1920 else False
if not normalize_file_path(CONFIG_FILE_NAME):
init_config_file(real_width=real_width, real_height=real_height)
log.info(f"Real resolution: {real_width} x {real_height} x {scaling} x {borderless}")
modify_json_file(CONFIG_FILE_NAME, "real_width", real_width)
modify_json_file(CONFIG_FILE_NAME, "real_height", real_height)
modify_json_file(CONFIG_FILE_NAME, "scaling", scaling)
modify_json_file(CONFIG_FILE_NAME, "borderless", borderless)