views:

469

answers:

0

I am doing the screen shots of IE using PrintWindow. The problem is that some times I get images with black areas. It may be a whole html content what is black, some times only certain areas are black.

The content of the IE is NOT changed between taking shots.

What is strange is that on some computers I get black images very oftern, on some I never get them.

I tested with Fx, and had same black images.

HBITMAP ShootWindow(HWND hWnd)
{
    RECT rect = {0};

    GetWindowRect(hWnd, & rect);

    HDC hDC = GetDC(hWnd);
    if(hDC == NULL)
        throw "GetDC failed.";

    HDC hTargetDC = CreateCompatibleDC(hDC);
    if(hTargetDC == NULL)
        throw "CreateCompatibleDC failed.";

    HBITMAP hBitmap = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
    if(hBitmap == NULL)
        throw "CreateCompatibleBitmap failed.";

    if(!SelectObject(hTargetDC, hBitmap))
        throw "SelectObject failed.";

    if(!PrintWindow(hWnd, hTargetDC, 0))
        throw "PrintWindow failed.";

    ReleaseDC(hWnd, hDC);
    ReleaseDC(hWnd, hTargetDC);

    return hBitmap;
}

I have found some links, but they give no answer:

http://www.vbforums.com/showthread.php?t=555250 http://www.codeguru.com/forum/archive/index.php/t-357211.html http://social.msdn.microsoft.com/forums/en-US/winforms/thread/3e3decd8-ced1-4f17-a745-466e5aa91391/