關鍵代碼實現:
1、 獲取屏幕DC
HDC hDC = ::GetDC(NULL); //獲取屏幕DC
2、 獲取當前鼠標位置像素值
CPoint pt;
GetCursorPos(&pt); //得到當前鼠標所在位置
COLORREF clr = ::GetPixel(hDC, pt.x, pt.y); //獲取當前鼠標點像素值
3、 分解出像素點中的紅、綠、藍顏色值
CString ClrText;
ClrText.Format("%d",GetRValue(clr)); //分解出紅色值
ClrText.Format("%d",GetGValue(clr)); //分解出綠色值
ClrText.Format("%d",GetBValue(clr)); //分解出藍色值
::ReleaseDC(NULL, hDC); //釋放屏幕DC