2017-11-27 13:11:20 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Vanara.PInvoke;
|
2017-12-13 12:20:03 -05:00
|
|
|
|
using static Vanara.PInvoke.User32_Gdi;
|
2017-11-27 13:11:20 -05:00
|
|
|
|
|
|
|
|
|
namespace Vanara.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static partial class MapPointExtension
|
|
|
|
|
{
|
|
|
|
|
public static Point MapPointToClient(this IWin32Window ctrl, Point pt) => MapPoint(null, pt, ctrl);
|
|
|
|
|
|
|
|
|
|
public static Point MapPoint(this IWin32Window ctrl, Point pt, IWin32Window newWin = null)
|
|
|
|
|
{
|
2018-09-22 00:35:34 -04:00
|
|
|
|
MapWindowPoints(GetHandle(ctrl), GetHandle(newWin), ref pt, 1);
|
2017-11-27 13:11:20 -05:00
|
|
|
|
return pt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Rectangle MapRectangle(this IWin32Window ctrl, Rectangle rectangle, IWin32Window newWin = null)
|
|
|
|
|
{
|
|
|
|
|
RECT ir = rectangle;
|
2018-09-22 00:35:34 -04:00
|
|
|
|
MapWindowPoints(GetHandle(ctrl), GetHandle(newWin), ref ir, 2);
|
2017-11-27 13:11:20 -05:00
|
|
|
|
return ir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapPoints(this IWin32Window ctrl, Point[] points, IWin32Window newWin = null)
|
|
|
|
|
{
|
|
|
|
|
if (points == null) throw new ArgumentNullException(nameof(points));
|
2018-09-22 00:35:34 -04:00
|
|
|
|
MapWindowPoints(GetHandle(ctrl), GetHandle(newWin), points, points.Length);
|
2017-11-27 13:11:20 -05:00
|
|
|
|
/*Point[] pts = new Point[points.Length];
|
|
|
|
|
points.CopyTo(pts, 0);
|
|
|
|
|
for (int i = 0; i < pts.Length; i++)
|
|
|
|
|
MapWindowPoints(GetHandleRef(ctrl), GetHandleRef(newWin), ref pts[i], 1);
|
|
|
|
|
return pts;*/
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 00:35:34 -04:00
|
|
|
|
private static HWND GetHandle(IWin32Window ctrl) => new HWND(ctrl?.Handle ?? IntPtr.Zero);
|
2017-11-27 13:11:20 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|