none
Grab window content

    Question

  •  

    Hi all,

     

    I'm trying to grab a window content so that I can later convert it into a bitmap image.

     

    Is it possible? I know how to get the window handler and how to resize it with that handler but, how could I grab a picture like Print Screen currently does.

     

    Thank you in advance.

    Wednesday, March 26, 2008 1:47 PM

Answers

  • Code Snippet

    1. Get screen DC

    HDC hdcScreen = GetDC(NULL);

     

    2. Get Window (being captured) bounds

    RECT rcWindow;

    GetWindowRect(hwnd);

     

    3. Allocated a DC and a bitmap:

     

    HDC hdcMem = CreateCompatibleDC(hdcScreen);

    HBITMAP hbmCapture = CreateCompatibleBitmap(hdcScreen, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);

    HGDIOBJ hbm = SelectObject(hdcMem, hbmCapture);

     

    4. Blit a block to the memory DC

     

    BitBlt(hdcMem, 0, 0, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, hdcScreen, rcWindow.left, rcWindow.top, SRCCOPY);

     

     

     

    Thursday, March 27, 2008 3:45 AM