IHTMLElementRender
代わりに、HTMLElemwntのインターフェースを使用することをお勧めします。カーソルの下の要素を簡単に見つけて、これをビットマップにレンダリングできます。
私のTWebBrowserデスカントでは、次のように実装しました。
function TWebBrowserIBMA.ElementAsBitmap(pElement : IHTMLElement2) : TBitmap;
var
pRender : IHTMLElementRender;
oBmpPart : TBitmap;
nClientWidth : Integer;
nClientHeight : Integer;
nX : Integer;
nLastX : Integer;
bDoneX : Boolean;
nY : Integer;
nLastY : Integer;
bDoneY : Boolean;
begin
Result := TBitmap.Create;
try
Result.Height := pElement.scrollHeight;
Result.Width := pElement.scrollWidth;
except
exit;
end;
LockWindowUpdate(Handle);
if (pElement.QueryInterface(IID_IHTMLElementRender, pRender) = S_OK) then begin
try
oBmpPart := TBitmap.Create;
oBmpPart.Width := pElement.scrollWidth;
oBmpPart.Height := pElement.scrollHeight;
nClientWidth := pElement.clientWidth;
nClientHeight := pElement.clientHeight;
try
nX := pElement.scrollWidth;
nLastX := -1;
bDoneX := false;
while not bDoneX do begin
pElement.scrollLeft := nX;
nX := pElement.scrollLeft;
if nLastX = -1 then begin
nLastX := nX + nClientWidth;
end;
nY := pElement.scrollHeight;
nLastY := (-1);
bDoneY := false;
while not bDoneY do begin
pElement.scrollTop := nY;
nY := pElement.scrollTop;
if nLastY = -1 then begin
nLastY := nY + nClientHeight;
end;
if (pRender.DrawToDC(oBmpPart.Canvas.Handle) = S_OK) then begin
BitBlt(Result.Canvas.Handle, nX, nY, nLastX-nX, nLastY-nY, oBmpPart.Canvas.Handle, 2, 2,SRCCOPY);
end;
bDoneY := (nY = 0);
nLastY := nY;
Dec(nY, nClientHeight-4);
end;
bDoneX := (nX = 0);
nLastX := nX;
Dec(nX, (nClientWidth-4));
end;
finally
FreeAndNil(oBmpPart);
end;
finally
pRender := nil;
end;
end;
LockWindowUpdate(0);
end;