I'm trying to get whether the mouse cursor is over the desktop screen. Here is my code:
[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();
}
but it doesn't work. When the mouse cursor is over the desktop, WindowFromPoint and GetDesktopWindow return different values.