On the desktop to run a variety of programs, there are many colors are very beautiful, we sometimes want to use their colors, but suffer from no source code, so it is difficult to accurately know their R, G, B color values. So there are a lot of tools to pick up screen colors, do you want to know how they are implemented with the program? I'll take the example code of a screen color picker I made with VC6.0 to tell you that the interface of the instance program after running is as follows:
Basic composition thought:
The principle is simple, only a brief three-step. Both: Get the screen DC, get the current mouse pixel value, decomposition of the pixel value of red, green, blue Three colors can, very simple!
Key code implementations:
1. Get the screen DC
HDC hDC = ::GetDC(NULL); //获取屏幕DC
2, get the current mouse position pixel value
CPoint pt;
GetCursorPos(&pt); //得到当前鼠标所在位置
COLORREF clr = ::GetPixel(hDC, pt.x, pt.y); //获取当前鼠标点像素值
3, the decomposition of the pixel point of red, green, blue color values
CString ClrText;
ClrText.Format("%d",GetRValue(clr)); //分解出红色值
ClrText.Format("%d",GetGValue(clr)); //分解出绿色值
ClrText.Format("%d",GetBValue(clr)); //分解出蓝色值
::ReleaseDC(NULL, hDC); //释放屏幕DC
The details of the implementation of the above part of the code, you can download the instance code, carefully check the source can be (with detailed comments).