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

项目:  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)





  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值