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);
}
参考文档:
本来在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)
相关文章推荐
- VC获取屏幕上任意点位置的颜色
- 动态获取当前屏幕中光标所在位置的颜色
- C#动态获取当前屏幕中光标所在位置的颜色
- 如何获取屏幕上各颜色的红、绿、蓝值
- 在VC中设置屏幕分辨率和颜色质量
- 动态获取当前屏幕中光标所在位置的颜色
- Android 之实用小代码-获取屏幕尺寸、判断是否是平板、文字颜色、点击效果、计算字宽等。
- VC 获取鼠标 点击时的屏幕坐标
- VC:CListCtrl(库函数的加载和释放、获取系统颜色、向图片链表添加位图、客户区的获取和填充)
- Js获取电脑屏幕的颜色色彩品质(16位或32位)
- C#简单获取屏幕鼠标坐标点颜色
- 动态获取当前屏幕中光标所在位置的颜色
- C# 获取任意窗体选中文字 屏幕取词
- 动态获取当前屏幕中光标所在位置的颜色
- vc 获取屏幕大小
- 如何获取屏幕上各颜色的红、绿、蓝值
- 屏幕任意点颜色拾取
- vc 获取屏幕大小
- VC获取的是显示屏幕
- VC获取屏幕分辨率及大小相关