Skip to content

Commit

Permalink
Merge pull request #24 from tuarua/2.5.0
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
tuarua authored Oct 18, 2020
2 parents b43ff00 + 9e1f28a commit 74448b0
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 2.5.0
- Add more reliable `WinApi.GetScaleFactor(Hwnd hwnd)`

### 2.4.0
- `FreSharp.dispose()` is now static funcion

Expand Down
4 changes: 2 additions & 2 deletions framework_src/FreSharp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

53 changes: 48 additions & 5 deletions framework_src/FreSharp/Utils/WinAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,9 +15,8 @@ namespace TuaRua.FreSharp.Utils {
/// </summary>
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);
Expand All @@ -37,6 +37,19 @@ public static double GetScaleFactor() {
return 1.0;
}

/// <summary>
/// Gets the scale factor of the monitor.
/// </summary>
/// <param name="hwnd">A handle to the window of interest.</param>
/// <returns></returns>
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;
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -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);


/// <summary>
///
/// </summary>
Expand All @@ -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);
}

/// <summary>
/// Gets the scale factor of a specific monitor.
/// </summary>
/// <param name="hMon">The monitor's handle.</param>
/// <param name="pScale">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.</param>
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
[DllImport(ShCore)]
public static extern Hwnd GetScaleFactorForMonitor([In]Hmonitor hMon, [Out]out int pScale);

/// <summary>
/// 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.
/// </summary>
/// <param name="hwnd">A handle to the window of interest.</param>
/// <param name="dwFlags">Determines the function's return value if the window does not intersect any display monitor.</param>
/// <returns>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.</returns>
[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,
Expand Down
Binary file modified framework_src/FreSharpCore/FreSharpCore.rc
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion framework_src/example/native_extension/ane/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>com.tuarua.FreSharpExampleANE</id>
<name>FreSharp Example ANE</name>
<copyright>his work is licensed under MIT License, Copyright (c) 2017 Tua Rua Ltd.</copyright>
<versionNumber>2.4.0</versionNumber>
<versionNumber>2.5.0</versionNumber>
<platforms>
<platform name="Windows-x86">
<applicationDeployment>
Expand Down
Binary file modified framework_src/fresharp_native_extension/ane/FreSharp.ane
Binary file not shown.
2 changes: 1 addition & 1 deletion framework_src/fresharp_native_extension/ane/extension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>com.tuarua.FreSharp</id>
<name>FreSharp</name>
<copyright>This work is licensed under Apache License, Copyright (c) 2017 Tua Rua Ltd.</copyright>
<versionNumber>2.4.0</versionNumber>
<versionNumber>2.5.0</versionNumber>
<platforms>
<platform name="Windows-x86">
<applicationDeployment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\..\..\sdks\AIR\AIRSDK_29\include\FlashRuntimeExtensions.h" />
<ClInclude Include="D:\dev\sdks\AIR\AIRSDK_32\include\FlashRuntimeExtensions.h" />
<ClInclude Include="FreNamespace.h" />
<ClInclude Include="FreSharpBridge.h" />
<ClInclude Include="FreSharpMacros.h" />
Expand All @@ -194,7 +194,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="FreSharp">
<HintPath>..\packages\TuaRua.FreSharp.2.4.0\FreSharp\$(PlatformTarget)\FreSharp.dll</HintPath>
<HintPath>..\packages\TuaRua.FreSharp.2.5.0\FreSharp\$(PlatformTarget)\FreSharp.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.props" Condition="Exists('..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.props')" />
<Import Project="..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.props" Condition="Exists('..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -89,8 +89,8 @@
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.props'))" />
<Error Condition="!Exists('..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.targets'))" />
<Error Condition="!Exists('..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.props'))" />
<Error Condition="!Exists('..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.targets'))" />
</Target>
<Import Project="..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.targets" Condition="Exists('..\packages\TuaRua.FreSharp.2.4.0\build\TuaRua.FreSharp.targets')" />
<Import Project="..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.targets" Condition="Exists('..\packages\TuaRua.FreSharp.2.5.0\build\TuaRua.FreSharp.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="TuaRua.FreSharp" version="2.4.0" targetFramework="net46" />
<package id="TuaRua.FreSharp" version="2.5.0" targetFramework="net46" />
</packages>

0 comments on commit 74448b0

Please sign in to comment.