From cd14cb3f5bbf87a9660091207bdf1e714bdc34cf Mon Sep 17 00:00:00 2001 From: trustable-code Date: Sat, 17 Aug 2019 13:31:52 +0200 Subject: Fix #46 Apps don't run on Windows 7 any more --- src/nigui/private/windows/platform_impl.nim | 21 ++++++++++++++++----- src/nigui/private/windows/windows.nim | 9 ++++----- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nigui/private/windows/platform_impl.nim b/src/nigui/private/windows/platform_impl.nim index 6a04c46..fba9f65 100755 --- a/src/nigui/private/windows/platform_impl.nim +++ b/src/nigui/private/windows/platform_impl.nim @@ -8,6 +8,7 @@ # math, os, strutils, times are imported by nigui.nim import windows import tables +import dynlib # ---------------------------------------------------------------------------------------- @@ -36,7 +37,7 @@ proc pCheckGdiplusStatus(status: int32, showAlert = true) = pRaiseLastOSError(showAlert) else: raiseError("A GDI+ error occured. (Status: " & $status & ")", showAlert) - + proc pColorToRGB32(color: Color): RGB32 = result.red = color.red result.green = color.green @@ -367,6 +368,19 @@ proc pGetTextSize(hDC, font: pointer, text: string): Size = # App Procedures # ---------------------------------------------------------------------------------------- +proc pEnableHighDpiSupport() = + let shcoreLib = loadLib("Shcore.dll") + if shcoreLib == nil: + return + let SetProcessDpiAwareness = cast[SetProcessDpiAwarenessType](shcoreLib.symAddr("SetProcessDpiAwareness")) + discard SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) + let user32Lib = loadLib("User32.dll") + if user32Lib == nil: + return + let GetDpiForWindow = cast[GetDpiForWindowType](user32Lib.symAddr("GetDpiForWindow")) + fSystemDpi = GetDpiForWindow(pDefaultParentWindow) + fDefaultFontSize = defaultFontSizeForDefaultDpi.scaleToDpi + proc init(app: App) = pInitGdiplus() pEnableVisualStyles() @@ -378,10 +392,7 @@ proc init(app: App) = app.defaultBackgroundColor = GetSysColor(COLOR_BTNFACE).pRgb32ToColor() app.defaultFontFamily = "Arial" fScrollbarSize = GetSystemMetrics(SM_CXVSCROLL) - # High DPI support: - discard SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) - fSystemDpi = GetDpiForWindow(pDefaultParentWindow) - fDefaultFontSize = defaultFontSizeForDefaultDpi.scaleToDpi + pEnableHighDpiSupport() proc runMainLoop() = var msg: Msg diff --git a/src/nigui/private/windows/windows.nim b/src/nigui/private/windows/windows.nim index e43bc56..638c701 100755 --- a/src/nigui/private/windows/windows.nim +++ b/src/nigui/private/windows/windows.nim @@ -24,7 +24,6 @@ {.pragma: libShell32, stdcall, dynlib: "Shell32.dll".} {.pragma: libGdiplus, stdcall, dynlib: "Gdiplus.dll".} {.pragma: libComdlg32, stdcall, dynlib: "Comdlg32.dll".} -{.pragma: libShcore, stdcall, dynlib: "Shcore.dll".} # ---------------------------------------------------------------------------------------- @@ -431,7 +430,8 @@ proc GetClipboardData*(uFormat: int32): pointer {.importc: "GetClipboardData", l proc SetClipboardData*(uFormat: int32, hMem: pointer): pointer {.importc: "SetClipboardData", libUser32.} proc EmptyClipboard*(): bool {.importc: "EmptyClipboard", libUser32.} proc MapVirtualKeyW*(uCode, uMapType: int32): int32 {.importc: "MapVirtualKeyW", libUser32.} -proc GetDpiForWindow*(hWnd: pointer): int32 {.importc: "GetDpiForWindow", libUser32.} + +type GetDpiForWindowType* = proc(hWnd: pointer): int32 {.gcsafe, stdcall.} # not available on Windows 7 when defined(cpu64): # Only available on 64-bit Windows: @@ -529,8 +529,7 @@ proc GetSaveFileNameW*(lpofn: var OpenFileName): bool {.importc: "GetSaveFileNam # ---------------------------------------------------------------------------------------- -# Comdlg32 Procs +# Shcore Procs # ---------------------------------------------------------------------------------------- -proc SetProcessDpiAwareness*(value: int32): int32 {.importc: "SetProcessDpiAwareness", libShcore.} - +type SetProcessDpiAwarenessType* = proc(value: int32): int32 {.gcsafe, stdcall.} # not available on Windows 7 -- cgit v1.2.3