首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色?该如何处理

2011-12-30 
怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色?怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色[解

怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色?
怎样根据窗口的句柄,获取窗口上某一个坐标点的颜色

[解决办法]
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;
}

热点排行