怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色?
怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色
------解决方案--------------------using System.Runtime.InteropServices;
[DllImport( "user32.dll ")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport( "user32.dll ")]
public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport( "gdi32.dll ")]
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
private void button1_Click(object sender, EventArgs e)
{
IntPtr vDC = GetDC(IntPtr.Zero); // IntPtr.Zero换成楼主的窗体句柄即可
int vPixel = (int)GetPixel(vDC, Cursor.Position.X, Cursor.Position.Y);
Color vColor = Color.FromArgb(
(vPixel & 0x000000FF) > > 0,
(vPixel & 0x0000FF00) > > 8,
(vPixel & 0x00FF0000) > > 16);
ReleaseDC(IntPtr.Zero, vDC);
button1.ForeColor = vColor;
}