mirror of
https://github.com/VitalickS/BrightSharp.Toolkit.git
synced 2026-03-21 02:21:15 +00:00
Add WindowMinMaxSizeBehavior
This commit is contained in:
11
BrightSharp/Interop/Constants.cs
Normal file
11
BrightSharp/Interop/Constants.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace BrightSharp.Interop
|
||||
{
|
||||
namespace Constants
|
||||
{
|
||||
internal enum MonitorFromWindowFlags
|
||||
{
|
||||
MONITOR_DEFAULTTONEAREST = 0x00000002
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
BrightSharp/Interop/NativeMethods.cs
Normal file
20
BrightSharp/Interop/NativeMethods.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using BrightSharp.Interop.Structures;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BrightSharp.Interop
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
#region Monitor
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
130
BrightSharp/Interop/Structures.cs
Normal file
130
BrightSharp/Interop/Structures.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BrightSharp.Interop
|
||||
{
|
||||
namespace Structures
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
internal class MONITORINFO
|
||||
{
|
||||
public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
|
||||
|
||||
public RECT rcMonitor;
|
||||
|
||||
public RECT rcWork;
|
||||
|
||||
public int dwFlags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
internal struct POINT
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0)]
|
||||
internal struct RECT
|
||||
{
|
||||
public int Left;
|
||||
|
||||
public int Top;
|
||||
|
||||
public int Right;
|
||||
|
||||
public int Bottom;
|
||||
|
||||
public static readonly RECT Empty;
|
||||
|
||||
public int Width
|
||||
{
|
||||
get {
|
||||
return Math.Abs(Right - Left);
|
||||
} // Abs needed for BIDI OS
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get {
|
||||
return Bottom - Top;
|
||||
}
|
||||
}
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public RECT(RECT rcSrc)
|
||||
{
|
||||
Left = rcSrc.Left;
|
||||
Top = rcSrc.Top;
|
||||
Right = rcSrc.Right;
|
||||
Bottom = rcSrc.Bottom;
|
||||
}
|
||||
|
||||
public bool IsEmpty
|
||||
{
|
||||
get {
|
||||
// BUGBUG : On Bidi OS (hebrew arabic) left > right
|
||||
return Left >= Right || Top >= Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (this == Empty)
|
||||
{
|
||||
return "RECT {Empty}";
|
||||
}
|
||||
return "RECT { left : " + Left + " / top : " + Top + " / right : " + Right + " / bottom : " +
|
||||
Bottom + " }";
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is RECT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (this == (RECT)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Left.GetHashCode() + Top.GetHashCode() + Right.GetHashCode() +
|
||||
Bottom.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(RECT rect1, RECT rect2)
|
||||
{
|
||||
return (rect1.Left == rect2.Left && rect1.Top == rect2.Top && rect1.Right == rect2.Right &&
|
||||
rect1.Bottom == rect2.Bottom);
|
||||
}
|
||||
|
||||
public static bool operator !=(RECT rect1, RECT rect2)
|
||||
{
|
||||
return !(rect1 == rect2);
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct MINMAXINFO
|
||||
{
|
||||
public POINT ptReserved;
|
||||
|
||||
public POINT ptMaxSize;
|
||||
|
||||
public POINT ptMaxPosition;
|
||||
|
||||
public POINT ptMinTrackSize;
|
||||
|
||||
public POINT ptMaxTrackSize;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user