注意:本篇文章都是使用C#代码
///<summary>
///返回当前光标的位置(用来更换鼠标位置)
///lpPoint-POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构
///</summary>
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
public static extern int GetCursorPos(ref Point lpPoint);
private void Button_Click(object sender, RoutedEventArgs e)
{
Point myPoint = new Point();
GetCursorPos(ref myPoint);
Debug.WriteLine("鼠标坐标:" + myPoint.X + "," + myPoint.Y);
}
以上代码在WinForm程序中运行正常,可以正确的读取鼠标坐标
以上代码在WPF程序中运行不正常,获取错误的鼠标坐标
怎么办呢?没有对比没有伤害。为什么WPF不行呢