我正在使用 PrintWindow 做 IE 的屏幕截图。问题是有时我会得到带有黑色区域的图像。可能是整个 html 内容是黑色的,有时只有某些区域是黑色的。
IE 的内容在拍摄之间不会改变。
奇怪的是,在某些计算机上我经常得到黑色图像,而在某些计算机上我从来没有得到它们。
我用 Fx 进行了测试,得到了相同的黑色图像。
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;
}
我找到了一些链接,但他们没有给出答案:
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/