Browse Source

Merge pull request #1953 from ahopper/fix-make-MONITORINFO-a-struct

Fix make monitorinfo a struct
pull/1959/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
68cbf4111e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 4
      src/Windows/Avalonia.Win32/ScreenImpl.cs
  3. 4
      src/Windows/Avalonia.Win32/WindowImpl.cs

17
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -987,7 +987,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32", EntryPoint = "GetMonitorInfoW", ExactSpelling = true, CharSet = CharSet.Unicode)] [DllImport("user32", EntryPoint = "GetMonitorInfoW", ExactSpelling = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorInfo([In] IntPtr hMonitor, [Out] MONITORINFO lpmi); public static extern bool GetMonitorInfo([In] IntPtr hMonitor, ref MONITORINFO lpmi);
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "PostMessageW")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "PostMessageW")]
@ -1055,12 +1055,17 @@ namespace Avalonia.Win32.Interop
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal class MONITORINFO internal struct MONITORINFO
{ {
public int cbSize = Marshal.SizeOf<MONITORINFO>(); public int cbSize;
public RECT rcMonitor = new RECT(); public RECT rcMonitor;
public RECT rcWork = new RECT(); public RECT rcWork;
public int dwFlags = 0; public int dwFlags;
public static MONITORINFO Create()
{
return new MONITORINFO() { cbSize = Marshal.SizeOf<MONITORINFO>() };
}
public enum MonitorOptions : uint public enum MonitorOptions : uint
{ {

4
src/Windows/Avalonia.Win32/ScreenImpl.cs

@ -26,8 +26,8 @@ namespace Avalonia.Win32
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
(IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data) => (IntPtr monitor, IntPtr hdcMonitor, ref Rect lprcMonitor, IntPtr data) =>
{ {
MONITORINFO monitorInfo = new MONITORINFO(); MONITORINFO monitorInfo = MONITORINFO.Create();
if (GetMonitorInfo(monitor, monitorInfo)) if (GetMonitorInfo(monitor,ref monitorInfo))
{ {
RECT bounds = monitorInfo.rcMonitor; RECT bounds = monitorInfo.rcMonitor;
RECT workingArea = monitorInfo.rcWork; RECT workingArea = monitorInfo.rcWork;

4
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -837,9 +837,9 @@ namespace Avalonia.Win32
if (monitor != IntPtr.Zero) if (monitor != IntPtr.Zero)
{ {
MONITORINFO monitorInfo = new MONITORINFO(); MONITORINFO monitorInfo = MONITORINFO.Create();
if (GetMonitorInfo(monitor, monitorInfo)) if (GetMonitorInfo(monitor,ref monitorInfo))
{ {
RECT rcMonitorArea = monitorInfo.rcMonitor; RECT rcMonitorArea = monitorInfo.rcMonitor;

Loading…
Cancel
Save