Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:31:56+00:00 2026-05-26T10:31:56+00:00

Is it possible to draw or put something over the WebBrowser component to draw

  • 0

Is it possible to draw or put something over the WebBrowser component to draw on it ?

When I add an image on WebBrowser this image is always under the WebBrowser.
I need this to draw area over different map types always in the same way.
For example I need to draw the same area on Google Maps and open street maps…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:31:56+00:00Added an answer on May 26, 2026 at 10:31 am

    You should use IHTMLPainter.Draw event method for doing this. The following code needs a TWebBrowser where you have to write the OnDocumentComplete event handler.

    Note that this example has one big weakness, the user input events like mouse clicking are active because the only thing what this example do is the painting over the element. I’ve been playing with this a little bit, but without success. This might be a good topic for another question.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      StdCtrls, SHDocVw, MSHTML, OleCtrls;
    
    type
      TElementBehavior = class(TInterfacedObject, IElementBehavior, IHTMLPainter)
      private
        FPaintSite: IHTMLPaintSite;
      public
        { IElementBehavior }
        function Init(const pBehaviorSite: IElementBehaviorSite): HRESULT; stdcall;
        function Notify(lEvent: Integer; var pVar: OleVariant): HRESULT; stdcall;
        function Detach: HRESULT; stdcall;
        { IHTMLPainter }
        function Draw(rcBounds: tagRECT; rcUpdate: tagRECT; lDrawFlags: Integer;
          hdc: hdc; pvDrawObject: Pointer): HRESULT; stdcall;
        function OnResize(size: tagSIZE): HRESULT; stdcall;
        function GetPainterInfo(out pInfo: _HTML_PAINTER_INFO): HRESULT; stdcall;
        function HitTestPoint(pt: tagPOINT; out pbHit: Integer; out plPartID: Integer): HRESULT; stdcall;
      end;
    
      TElementBehaviorFactory = class(TInterfacedObject, IElementBehaviorFactory)
      public
        function FindBehavior(const bstrBehavior: WideString;
          const bstrBehaviorUrl: WideString; const pSite: IElementBehaviorSite;
          out ppBehavior: IElementBehavior): HRESULT; stdcall;
      end;
    
      TForm1 = class(TForm)
        WebBrowser1: TWebBrowser;
        procedure FormDestroy(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure WebBrowser1DocumentComplete(ASender: TObject;
          const pDisp: IDispatch; var URL: OleVariant);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      Image: TBitmap;
      Behavior: TElementBehavior;
      Factory: TElementBehaviorFactory;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Image := TBitmap.Create;
      Image.LoadFromFile('c:\yourpicture.bmp');
      WebBrowser1.Navigate('maps.google.com');
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      Behavior := nil;
      Factory := nil;
      Image.Free;
    end;
    
    procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    var
      HTMLElement: IHTMLElement2;
      FactoryVariant: OleVariant;
    begin
      HTMLElement := (WebBrowser1.Document as IHTMLDocument3).getElementById('map') as IHTMLElement2;
    
      if Assigned(HTMLElement) then
      begin
        Behavior := TElementBehavior.Create;
        Factory := TElementBehaviorFactory.Create;
        FactoryVariant := IElementBehaviorFactory(Factory);
        HTMLElement.addBehavior('', FactoryVariant);
      end;
    end;
    
    function TElementBehaviorFactory.FindBehavior(const bstrBehavior,
      bstrBehaviorUrl: WideString; const pSite: IElementBehaviorSite;
      out ppBehavior: IElementBehavior): HRESULT;
    begin
      ppBehavior := Behavior;
      Result := S_OK;
    end;
    
    function TElementBehavior.Draw(rcBounds: tagRECT; rcUpdate: tagRECT; lDrawFlags: Integer;
      hdc: hdc; pvDrawObject: Pointer): HRESULT;
    begin
      StretchBlt(
        hdc,
        rcBounds.Left,
        rcBounds.Top,
        rcBounds.Right - rcBounds.Left,
        rcBounds.Bottom - rcBounds.Top,
        Image.Canvas.Handle,
        0,
        0,
        Image.Canvas.ClipRect.Right - Image.Canvas.ClipRect.Left,
        Image.Canvas.ClipRect.Bottom - Image.Canvas.ClipRect.Top,
        SRCCOPY);
      Result := S_OK; 
    end;
    
    function TElementBehavior.GetPainterInfo(out pInfo: _HTML_PAINTER_INFO): HRESULT;
    begin
      pInfo.lFlags := HTMLPAINTER_OPAQUE;
      pInfo.lZOrder := HTMLPAINT_ZORDER_WINDOW_TOP;
      FillChar(pInfo.rcExpand, SizeOf(TRect), 0);
      Result := S_OK;
    end;
    
    function TElementBehavior.HitTestPoint(pt: tagPOINT; out pbHit,
      plPartID: Integer): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TElementBehavior.OnResize(size: tagSIZE): HRESULT;
    begin
      Result := S_OK;
    end;
    
    function TElementBehavior.Detach: HRESULT;
    begin
      if Assigned(FPaintSite) then
        FPaintSite.InvalidateRect(nil);
      Result := S_OK;
    end;
    
    function TElementBehavior.Init(
      const pBehaviorSite: IElementBehaviorSite): HRESULT;
    begin
      Result := pBehaviorSite.QueryInterface(IHTMLPaintSite, FPaintSite);
      if Assigned(FPaintSite) then
        FPaintSite.InvalidateRect(nil);
    end;
    
    function TElementBehavior.Notify(lEvent: Integer;
      var pVar: OleVariant): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if it's actually possible to draw a polygon over a complete town
is it possible to draw a line semi-transparent with image magick? i want to
Possible Duplicate: Android: How to overlay-a-bitmap/draw-over a bitmap? I have implement the android Camera
Is it possible to draw a road using bing maps js api? Ideally I
Is it possible to draw some strings onto a listview? I overridden the OnPaint
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Is possible to draw a quad given its normal vector, a point that is
Is it possible to draw a frame around an expression? For example if I
im trying to use the graphic veiw of QT to draw lines it's possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.