2010-04-16 71 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