2012-11-11 68 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