My problem about rendering behavior
==== What I want to do: ====
I am hosting a "Microsoft Web Browser" control in my MFC program.
I want to draw a red rectangle encompassing one or a group of html
Since the rectangle may encompass more than one elements, it
seems to me that it is
impossible to do it by changing element styles using IHTMLStyle
==== The Method I am using now ====
Currently I am using "rendering behavior" method described in this
which offers some sample codes as follows:
<sample code begin>
IHTMLElement* pBody = 0;
IHTMLElement2 pBody2 = 0;
long lCookie = 0;
vBehavior.vt = VT_UNKNOWN;
vBehavior.punkVal = pBehavior;
pBody2->addBehavior(NULL, &vBehavior, &lCookie);
<sample code end>
==== More details on my method ====
I downloaded the "render behavior" sample from microsoft:
Since I don't need the behavior to handle events, the CBehavior class
only inherits from IElementBehavior and IHTMLPainter(NO IEventSink).
class ATL_NO_VTABLE CBehavior :
public CComCoClass<CBehavior, &CLSID_Behavior>,
It overrides IHTMLPainter::Draw like this:
HPEN redPen = CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
HPEN oldPen = (HPEN)SelectObject(hdc, redPen);
HBRUSH hollowBrush = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, hollowBrush);
Rectangle(hdc, 100, 100, 200, 200); //have a test first...
FillRect(hdc, &rect, hollowBrush);
I want it to work like this:
Somewhere in my program, I change CBehaviors' member flag and rect, and
then I make web browser to update, which will call CBehavior's draw
function and draws a rectangle.
==== My Problem====
It works, partially.
I can see several "half rectangles" on the web browser control. No
full rectangle can be seen.
Besides, when I scroll the bar of the web browser, the rectangle pieces
update their positions automatically(It is good.).
But, when I scroll them out of view, and then scroll them back in, they
disappear.(It is really bad.)
Any help will be appreciated.