[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: OLE event source - snippet 123

Thx grant.
Seems that there is a security problem but I found a solution for it
http://codecentrix.blogspot.com/2007/10/when-ihtmlwindow2getdocument-returns.html

This requires to have IServiceProvider.java for QueryService( method which is actually not part of Eclipse. An implementation can be found at
http://hp.vector.co.jp/authors/VA000137/rss_reader/extends_browser.html


If the copyright would allow it maybe it would make sense to include IServiceProvider in Eclipse by default.

Jack

Grant Gayed schrieb:
The attachEvent probably needs to be hooked on each of the frames.
IHTMLDocument2 (this is the type of htmlDocument in the snippet) has
property "frames" (see
http://msdn2.microsoft.com/en-us/library/aa752592(VS.85).aspx ) which gives
you access to an IHTMLFramesCollection2, which contains the frames.  Frame
has method "attachEvent".

Grant


"Jack Glass" <jack.glass@xxxxxxx> wrote in message news:fuib2u$c3e$1@xxxxxxxxxxxxxxxxxxxx
Hi,

I tried this code out (I get the onclick events, and elements) and it
works great in general except for frames/iframes.
Does someone has an example which works also for frames/iframes?

Best regards,
Jack.

Grant Gayed wrote:
Hi Martin,

I don't think you currently can determine the html element with the
snippet
because setting the event listener properties seems to give
notifications
that do not include info about the event.  If you hook a listener by
invoking "attachEvent" instead then the callback has more useful
information.  To do this, start with Snippet123:

Change its DownloadComplete listener to:

public void handleEvent(OleEvent event) {
    int[] htmlDocumentID = webBrowser.getIDsOfNames(new
String[]{"Document"});
    if (htmlDocumentID == null) return;
    Variant pVarResult = webBrowser.getProperty(htmlDocumentID[0]);
    if (pVarResult == null || pVarResult.getType() == 0) return;

    OleAutomation htmlDocument = pVarResult.getAutomation();
//IHTMLDocument3
    pVarResult.dispose();
    EventDispatch myDispatch = new EventDispatch(EventDispatch.onclick);
    IDispatch idispatch = new IDispatch(myDispatch.getAddress());

    int[] ids = htmlDocument.getIDsOfNames(new String[]{"attachEvent"});
    Variant[] rgvarg = new Variant[2];
    rgvarg[0] = new Variant("onclick");
    rgvarg[1] = new Variant(idispatch);
    pVarResult = htmlDocument.invoke(ids[0], rgvarg);
    pVarResult.dispose();
    rgvarg[0].dispose();
    htmlDocument.dispose();
}

Change its Invoke method to (shortened to the onclick case just for
brevity):

private int Invoke(int dispIdMember, int /*long*/ riid, int lcid, int
dwFlags, int /*long*/ pDispParams, int /*long*/ pVarResult, int /*long*/
pExcepInfo, int /*long*/ pArgErr) {
    switch (eventID) {
        case onclick: {
            DISPPARAMS params = new DISPPARAMS();
            COM.MoveMemory(params, pDispParams, DISPPARAMS.sizeof);
            Variant variant = Variant.win32_new(params.rgvarg);
            OleAutomation event = variant.getAutomation();
            variant.dispose();
            int[] rgdispid = event.getIDsOfNames(new String[] {
"srcElement" });
            dispIdMember = rgdispid[0];
            Variant result = event.getProperty(dispIdMember);
            event.dispose();
            OleAutomation element = result.getAutomation();
            result.dispose();
            rgdispid = element.getIDsOfNames(new String[] {
"outerHtml" });
            dispIdMember = rgdispid[0];
            result = element.getProperty(dispIdMember);
            element.dispose();
            System.out.println(result.getString());
            result.dispose();
            break;
        }
    }
    return COM.S_OK;
}

HTH,
Grant


"Martin" <fiesta81@xxxxxx> wrote in message news:c0fb208d02a0f744eaf4bf4ccdc17f1e$1@xxxxxxxxxxxxxxxxxx
Hi,

i tested the OLE and ActiveX example snippet (Snippet123) to catch
events
from the ie browser widget. Everything works fine and i get a "onclick"
on
my console when a onclick-event occured. But how to find out the
html-element (e.g. a button or link) that was clicked?

Regards
Martin