您的位置:首页 > 其它

VC获取屏幕上任意点的颜色

2014-09-05 21:34 316 查看
项目:  http://download.csdn.net/detail/a379039233/7869757

本来在MouseMove事件中获得鼠标位置及位置,发现只能获取窗体内的颜色,后来参看了其他人的代码才发现

可以在定时器中获取。



主要代码如下:

void CGetColorDlg::OnTimer(UINT nIDEvent) 

{

CPoint point;

GetCursorPos(&point);

HDC hDC = ::GetDC(NULL);

    COLORREF colorref = ::GetPixel(hDC, point.x, point.y);//Get the cursor color

    ::ReleaseDC(NULL,hDC);

//显示鼠标出坐标

CString str;

str.Format("%d,%d",point.x,point.y);

m_cS1.SetWindowText(str);

//填充颜色

CClientDC dc(this);

CRect rc;

m_cG2.GetWindowRect(&rc);

ScreenToClient(rc);

CBrush brush;

brush.Detach(); 

brush.CreateSolidBrush(colorref);

dc.FillRect(rc,&brush);

//RGB值显示

str.Format("%d,%d,%d",colorref&0xFF,(colorref>>8)&0xFF,colorref>>16);

m_cS2.SetWindowText(str);

//RGB Hex值显示

str.Format("#%02X%02X%02X",colorref&0xFF,(colorref>>8)&0xFF,colorref>>16);

m_cS3.SetWindowText(str);

CDialog::OnTimer(nIDEvent);

}

参考文档:


VC_实时获取鼠标指针坐标编程方法 (http://www.docin.com/p-65104153.html)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息