Как захватить конкретное окно вместо общего рабочего стола? - PullRequest
1 голос
/ 16 апреля 2010

Я захватил весь рабочий стол, используя CPP, COM и DirectShow. Но как я могу захватить только конкретное окно?

Ответы [ 2 ]

0 голосов
/ 06 декабря 2011
  1. Способ захвата рабочего стола, BitBlt только область интересующего вас окна в ваше закадровое растровое изображение (подумайте о захвате полного рабочего стола и обрезке изображения до положения окна)
  2. Или используйте сообщения WM_PAINT, WM_PRINTCLIENT, чтобы запросить окно, чтобы нарисовать себя в DC
0 голосов
/ 06 декабря 2011

Я использую несколько помощников, но их должно быть легко перевести на то, что вам нужно:

// 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;
}
...