|
3 | 3 | Source: https://github.com/BoboTiG/python-mss
|
4 | 4 | """
|
5 | 5 |
|
| 6 | +import sys |
6 | 7 | import ctypes
|
7 | 8 | from ctypes.wintypes import (
|
8 | 9 | BOOL,
|
@@ -96,19 +97,7 @@ def __init__(self, **_):
|
96 | 97 | self.user32 = ctypes.WinDLL("user32")
|
97 | 98 | self.gdi32 = ctypes.WinDLL("gdi32")
|
98 | 99 | self._set_cfunctions()
|
99 |
| - |
100 |
| - # Set DPI aware to capture full screen on Hi-DPI monitors |
101 |
| - try: |
102 |
| - # Windows 8.1+ |
103 |
| - # Automatically scale for DPI changes |
104 |
| - self.user32.SetProcessDpiAwareness( |
105 |
| - self.user32.PROCESS_PER_MONITOR_DPI_AWARE |
106 |
| - ) |
107 |
| - except AttributeError: |
108 |
| - try: |
109 |
| - self.user32.SetProcessDPIAware() |
110 |
| - except AttributeError: |
111 |
| - pass # Windows XP doesn't have SetProcessDPIAware |
| 100 | + self._set_dpi_awareness() |
112 | 101 |
|
113 | 102 | self._srcdc = self.user32.GetWindowDC(0)
|
114 | 103 | self._memdc = self.gdi32.CreateCompatibleDC(self._srcdc)
|
@@ -201,6 +190,21 @@ def close(self):
|
201 | 190 | except AttributeError:
|
202 | 191 | pass
|
203 | 192 |
|
| 193 | + def _set_dpi_awareness(self): |
| 194 | + """ Set DPI aware to capture full screen on Hi-DPI monitors. """ |
| 195 | + |
| 196 | + version = sys.getwindowsversion()[:2] |
| 197 | + if version >= (6, 3): |
| 198 | + # Windows 8.1+ |
| 199 | + # Here 2 = PROCESS_PER_MONITOR_DPI_AWARE, which means: |
| 200 | + # per monitor DPI aware. This app checks for the DPI when it is |
| 201 | + # created and adjusts the scale factor whenever the DPI changes. |
| 202 | + # These applications are not automatically scaled by the system. |
| 203 | + ctypes.windll.shcore.SetProcessDpiAwareness(2) |
| 204 | + elif (6, 0) <= version < (6, 3): |
| 205 | + # Windows Vista, 7, 8 and Server 2012 |
| 206 | + self.user32.SetProcessDPIAware() |
| 207 | + |
204 | 208 | @property
|
205 | 209 | def monitors(self):
|
206 | 210 | # type: () -> Monitors
|
|
0 commit comments