uzi
April 30th, 2000, 10:18 AM
Hi . I am implementing a shdocvw.WebBrowser object and I am trying to find out when a mouse click occurs on this objec. I tried to be a MouseListener and do shdocvw.WebBrowser.addMouseListener(this), but it didn't work. I tried to put an invisible window on it , but I could not make a transparent background. I found the following example in C++ which works but I can't seem to be able to convert it to Java:
>> you can attach an event handler to any of the inner objects in the web browser control, you need to do the following.
>>
>>1- create a class derived from the IDispatch
>>2- pass a pointer to an object of that class to
>>IHTMLDocument2::put_onclick()
>>3- you will recieve the events in the Invoke method of your class.
>>
>>for example
>>
>>// your event class definition
>>class CClickEvent : public IDispatch
>>{
>>... class members
>>};
>>// your event handler
>>CClickEvent ::Invoke(...)
>>{
>>}
>>
>>
>>In your webbrowser Document complete do the following
>>
>>OnDocumentComplete(LPSTR lpURL)
>>{
>>
>> CClickEvent * pClickEvent;
>>
>> LPDISPATCH pDisp = GetHtmlDocument();
>> if (!pDisp)
>> return;
>>
>>
>> IHTMLDocument2 * pDoc2;
>> HRESULT hr ;
>>
>> if ( SUCCEEDED(hr =
>> pDisp->QueryInterface(IID_IHTMLDocument2,(void**) &pDoc2)) ) {
>>
>> pClickEvent = new CClickEvent ;
>>
>> VARIANT vDocDisp;
>> vDocDisp.vt = VT_DISPATCH;
>> vDocDisp.pdispVal = pClickEvent ;
>>
>> pDoc2->put_onclick( vDocDisp);
>>
>> }
>> pDisp->Release();
>>
>>}
I tried to imlement it in Java by doing:
>> m_click = new ClickEvent(this);
>> IHTMLDocument2 document =(IHTMLDocument2) browser.getDocument();
>>
>> Variant var = document.getonclick();
>>
>> Variant variant = new Variant(Variant.VariantDispatch,null);
>> document.putonclick(variant);
But it didn't work.
Do you know how to do it?
Do you know which invoke function I should implement in my class ClickEvent?
Do you have another idea?
Thanks in advance,
Uzi
>> you can attach an event handler to any of the inner objects in the web browser control, you need to do the following.
>>
>>1- create a class derived from the IDispatch
>>2- pass a pointer to an object of that class to
>>IHTMLDocument2::put_onclick()
>>3- you will recieve the events in the Invoke method of your class.
>>
>>for example
>>
>>// your event class definition
>>class CClickEvent : public IDispatch
>>{
>>... class members
>>};
>>// your event handler
>>CClickEvent ::Invoke(...)
>>{
>>}
>>
>>
>>In your webbrowser Document complete do the following
>>
>>OnDocumentComplete(LPSTR lpURL)
>>{
>>
>> CClickEvent * pClickEvent;
>>
>> LPDISPATCH pDisp = GetHtmlDocument();
>> if (!pDisp)
>> return;
>>
>>
>> IHTMLDocument2 * pDoc2;
>> HRESULT hr ;
>>
>> if ( SUCCEEDED(hr =
>> pDisp->QueryInterface(IID_IHTMLDocument2,(void**) &pDoc2)) ) {
>>
>> pClickEvent = new CClickEvent ;
>>
>> VARIANT vDocDisp;
>> vDocDisp.vt = VT_DISPATCH;
>> vDocDisp.pdispVal = pClickEvent ;
>>
>> pDoc2->put_onclick( vDocDisp);
>>
>> }
>> pDisp->Release();
>>
>>}
I tried to imlement it in Java by doing:
>> m_click = new ClickEvent(this);
>> IHTMLDocument2 document =(IHTMLDocument2) browser.getDocument();
>>
>> Variant var = document.getonclick();
>>
>> Variant variant = new Variant(Variant.VariantDispatch,null);
>> document.putonclick(variant);
But it didn't work.
Do you know how to do it?
Do you know which invoke function I should implement in my class ClickEvent?
Do you have another idea?
Thanks in advance,
Uzi