I have a WinForms application. Inside my application i have a panel and that panel is supposed to turn into a different color based on where my cursor is. I want to be able to have the ability to place my cursor outside my application and still be able to find the color.
This is what i have so far:
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
Point p = Control.MousePosition;
IntPtr dc = GetDC(GetDesktopWindow());
private void timer1_Tick(object sender, EventArgs e)
{
Color c = ColorTranslator.FromWin32(GetPixel(dc, p.X, p.Y));
panel1.BackColor = c;
Console.WriteLine(c);
panel1.Refresh();
ReleaseDC(GetDesktopWindow(), dc);
}