Friday, May 6, 2011

Simple screen capture example - GDI version.

A Simple screen capture example using windows handle and BitBlt.
This mechanism works for both GDI and DirectX window mode.
However, this screen capture has its own weakness, low performance and
abnormal mouse behaviour. Use it just as reference.



// Functions for captureing WoW screen.
//
HWND        getWoWWindowHandle(void)
{
    HWND        wowWnd;


    //return GetDesktopWindow();

    // Try to find WoW window handle.
    //
    wowWnd = FindWindow(TEXT("GxWindowClass"), TEXT("월드 오브 워크래프트"));
    if( wowWnd )
    {
        // The window is found.
        //
        return wowWnd;
    }
    else
        return NULL;
}


void        captureWoWWindow(HDC hTgtDC)
{
    HWND        hSrcWnd;
    HDC            hSrcDC;

    // Get WoW Window Handle.
    //
    hSrcWnd = getWoWWindowHandle();
    if( hSrcWnd )
    {
        hSrcDC = GetDC(hSrcWnd);

        BitBlt(hTgtDC, 0, 0, 960, 640, hSrcDC, 0, 0, SRCCOPY | CAPTUREBLT);

        ReleaseDC(hSrcWnd, hSrcDC);
    }

    return;
}