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 /