locked
Rendering Behavior - > IHtmlPainter :: Draw() not working [Drawing rectangle around elements] RRS feed

  • Question

  • I am writing a BHO (using ATL) to draw a rectangle around the elements as I mouse over. So I planned to use IElementBehaviour and Implementing IHtmlPainter. But I could find that IHTMLPainter->Draw() is only called when the attached element's style either specifies an absolute position, or a value for the width or height attributes .

     

    With both my own implementation and the ATL sample I downloaded from MSDN, they work if I specify absolute position or size in the html source for the element attached to the behavior. If neither of these attributes are set, they don't work either. Any solutions for this ? or any other alternative for drawing a selection rectangle for elements as I mouse over ?

     

    thanks,

    Jithesh

    Wednesday, June 25, 2008 8:13 AM

All replies

  • See: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3497416&SiteID=1
    Thursday, June 26, 2008 12:13 AM
  • Hi Jeff,

             Thanks for your valuable suggestions. I tried to Implement as you suggest but found few issues, please correct if I am wrong.

     


    1. First took the window handle and DC
      
        m_spWebBrowser2->get_HWND(&hwnd);
        HDC dc =  GetDC((HWND) hwnd);


    2. Then got the current html element from ITMLEVENTOBJECT

       spEvent->get_srcElement(&spElement);


    3.  Took the bounding rectangle.
        spElement2->getBoundingClientRect(&hRect);


    4.  Created the point from this and transformed
         hr = spDisplayServices->TransformPoint(&ptTop,COORD_SYSTEM_FRAME,          COORD_SYSTEM_GLOBAL , spElement);

                    hr = spDisplayServices->TransformPoint(&ptBot,COORD_SYSTEM_FRAME,      COORD_SYSTEM_GLOBAL  , spElement);


    5.   Then Draw the rectangle
         Rectangle(dc, ptTop.x ,ptTop.y  , ptBot.x , ptBot.y );
         FillRect(dc, &Rect, hollowBrush);

     

    Problem I found in these are

     

    1.  The Transformation of DisplayService is not working perfect. So I
        have done my own transformations to make it work ( like adjusting on
        basis of client and window co-ordinates). This makes the rectangle positioned well
        but width and height not perfect.

     

    Please suggest where I have gone wrong.

    thanks,
    Jithesh
       

    Thursday, June 26, 2008 9:34 AM
  • I think you're doing it as right as possible.  A lot of these methods dealing with coordinates have known bugs, depending on the version of IE you use.  I think you just have to mess with it and debug it until you get something that works for you.
    Thursday, June 26, 2008 8:15 PM
  •  

    Hi Jeff,

     

             Thanks for your support.

    Now I could draw a recatangle around the html elements as I mouse over. But in case of certain elements like <A href ...> I could see the rectangle flashing and going. I that due to natural behaviour of <A> tag ? Any way to draw rect around these type of elements?

     

     

    thanks,

    Jithesh

    Tuesday, July 1, 2008 9:53 AM
  • Not sure why that would happen.  If the IE Dev toolbar can do it, I imagine you can too.

    Another thing you could try is getting the IHTMLElement you're hovering over (I think there's a pointToElement() function on some interface) and then change it's CSS to have a border.  Of course, then you might break some webpages. 

    I wonder how IE Dev toolbar does it.  You may be able to figure it out using Spy++ or NTSD.

    -jeff
    Tuesday, July 1, 2008 6:20 PM