我正在尝试获取鼠标光标是否悬停在桌面屏幕上。以下是我的代码:
但是它并不起作用。当鼠标光标位于桌面上时,WindowFromPoint和GetDesktopWindow将返回不同的值。
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out Point lpPoint);
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point Point);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetDesktopWindow();
public static bool IsMouseOverDesktop()
{
Point mouseCursor;
GetCursorPos(out mouseCursor);
return WindowFromPoint(mouseCursor) == GetDesktopWindow();
}
但是它并不起作用。当鼠标光标位于桌面上时,WindowFromPoint和GetDesktopWindow将返回不同的值。