|
6 | 6 |
|
7 | 7 | from __future__ import division
|
8 | 8 |
|
| 9 | +import sys |
9 | 10 | import ctypes
|
10 | 11 | from ctypes.wintypes import (
|
11 | 12 | BOOL,
|
@@ -80,19 +81,7 @@ def __init__(self):
|
80 | 81 | self.user32 = ctypes.WinDLL("user32")
|
81 | 82 | self.gdi32 = ctypes.WinDLL("gdi32")
|
82 | 83 | self._set_cfunctions()
|
83 |
| - |
84 |
| - # Set DPI aware to capture full screen on Hi-DPI monitors |
85 |
| - try: |
86 |
| - # Windows 8.1+ |
87 |
| - # Automatically scale for DPI changes |
88 |
| - self.user32.SetProcessDpiAwareness( |
89 |
| - self.user32.PROCESS_PER_MONITOR_DPI_AWARE |
90 |
| - ) |
91 |
| - except AttributeError: |
92 |
| - try: |
93 |
| - self.user32.SetProcessDPIAware() |
94 |
| - except AttributeError: |
95 |
| - pass # Windows XP doesn't have SetProcessDPIAware |
| 84 | + self._set_dpi_awareness() |
96 | 85 |
|
97 | 86 | self._srcdc = self.user32.GetWindowDC(0)
|
98 | 87 | self._memdc = self.gdi32.CreateCompatibleDC(self._srcdc)
|
@@ -185,6 +174,21 @@ def close(self):
|
185 | 174 | except AttributeError:
|
186 | 175 | pass
|
187 | 176 |
|
| 177 | + def _set_dpi_awareness(self): |
| 178 | + """ Set DPI aware to capture full screen on Hi-DPI monitors. """ |
| 179 | + |
| 180 | + version = sys.getwindowsversion()[:2] |
| 181 | + if version >= (6, 3): |
| 182 | + # Windows 8.1+ |
| 183 | + # Here 2 = PROCESS_PER_MONITOR_DPI_AWARE, which means: |
| 184 | + # per monitor DPI aware. This app checks for the DPI when it is |
| 185 | + # created and adjusts the scale factor whenever the DPI changes. |
| 186 | + # These applications are not automatically scaled by the system. |
| 187 | + ctypes.windll.shcore.SetProcessDpiAwareness(2) |
| 188 | + elif (6, 0) <= version < (6, 3): |
| 189 | + # Windows Vista, 7, 8 and Server 2012 |
| 190 | + self.user32.SetProcessDPIAware() |
| 191 | + |
188 | 192 | @property
|
189 | 193 | def monitors(self):
|
190 | 194 | # type: () -> List[Dict[str, int]]
|
|
0 commit comments