有 2 个选项:
首先,您可以使用 GetPixel()。我用过很多次。它工作正常:
COLORREF GetPixel(
HDC hdc,
int nXPos,
int nYPos
);
如今,处理器使用此函数拾取矩形在某些情况下也可能起作用。
其次,您可以将屏幕内容复制到位图中。之后你可以将它放在剪贴板中,用你的代码进行处理等。核心功能是:
BOOL BitBlt(
_In_ HDC hdcDest,
_In_ int nXDest,
_In_ int nYDest,
_In_ int nWidth,
_In_ int nHeight,
_In_ HDC hdcSrc,
_In_ int nXSrc,
_In_ int nYSrc,
_In_ DWORD dwRop
);
如果需要的话,我可以发布更详细的片段。
// Pick up the DC.
HDC hDC = ::GetDC(m_control);
// Pick up the second DC.
HDC hDCMem = ::CreateCompatibleDC(hDC);
// Create the in memory bitmap.
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, bmp_size_x, bmp_size_y);
// Put bitmat into the memory DC. This will make it functional.
HBITMAP hBmpOld = (HBITMAP)::SelectObject(hDCMem, hBitmap);
// Clear the background.
HBRUSH hBkgr = ::CreateSolidBrush(props.bkgr_brush);
RECT bitmap_rect = { 0, 0, bmp_size_x, bmp_size_y };
::FillRect(hDCMem, &bitmap_rect, hBkgr);
::DeleteObject(hBkgr);
// Do the job.
::BitBlt(hDCMem, margins_rect.left, margins_rect.top,
size_to_copy_x, size_to_copy_y, hDC,
screen_from_x, screen_from_y, SRCCOPY);