Files
Common.Native/Structures.cs
2014-04-30 17:00:26 -04:00

199 lines
5.7 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace Common.Native
{
public static class Structures
{
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int X;
public int Y;
public Point(int x, int y)
{
X = x;
Y = y;
}
public Point(System.Drawing.Point pt) : this(pt.X, pt.Y) { }
public static implicit operator System.Drawing.Point(Point p)
{
return new System.Drawing.Point(p.X, p.Y);
}
public static implicit operator Point(System.Drawing.Point p)
{
return new Point(p.X, p.Y);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int Left, Top, Right, Bottom;
public Rect(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public Rect(System.Drawing.Rectangle r) : this(r.Left, r.Top, r.Right, r.Bottom) { }
public int X
{
get { return Left; }
set { Right -= (Left - value); Left = value; }
}
public int Y
{
get { return Top; }
set { Bottom -= (Top - value); Top = value; }
}
public int Height
{
get { return Bottom - Top; }
set { Bottom = value + Top; }
}
public int Width
{
get { return Right - Left; }
set { Right = value + Left; }
}
public System.Drawing.Point Location
{
get { return new System.Drawing.Point(Left, Top); }
set { X = value.X; Y = value.Y; }
}
public System.Drawing.Size Size
{
get { return new System.Drawing.Size(Width, Height); }
set { Width = value.Width; Height = value.Height; }
}
public static implicit operator System.Drawing.Rectangle(Rect r)
{
return new System.Drawing.Rectangle(r.Left, r.Top, r.Width, r.Height);
}
public static implicit operator Rect(System.Drawing.Rectangle r)
{
return new Rect(r);
}
public static bool operator ==(Rect r1, Rect r2)
{
return r1.Equals(r2);
}
public static bool operator !=(Rect r1, Rect r2)
{
return !r1.Equals(r2);
}
public bool Equals(Rect r)
{
return r.Left == Left && r.Top == Top && r.Right == Right && r.Bottom == Bottom;
}
public override bool Equals(object obj)
{
if (obj is Rect)
return Equals((Rect) obj);
if (obj is System.Drawing.Rectangle)
return Equals(new Rect((System.Drawing.Rectangle) obj));
return false;
}
public override int GetHashCode()
{
return ((System.Drawing.Rectangle) this).GetHashCode();
}
public override string ToString()
{
return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{{Left={0},Top={1},Right={2},Bottom={3}}}", Left, Top, Right, Bottom);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct CWPRETSTRUCT
{
public IntPtr lResult;
public IntPtr lParam;
public IntPtr wParam;
public uint message;
public IntPtr hwnd;
}
[StructLayout(LayoutKind.Sequential)]
public struct WindowPosition
{
public IntPtr Handle;
public IntPtr HandleInsertAfter;
public int Left;
public int Top;
public int Width;
public int Height;
public Constants.WindowPositionFlags Flags;
public int Right { get { return Left + Width; } }
public int Bottom { get { return Top + Height; } }
public bool IsSameLocationAndSize(WindowPosition compare)
{
return (compare.Left == Left && compare.Top == Top && compare.Width == Width && compare.Height == Height);
}
public bool IsSameSize(WindowPosition compare)
{
return (compare.Width == Width && compare.Height == Height);
}
public bool IsSameLocation(WindowPosition compare)
{
return (compare.Left == Left && compare.Top == Top);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct ProcessEntry32
{
public uint Size;
public uint Usage;
public uint ProcessId;
public IntPtr DefaultHeapId;
public uint ModuleId;
public uint Threads;
public uint ParentProcessId;
public int PriorityClassBase;
public uint Flags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string ExeFilename;
}
public struct WindowPlacement
{
public int Length;
public int Flags;
public Constants.ShowWindowCommand ShowCommand;
public Point MinPosition;
public Point MaxPosition;
public Rect NormalPosition;
}
}
}