<?xml version="1.0" encoding="UTF-8"?>
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
public override string ToString()
{
return ("X:" + X + ", Y:" + Y);
}
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetCursorPos(out POINT pt);
使用:
POINT currentPosition = new POINT();
GetCursorPos(out currentPosition);
System.Diagnostics.Debug.WriteLine("Current mouse point: " + currentPosition.ToString());
//转为客户区域坐标
Point relativePos = itemsControl.PointFromScreen(new Point(currentPosition.X, currentPosition.Y));