Is there a way to find the HTMLDocument from the IHTMLEventObj passed from an onload event in IE?

StackOverflow https://stackoverflow.com/questions/14448856

سؤال

I am working on a Browser Helper Object in C# (yes I know performance will not be great).

I am attaching a handler to the HTMLWindowEvents2_Event.onload event of my window. The event is being raised correctly (for example when a refresh happens). I see my handler being called, and the type is correctly shows as a 'load' event.

The event handler has a parameter that supports the IHTMLEventObj. I cannot work out how to get from this object to the window or document that threw the onload event. Is this even possible from this interface? The object passed into appears to have a null srcElement property (presumably as it is an event raised by the window, not some element in the document).

Do I need to cast this into another class or interface to get at the document?

I would be happy for any help in C# or C++.

هل كانت مفيدة؟

المحلول

There is no source information for the event.

The assumption is that since you attached the event to the connection point of the Window object, you knew which window would be the event source. When you hook the event you need to save the reference to the window in case you need the event source.

Class HTMLWindowEvents2Sink
{
    public HTMLWindowEvents2Sink(IHTMLWindow2 eventSource)
    {
        this.eventSource=eventSource;
    }
    IHTMLWindow2 eventSource;
    void AdviseEvent()
    {
        eventSource.load += this.HTMLWindow_onload; 
    }
    ....
}

You also have a performance hit and potential bug farm here, by using the delegate event handling model.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top