diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b71a6..3b6a5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### 2.5.0 +- Add more reliable `WinApi.GetScaleFactor(Hwnd hwnd)` + ### 2.4.0 - `FreSharp.dispose()` is now static funcion diff --git a/framework_src/FreSharp/Properties/AssemblyInfo.cs b/framework_src/FreSharp/Properties/AssemblyInfo.cs index 56c5f49..8888ca5 100644 --- a/framework_src/FreSharp/Properties/AssemblyInfo.cs +++ b/framework_src/FreSharp/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.4.0.0")] -[assembly: AssemblyFileVersion("2.4.0.0")] +[assembly: AssemblyVersion("2.5.0.0")] +[assembly: AssemblyFileVersion("2.5.0.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/framework_src/FreSharp/Utils/WinAPI.cs b/framework_src/FreSharp/Utils/WinAPI.cs index f5ed1bd..26a765a 100644 --- a/framework_src/FreSharp/Utils/WinAPI.cs +++ b/framework_src/FreSharp/Utils/WinAPI.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Runtime.InteropServices; using Hwnd = System.IntPtr; +using Hmonitor = System.IntPtr; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global // ReSharper disable FieldCanBeMadeReadOnly.Global @@ -14,9 +15,8 @@ namespace TuaRua.FreSharp.Utils { /// public static class WinApi { private const string User32 = "user32"; - - //private const string Kernel32 = "kernel32"; private const string Gdi32 = "gdi32"; + private const string ShCore = "shcore"; public static double GetScaleFactor() { var g = Graphics.FromHwnd(Hwnd.Zero); @@ -37,6 +37,19 @@ public static double GetScaleFactor() { return 1.0; } + /// + /// Gets the scale factor of the monitor. + /// + /// A handle to the window of interest. + /// + public static double GetScaleFactor(Hwnd hwnd) { + GetScaleFactorForMonitor( + MonitorFromWindow(hwnd, MonitorFlags.MONITOR_DEFAULTTONEAREST), + out int dsf); + if (dsf < 100) dsf = 100; + return Convert.ToDouble(dsf) / 100.0; + } + /// /// /// @@ -78,7 +91,6 @@ public static extern bool SetWindowPos(Hwnd hwnd, Hwnd hWndInsertAfter, int x, i [DllImport(User32, ExactSpelling = true)] public static extern bool RegisterTouchWindow(Hwnd hwnd, TouchWindowFlags flags); - /// /// /// @@ -102,13 +114,44 @@ public static extern bool SetLayeredWindowAttributes(Hwnd hwnd, uint crKey, byte [DllImport(Gdi32, ExactSpelling = true)] public static extern int GetDeviceCaps(Hwnd hdc, int nIndex); - } + /// + /// Gets the scale factor of a specific monitor. + /// + /// The monitor's handle. + /// When this function returns successfully, this value points to one of the + /// DEVICE_SCALE_FACTOR values that specify the scale factor of the specified monitor. + /// If the function call fails, this value points to a valid scale factor so that apps can opt to + /// continue on with incorrectly sized resources. + /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. + [DllImport(ShCore)] + public static extern Hwnd GetScaleFactorForMonitor([In]Hmonitor hMon, [Out]out int pScale); + + /// + /// The MonitorFromWindow function retrieves a handle to the display monitor that has the largest area of + /// intersection with the bounding rectangle of a specified window. + /// + /// A handle to the window of interest. + /// Determines the function's return value if the window does not intersect any display monitor. + /// If the window intersects one or more display monitor rectangles, the return value is + /// an HMONITOR handle to the display monitor that has the largest area of intersection with the window. + /// If the window does not intersect a display monitor, the return value depends on the value of dwFlags. + [DllImport(User32)] + public static extern Hmonitor MonitorFromWindow(Hwnd hwnd, MonitorFlags dwFlags); + } [Flags] - public enum WindowLongFlags { + public enum WindowLongFlags + { GWL_EXSTYLE = -20 } + [Flags] + public enum MonitorFlags { + MONITOR_DEFAULTTONULL = 0, + MONITOR_DEFAULTTOPRIMARY = 1, + MONITOR_DEFAULTTONEAREST = 2 + } + [Flags] public enum ShowWindowCommands { SW_FORCEMINIMIZE = 11, diff --git a/framework_src/FreSharpCore/FreSharpCore.rc b/framework_src/FreSharpCore/FreSharpCore.rc index e0d1eaa..bcf1422 100644 Binary files a/framework_src/FreSharpCore/FreSharpCore.rc and b/framework_src/FreSharpCore/FreSharpCore.rc differ diff --git a/framework_src/example/native_extension/ane/FreSharpExampleANE.ane b/framework_src/example/native_extension/ane/FreSharpExampleANE.ane index 859cb75..b98f479 100644 Binary files a/framework_src/example/native_extension/ane/FreSharpExampleANE.ane and b/framework_src/example/native_extension/ane/FreSharpExampleANE.ane differ diff --git a/framework_src/example/native_extension/ane/extension.xml b/framework_src/example/native_extension/ane/extension.xml index 258c6e0..80a7d34 100644 --- a/framework_src/example/native_extension/ane/extension.xml +++ b/framework_src/example/native_extension/ane/extension.xml @@ -3,7 +3,7 @@ com.tuarua.FreSharpExampleANE FreSharp Example ANE his work is licensed under MIT License, Copyright (c) 2017 Tua Rua Ltd. - 2.4.0 + 2.5.0 diff --git a/framework_src/fresharp_native_extension/ane/FreSharp.ane b/framework_src/fresharp_native_extension/ane/FreSharp.ane index 739b9af..c2ea756 100644 Binary files a/framework_src/fresharp_native_extension/ane/FreSharp.ane and b/framework_src/fresharp_native_extension/ane/FreSharp.ane differ diff --git a/framework_src/fresharp_native_extension/ane/extension.xml b/framework_src/fresharp_native_extension/ane/extension.xml index 41915a0..953f81c 100644 --- a/framework_src/fresharp_native_extension/ane/extension.xml +++ b/framework_src/fresharp_native_extension/ane/extension.xml @@ -3,7 +3,7 @@ com.tuarua.FreSharp FreSharp This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd. - 2.4.0 + 2.5.0 diff --git a/starter_project/native_library/win/HelloWorldANE/HelloWorldANE/HelloWorldANE.vcxproj b/starter_project/native_library/win/HelloWorldANE/HelloWorldANE/HelloWorldANE.vcxproj index dfdae40..16f02a2 100644 --- a/starter_project/native_library/win/HelloWorldANE/HelloWorldANE/HelloWorldANE.vcxproj +++ b/starter_project/native_library/win/HelloWorldANE/HelloWorldANE/HelloWorldANE.vcxproj @@ -181,7 +181,7 @@ - + @@ -194,7 +194,7 @@ - ..\packages\TuaRua.FreSharp.2.4.0\FreSharp\$(PlatformTarget)\FreSharp.dll + ..\packages\TuaRua.FreSharp.2.5.0\FreSharp\$(PlatformTarget)\FreSharp.dll diff --git a/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/HelloWorldANELib.csproj b/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/HelloWorldANELib.csproj index e0688e2..377437c 100644 --- a/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/HelloWorldANELib.csproj +++ b/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/HelloWorldANELib.csproj @@ -1,6 +1,6 @@  - + Debug @@ -89,8 +89,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - + \ No newline at end of file diff --git a/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/packages.config b/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/packages.config index 8fd1f97..2b7de11 100644 --- a/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/packages.config +++ b/starter_project/native_library/win/HelloWorldANE/HelloWorldANELib/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file