Skip to content

Commit

Permalink
Merge pull request #717 from everettraven/Windows-10-DPI-process-fix
Browse files Browse the repository at this point in the history
Implemented DPI process bug fix
  • Loading branch information
freakboy3742 authored Aug 15, 2019
2 parents 4284026 + 9fa7425 commit 510ec81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/winforms/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import toga

from .libs import Threading, WinForms, add_handler, user32, win_version
from .libs import Threading, WinForms, add_handler, user32, win_version, shcore
from .window import Window


Expand All @@ -21,8 +21,24 @@ def __init__(self, interface):
def create(self):
self.native = WinForms.Application

if win_version >= 6:
user32.SetProcessDPIAware(True)
# Check the version of windows and make sure we are setting the DPI mode
# with the most up to date API
# Windows Versioning Check Sources : https://www.lifewire.com/windows-version-numbers-2625171
# and https://docs.microsoft.com/en-us/windows/release-information/
if win_version.Major >= 6: # Checks for Windows Vista or later
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use
# SetProcessDpiAwareness(True)
if ((win_version.Major == 6 and win_version.Minor == 3) or
(win_version.Major == 10 and win_version.Build < 15063)):
shcore.SetProcessDpiAwareness(True)
# Represents Windows 10 Build 1703 and beyond which should use
# SetProcessDpiAwarenessContext(-2)
elif win_version.Major == 10 and win_version.Build >= 15063:
user32.SetProcessDpiAwarenessContext(-2)
# Any other version of windows should use SetProcessDPIAware(True)
else:
user32.SetProcessDPIAware(True)

self.native.EnableVisualStyles()
self.native.SetCompatibleTextRenderingDefault(False)

Expand Down
3 changes: 2 additions & 1 deletion src/winforms/toga_winforms/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
) # noqa: E402

user32 = ctypes.windll.user32
win_version = Environment.OSVersion.Version.Major
shcore = ctypes.windll.shcore
win_version = Environment.OSVersion.Version


def TextAlignment(value):
Expand Down

0 comments on commit 510ec81

Please sign in to comment.