mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-16 18:49:54 -05:00
Fix for the DPI issue described in #26
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
//
|
//
|
||||||
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE
|
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE
|
||||||
|
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
|
|
||||||
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
||||||
@@ -30,12 +31,18 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SystemInfo
|
public static class SystemInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure the initial value is calculated at the first access
|
||||||
|
/// </summary>
|
||||||
static SystemInfo()
|
static SystemInfo()
|
||||||
{
|
{
|
||||||
UpdateFactors();
|
UpdateDpiFactors();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void UpdateFactors()
|
/// <summary>
|
||||||
|
/// This calculates the current DPI values and sets this into the DpiFactorX/DpiFactorY values
|
||||||
|
/// </summary>
|
||||||
|
internal static void UpdateDpiFactors()
|
||||||
{
|
{
|
||||||
using (var source = new HwndSource(new HwndSourceParameters()))
|
using (var source = new HwndSource(new HwndSourceParameters()))
|
||||||
{
|
{
|
||||||
@@ -59,5 +66,20 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// Returns the DPI Y Factor
|
/// Returns the DPI Y Factor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static double DpiFactorY { get; private set; } = 1;
|
public static double DpiFactorY { get; private set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scale the supplied point to the current DPI settings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="point"></param>
|
||||||
|
/// <returns>Point</returns>
|
||||||
|
[Pure]
|
||||||
|
public static Point ScaleWithDpi(this Point point)
|
||||||
|
{
|
||||||
|
return new Point
|
||||||
|
{
|
||||||
|
X = (int)(point.X / DpiFactorX),
|
||||||
|
Y = (int)(point.Y / DpiFactorY)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,13 +51,6 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="point">Point</param>
|
/// <param name="point">Point</param>
|
||||||
/// <returns>Point</returns>
|
/// <returns>Point</returns>
|
||||||
public static Point GetDeviceCoordinates(Point point)
|
public static Point GetDeviceCoordinates(Point point) => point.ScaleWithDpi();
|
||||||
{
|
|
||||||
return new Point
|
|
||||||
{
|
|
||||||
X = (int)(point.X / SystemInfo.DpiFactorX),
|
|
||||||
Y = (int)(point.Y / SystemInfo.DpiFactorY)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,6 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate IntPtr WindowProcedureHandler(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);
|
public delegate IntPtr WindowProcedureHandler(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Win API WNDCLASS struct - represents a single window.
|
/// Win API WNDCLASS struct - represents a single window.
|
||||||
/// Used to receive window messages.
|
/// Used to receive window messages.
|
||||||
|
|||||||
@@ -223,7 +223,19 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// <param name="lParam">Provides information about the event.</param>
|
/// <param name="lParam">Provides information about the event.</param>
|
||||||
private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
|
private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
|
||||||
{
|
{
|
||||||
if (msg != CallbackMessageId) return;
|
// Check if it was a callback message
|
||||||
|
if (msg != CallbackMessageId)
|
||||||
|
{
|
||||||
|
// It was not a callback message, but make sure it's not something else we need to process
|
||||||
|
switch ((WindowsMessages) msg)
|
||||||
|
{
|
||||||
|
case WindowsMessages.WM_DPICHANGED:
|
||||||
|
Debug.WriteLine("DPI Change");
|
||||||
|
SystemInfo.UpdateDpiFactors();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var message = (WindowsMessages)lParam.ToInt32();
|
var message = (WindowsMessages)lParam.ToInt32();
|
||||||
Debug.WriteLine("Got message " + message);
|
Debug.WriteLine("Got message " + message);
|
||||||
|
|||||||
@@ -134,6 +134,13 @@ namespace Hardcodet.Wpf.TaskbarNotification.Interop
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
WM_MBUTTONDBLCLK = 0x0209,
|
WM_MBUTTONDBLCLK = 0x0209,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sent when the effective dots per inch (dpi) for a window has changed.
|
||||||
|
/// The DPI is the scale factor for a window.
|
||||||
|
/// There are multiple events that can cause the DPI to change.
|
||||||
|
/// </summary>
|
||||||
|
WM_DPICHANGED = 0x02e0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to define private messages for use by private window classes, usually of the form WM_USER+x, where x is an integer value.
|
/// Used to define private messages for use by private window classes, usually of the form WM_USER+x, where x is an integer value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
<RootNamespace>Samples</RootNamespace>
|
<RootNamespace>Samples</RootNamespace>
|
||||||
<AssemblyTitle>Sample Project</AssemblyTitle>
|
<AssemblyTitle>Sample Project</AssemblyTitle>
|
||||||
<Product>Sample Project</Product>
|
<Product>Sample Project</Product>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
||||||
|
|||||||
45
src/Sample Project/app.manifest
Normal file
45
src/Sample Project/app.manifest
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<!-- Make sure windows Vista and above treat Greenshot as "DPI Aware" See: http://msdn.microsoft.com/en-us/library/ms633543.aspx -->
|
||||||
|
<asmv3:application>
|
||||||
|
<asmv3:windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
|
||||||
|
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||||
|
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">false</gdiScaling>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
<maxversiontested Id="10.0.18363.0"/>
|
||||||
|
<!-- Windows 8.1 -->
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
||||||
|
<!--Windows 8 -->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
<!-- Windows 7 -->
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
<!-- Set UAC level to "asInvoker" and disable registry virtualization -->
|
||||||
|
<asmv2:trustInfo>
|
||||||
|
<asmv2:security>
|
||||||
|
<asmv3:requestedPrivileges>
|
||||||
|
<!--
|
||||||
|
The presence of the "requestedExecutionLevel" node will disable
|
||||||
|
file and registry virtualization on Vista. See:
|
||||||
|
http://msdn.microsoft.com/en-us/library/aa965884%28v=vs.85%29.aspx
|
||||||
|
|
||||||
|
Use the "level" attribute to specify the User Account Control level:
|
||||||
|
asInvoker = Never prompt for elevation
|
||||||
|
requireAdministrator = Always prompt for elevation
|
||||||
|
highestAvailable = Prompt for elevation when started by administrator,
|
||||||
|
but do not prompt for administrator password when started by
|
||||||
|
standard user.
|
||||||
|
-->
|
||||||
|
<asmv3:requestedExecutionLevel level="asInvoker" />
|
||||||
|
</asmv3:requestedPrivileges>
|
||||||
|
</asmv2:security>
|
||||||
|
</asmv2:trustInfo>
|
||||||
|
</assembly>
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<RootNamespace>Windowless_Sample</RootNamespace>
|
<RootNamespace>Windowless_Sample</RootNamespace>
|
||||||
<AssemblyTitle>Windowless Sample</AssemblyTitle>
|
<AssemblyTitle>Windowless Sample</AssemblyTitle>
|
||||||
<Product>Windowless Sample</Product>
|
<Product>Windowless Sample</Product>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
||||||
|
|||||||
45
src/Windowless Sample/app.manifest
Normal file
45
src/Windowless Sample/app.manifest
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<!-- Make sure windows Vista and above treat Greenshot as "DPI Aware" See: http://msdn.microsoft.com/en-us/library/ms633543.aspx -->
|
||||||
|
<asmv3:application>
|
||||||
|
<asmv3:windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
|
||||||
|
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||||
|
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">false</gdiScaling>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
<maxversiontested Id="10.0.18363.0"/>
|
||||||
|
<!-- Windows 8.1 -->
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
||||||
|
<!--Windows 8 -->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
<!-- Windows 7 -->
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
<!-- Set UAC level to "asInvoker" and disable registry virtualization -->
|
||||||
|
<asmv2:trustInfo>
|
||||||
|
<asmv2:security>
|
||||||
|
<asmv3:requestedPrivileges>
|
||||||
|
<!--
|
||||||
|
The presence of the "requestedExecutionLevel" node will disable
|
||||||
|
file and registry virtualization on Vista. See:
|
||||||
|
http://msdn.microsoft.com/en-us/library/aa965884%28v=vs.85%29.aspx
|
||||||
|
|
||||||
|
Use the "level" attribute to specify the User Account Control level:
|
||||||
|
asInvoker = Never prompt for elevation
|
||||||
|
requireAdministrator = Always prompt for elevation
|
||||||
|
highestAvailable = Prompt for elevation when started by administrator,
|
||||||
|
but do not prompt for administrator password when started by
|
||||||
|
standard user.
|
||||||
|
-->
|
||||||
|
<asmv3:requestedExecutionLevel level="asInvoker" />
|
||||||
|
</asmv3:requestedPrivileges>
|
||||||
|
</asmv2:security>
|
||||||
|
</asmv2:trustInfo>
|
||||||
|
</assembly>
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
<AssemblyTitle>WindowsFormsSample</AssemblyTitle>
|
<AssemblyTitle>WindowsFormsSample</AssemblyTitle>
|
||||||
<Product>WindowsFormsSample</Product>
|
<Product>WindowsFormsSample</Product>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
|
||||||
|
|||||||
45
src/WindowsFormsSample/app.manifest
Normal file
45
src/WindowsFormsSample/app.manifest
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<!-- Make sure windows Vista and above treat Greenshot as "DPI Aware" See: http://msdn.microsoft.com/en-us/library/ms633543.aspx -->
|
||||||
|
<asmv3:application>
|
||||||
|
<asmv3:windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
|
||||||
|
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
|
||||||
|
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">false</gdiScaling>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
<maxversiontested Id="10.0.18363.0"/>
|
||||||
|
<!-- Windows 8.1 -->
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
||||||
|
<!--Windows 8 -->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
<!-- Windows 7 -->
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
<!-- Set UAC level to "asInvoker" and disable registry virtualization -->
|
||||||
|
<asmv2:trustInfo>
|
||||||
|
<asmv2:security>
|
||||||
|
<asmv3:requestedPrivileges>
|
||||||
|
<!--
|
||||||
|
The presence of the "requestedExecutionLevel" node will disable
|
||||||
|
file and registry virtualization on Vista. See:
|
||||||
|
http://msdn.microsoft.com/en-us/library/aa965884%28v=vs.85%29.aspx
|
||||||
|
|
||||||
|
Use the "level" attribute to specify the User Account Control level:
|
||||||
|
asInvoker = Never prompt for elevation
|
||||||
|
requireAdministrator = Always prompt for elevation
|
||||||
|
highestAvailable = Prompt for elevation when started by administrator,
|
||||||
|
but do not prompt for administrator password when started by
|
||||||
|
standard user.
|
||||||
|
-->
|
||||||
|
<asmv3:requestedExecutionLevel level="asInvoker" />
|
||||||
|
</asmv3:requestedPrivileges>
|
||||||
|
</asmv2:security>
|
||||||
|
</asmv2:trustInfo>
|
||||||
|
</assembly>
|
||||||
Reference in New Issue
Block a user