2012-11-11 65 views

回答

2

有2个选项:

首先,您可以使用GetPixel()。我用了很多。它工作正常:

COLORREF GetPixel(
    HDC hdc, 
    int nXPos, 
    int nYPos 
); 

随着我们的日处理器使用此功能甚至使用rect可能在某些情况下工作。

其次,您可以将屏幕内容复制到位图中。在此之后,你可以将它放在剪贴板中,与您的代码工艺等核心功能有:

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); 
+0

嘿,谢谢你的回应,是的,你可以发布更详细的代码片段吗?这对我来说真的很新颖...... – joseRo

+0

谢谢,我在哪里可以找到RGS的.... hDCMem?与GetPixel()? – joseRo

+0

Kirill Kobelev,运行代码后我得到hMemDC元素:错误:表达式不能被评估。 我觉得我的尺寸参数有问题, margins_rect.left,margins_rect.top从哪里得到这些? 当我创建hBitamp它假设是hDC的大小或它可以更小? 如何评估屏幕尺寸? 谢谢, – joseRo