Re: TWebBrowser save to EMF



Thomas Mahle wrote:
I make desperate efforts to save the Canvas from a TWebBrowser to an
EMF. That´s about the size of it:

procedure TForm1.Button7Click(Sender: TObject);
var
  sourceDrawRect: TRect;
  mf            : TMetaFile;
  mfCanvas      : TMetafileCanvas;
  ViewObject    : IViewObject;
begin
  with WebBrowser1 do
  begin
    Height := OleObject.Document.ParentWindow.Screen.Height;
    Width := OleObject.Document.ParentWindow.Screen.Width;

    mf := TMetafile.Create();

    try
      sourceDrawRect := Rect(0, 0, Width, Height);
      mf.MMWidth := Width;
      mf.MMHeight := Height;

mfCanvas := TMetafileCanvas.Create(mf, GetDC(0));

You're leaking a device context here.

      Webbrowser1.Document.QueryInterface(IViewOBject, ViewObject);
      if ViewObject <> nil then
        OleCheck(ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil,
                                 Self.Handle,

Self.Handle is a window handle, not an information context. This parameter is ignored since the previous parameter is nil, but to avoid confusion, use a value without so much meaning, such as 0.


                                 mfCanvas.Handle,
                                 @sourceDrawRect, nil, nil, 0));
      mfCanvas.Free;
      mf.SaveToFile('.\test.emf');
    finally
      mf.Free;
    end;
  end;
end;

If I have a look at the EMF file I can see that the function BitBlt is
used and this is not wanted. I have no idea how I can stop this
behaviour and save a "real" EMF.
Could someone please help me?

Real EMFs can indeed contain BitBlt calls. So what you have is a valid EMF.

What makes you think Internet Explorer uses anything other than BitBlt to draw its image to a device context? Were you expecting a bunch of TextOut and LineTo calls for a Web page's text? Internet Explorer probably only does those calls once to its own internal buffer, and when it draws itself to the screen, it just blits a portion of that buffer. It has to do that if it's going to offer smooth scrolling or filter effects.

--
Rob
.