2010-04-16 69 views
1

我已經使用CPP,COM和DirectShow捕獲了總桌面。但是,我怎樣才能捕捉特定的窗口?如何捕獲特定的窗口而不是整個桌面?

+0

你的意思是捕獲在屏幕截圖中? – 2010-04-16 10:28:25

+0

不是一個屏幕截圖,但我必須捕獲一個特定的窗口,可以重新調整大小,最小化並在遠程端發佈它。當窗口最小化時,應該把什麼放在遠端? – Rupali 2010-04-16 13:20:55

回答

0

我利用幾個助手的 - 但你需要這些應該很容易翻譯成:

// Copy the contents of the client area or the window into an HBITMAP 
HBITMAP CaptureWindow(HWND hwnd, bool bIncludeFrame, const RECT * pClip) 
{ 
    // get the DC of the source 
    HDC hdcSource = bIncludeFrame ? ::GetWindowDC(hwnd) : ::GetDC(hwnd); 

    // get a memory DC 
    HDC hdcMemory = ::CreateCompatibleDC(hdcSource); 

    // get the clipping rect 
    RECT rcClip; 
    if (pClip) 
     rcClip = *pClip; 
    else if (bIncludeFrame) 
     ::GetWindowRect(hwnd, &rcClip); 
    else 
     ::GetClientRect(hwnd, &rcClip); 

    // determine the size of bitmap we're going to be making 
    SIZE sz = { rcClip.right - rcClip.left, rcClip.bottom - rcClip.top }; 

    // create a bitmap on which to copy the image 
    HBITMAP hbmCapture = ::CreateCompatibleBitmap(hdcSource, sz.cx, sz.cy); 

    // temporarily select our bitmap into the memory DC, grab the image, then deselect it again 
    if (AutoSelectGDIObject & select_capture = AutoSelectGDIObject(hdcMemory, hbmCapture)) 
     ::BitBlt(hdcMemory, 0, 0, sz.cx, sz.cy, hdcSource, rcClip.left, rcClip.top, SRCCOPY); 

    // release our resources 
    ::DeleteDC(hdcMemory); 
    ::ReleaseDC(hwnd, hdcSource); 

    // return the captured bitmap 
    return hbmCapture; 
} 
0
  1. 你捕捉桌面的方式,BitBlt只有感興趣的窗戶進入的區域的屏幕外的位圖(想捕獲完整的桌面和裁剪圖像窗口的位置)
  2. 或者,使用WM_PAINTWM_PRINTCLIENT消息請求的窗口本身繪製到您的DC