要想捕获当前线程内(也就是当前CxxxApp)所有窗口上光标所在的像素颜色,需要重载CxxxApp的PreTranslateMessage函数,加:
if ( pMSG->message == WM_MOUSEMOVE)
{
CPoint ptScreen;
GetCursorPos(&ptScreen);
CWnd*DeskWnd = GetDesktopWindow();
CDC*DeskDC = DeskWnd->GetDC();
COLORREF clr = DeskDC->GetPixel(ptScreen);
DeskWnd->ReleaseDC(DeskDC);
CString strShow;
strShow.Format("%d", clr);
...
}
要想捕获当前屏幕任何地方的像素值,要先SetCapute,然后在使用上面的代码。