PC Review


Reply
Thread Tools Rate Thread

Browser Helper Object

 
 
dwandless@gmail.com
Guest
Posts: n/a
 
      25th Oct 2006
I have successfully installed a BHO in IE7. Using C#.

Now I'm trying to figure out how to trap various events. onkeypress,
oncut, oncontextmenu, etc.

I have tried calling in various IHTMLElement2.attachEvent, but no
success. attachEvent wants two parameters: event name, and object
pdisp.

I cannot find the correct means to populate pdisp. Or is there another
way to trap events from a BHO and C#?

Any help would be greatly appreciated.

Thanks.

 
Reply With Quote
 
 
 
 
Dave Sexton
Guest
Posts: n/a
 
      25th Oct 2006
Hi,

The second parameter is the function pointer. Try passing in a delegate.

--
Dave Sexton

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have successfully installed a BHO in IE7. Using C#.
>
> Now I'm trying to figure out how to trap various events. onkeypress,
> oncut, oncontextmenu, etc.
>
> I have tried calling in various IHTMLElement2.attachEvent, but no
> success. attachEvent wants two parameters: event name, and object
> pdisp.
>
> I cannot find the correct means to populate pdisp. Or is there another
> way to trap events from a BHO and C#?
>
> Any help would be greatly appreciated.
>
> Thanks.
>



 
Reply With Quote
 
dwandless@gmail.com
Guest
Posts: n/a
 
      25th Oct 2006
I did try that.

public delegate void F();
F f = delegate () { MessageBox.Show ("delegate");};
IHTMLElement2 h;
h.attachEvent ("oncut", f);

Maybe the signature is not correct.

I did try passing various other signatures for the delegate.

If you have a specific example that would be great. I am stumped.
Duane


Dave Sexton wrote:
> Hi,
>
> The second parameter is the function pointer. Try passing in a delegate.
>
> --
> Dave Sexton
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I have successfully installed a BHO in IE7. Using C#.
> >
> > Now I'm trying to figure out how to trap various events. onkeypress,
> > oncut, oncontextmenu, etc.
> >
> > I have tried calling in various IHTMLElement2.attachEvent, but no
> > success. attachEvent wants two parameters: event name, and object
> > pdisp.
> >
> > I cannot find the correct means to populate pdisp. Or is there another
> > way to trap events from a BHO and C#?
> >
> > Any help would be greatly appreciated.
> >
> > Thanks.
> >


 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      26th Oct 2006
Hi,

There is a lot of stuff on the web about this problem. I searched in
groups.google.com for "dotnet default method" and read some MSDN articles as
well (most pertaining to legacy VB).

Basically, the HTML events require an IDispatch interface to invoke a default,
parameterless method, which C# doesn't support. I tried a bunch of things
using DispIdAttribute, ClassInterfaceAttribute and DispatchWrapper but I
couldn't get it to work. Assignment always throws an InvalidCastException
(presumably because I didn't go as far as implementing IDispatch

In the 2.0 framework I use the HtmlElement.AttachEventHandler method, which
allows me to supply an EventHandler delegate. Unfortunately, I doubt you'll
be able to go that route because the class itself is dependant on the
WebBrowser control, but you might want to take a peek at how it's accomplished
in that class.

--
Dave Sexton

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I did try that.
>
> public delegate void F();
> F f = delegate () { MessageBox.Show ("delegate");};
> IHTMLElement2 h;
> h.attachEvent ("oncut", f);
>
> Maybe the signature is not correct.
>
> I did try passing various other signatures for the delegate.
>
> If you have a specific example that would be great. I am stumped.
> Duane
>
>
> Dave Sexton wrote:
>> Hi,
>>
>> The second parameter is the function pointer. Try passing in a delegate.
>>
>> --
>> Dave Sexton
>>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I have successfully installed a BHO in IE7. Using C#.
>> >
>> > Now I'm trying to figure out how to trap various events. onkeypress,
>> > oncut, oncontextmenu, etc.
>> >
>> > I have tried calling in various IHTMLElement2.attachEvent, but no
>> > success. attachEvent wants two parameters: event name, and object
>> > pdisp.
>> >
>> > I cannot find the correct means to populate pdisp. Or is there another
>> > way to trap events from a BHO and C#?
>> >
>> > Any help would be greatly appreciated.
>> >
>> > Thanks.
>> >

>



 
Reply With Quote
 
dwandless@gmail.com
Guest
Posts: n/a
 
      26th Oct 2006
Amazingly I think I have it working. So for all you searching out
there. Try this:

public class
{
DispatcherClass dp = new DispatcherClass();

<< do code to get the IHTMLElements >>
foreach (IHTMLElement myTag in allTag1)
{
myTag.onkeypress = dp;
}
}

public DispatcherClass
{
[DispId(0)]
public void DefaultMethod()
{
// do your code
}
}
The key is the [DispId(0)]. This allows IDispatch to callback into my
C# code.

Of course now I have the event firing I'm not exactly sure how to find
out which key was pressed. I also could not get
IHTMLElement2.attachEvents() to work. But that is for another day.

Good luck.


Dave Sexton wrote:
> Hi,
>
> There is a lot of stuff on the web about this problem. I searched in
> groups.google.com for "dotnet default method" and read some MSDN articles as
> well (most pertaining to legacy VB).
>
> Basically, the HTML events require an IDispatch interface to invoke a default,
> parameterless method, which C# doesn't support. I tried a bunch of things
> using DispIdAttribute, ClassInterfaceAttribute and DispatchWrapper but I
> couldn't get it to work. Assignment always throws an InvalidCastException
> (presumably because I didn't go as far as implementing IDispatch
>
> In the 2.0 framework I use the HtmlElement.AttachEventHandler method, which
> allows me to supply an EventHandler delegate. Unfortunately, I doubt you'll
> be able to go that route because the class itself is dependant on the
> WebBrowser control, but you might want to take a peek at how it's accomplished
> in that class.
>
> --
> Dave Sexton
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I did try that.
> >
> > public delegate void F();
> > F f = delegate () { MessageBox.Show ("delegate");};
> > IHTMLElement2 h;
> > h.attachEvent ("oncut", f);
> >
> > Maybe the signature is not correct.
> >
> > I did try passing various other signatures for the delegate.
> >
> > If you have a specific example that would be great. I am stumped.
> > Duane
> >
> >
> > Dave Sexton wrote:
> >> Hi,
> >>
> >> The second parameter is the function pointer. Try passing in a delegate.
> >>
> >> --
> >> Dave Sexton
> >>
> >> <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> >I have successfully installed a BHO in IE7. Using C#.
> >> >
> >> > Now I'm trying to figure out how to trap various events. onkeypress,
> >> > oncut, oncontextmenu, etc.
> >> >
> >> > I have tried calling in various IHTMLElement2.attachEvent, but no
> >> > success. attachEvent wants two parameters: event name, and object
> >> > pdisp.
> >> >
> >> > I cannot find the correct means to populate pdisp. Or is there another
> >> > way to trap events from a BHO and C#?
> >> >
> >> > Any help would be greatly appreciated.
> >> >
> >> > Thanks.
> >> >

> >


 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      26th Oct 2006
Hi,

Interesting that works for you because I tried that and many variants but
nothing worked for me (neither attachEvents nor direct assignment) but then
again I was trying it with the WebBrowser control and the MSHTML PIA, so there
could be inconstancies.

Anyway, if you want to find the key that was pressed you need to access the
event object on the IHTMLWindow2. Note however that in C# the event is a
keyword so it must be accessed as follows (I think this only applies when
using the PIA, IIRC):

IHTMLWindow2 window = (IHTMLWindow2) winObj;

// Using the Keys enumeration has worked for me in the past,
// but you'll want to test it anyway just to be sure it works for you
Keys keys = (Keys) window.@event.keyCode

--
Dave Sexton

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Amazingly I think I have it working. So for all you searching out
> there. Try this:
>
> public class
> {
> DispatcherClass dp = new DispatcherClass();
>
> << do code to get the IHTMLElements >>
> foreach (IHTMLElement myTag in allTag1)
> {
> myTag.onkeypress = dp;
> }
> }
>
> public DispatcherClass
> {
> [DispId(0)]
> public void DefaultMethod()
> {
> // do your code
> }
> }
> The key is the [DispId(0)]. This allows IDispatch to callback into my
> C# code.
>
> Of course now I have the event firing I'm not exactly sure how to find
> out which key was pressed. I also could not get
> IHTMLElement2.attachEvents() to work. But that is for another day.
>
> Good luck.
>
>
> Dave Sexton wrote:
>> Hi,
>>
>> There is a lot of stuff on the web about this problem. I searched in
>> groups.google.com for "dotnet default method" and read some MSDN articles
>> as
>> well (most pertaining to legacy VB).
>>
>> Basically, the HTML events require an IDispatch interface to invoke a
>> default,
>> parameterless method, which C# doesn't support. I tried a bunch of things
>> using DispIdAttribute, ClassInterfaceAttribute and DispatchWrapper but I
>> couldn't get it to work. Assignment always throws an InvalidCastException
>> (presumably because I didn't go as far as implementing IDispatch
>>
>> In the 2.0 framework I use the HtmlElement.AttachEventHandler method, which
>> allows me to supply an EventHandler delegate. Unfortunately, I doubt
>> you'll
>> be able to go that route because the class itself is dependant on the
>> WebBrowser control, but you might want to take a peek at how it's
>> accomplished
>> in that class.
>>
>> --
>> Dave Sexton
>>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I did try that.
>> >
>> > public delegate void F();
>> > F f = delegate () { MessageBox.Show ("delegate");};
>> > IHTMLElement2 h;
>> > h.attachEvent ("oncut", f);
>> >
>> > Maybe the signature is not correct.
>> >
>> > I did try passing various other signatures for the delegate.
>> >
>> > If you have a specific example that would be great. I am stumped.
>> > Duane
>> >
>> >
>> > Dave Sexton wrote:
>> >> Hi,
>> >>
>> >> The second parameter is the function pointer. Try passing in a
>> >> delegate.
>> >>
>> >> --
>> >> Dave Sexton
>> >>
>> >> <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> >I have successfully installed a BHO in IE7. Using C#.
>> >> >
>> >> > Now I'm trying to figure out how to trap various events. onkeypress,
>> >> > oncut, oncontextmenu, etc.
>> >> >
>> >> > I have tried calling in various IHTMLElement2.attachEvent, but no
>> >> > success. attachEvent wants two parameters: event name, and object
>> >> > pdisp.
>> >> >
>> >> > I cannot find the correct means to populate pdisp. Or is there
>> >> > another
>> >> > way to trap events from a BHO and C#?
>> >> >
>> >> > Any help would be greatly appreciated.
>> >> >
>> >> > Thanks.
>> >> >
>> >

>



 
Reply With Quote
 
dwandless@gmail.com
Guest
Posts: n/a
 
      26th Oct 2006
Fantastic. Thanks again for the push in the right direction. I now
can see which key was pressed. Here is the basic code.

public DispatcherClass(BHO callback)
{
m_callback = callback;
}
[DispId(0)]
public void DefaultMethod()
{
Keys key = m_callback.CallBack();
<< do your code >>
}
=======================
public class BHO
{
DispatcherClass dp;

BHO()
{
dp = new DispatcherClass (this);
}

public Keys CallBack()
{
//m_window1 is the saved IHTMLWindow2 that I'm watching
return (Keys)m_window1.@event.keyCode;
}

public someFunc()
{
<< do code to get the IHTMLElements >>
foreach (IHTMLElement myTag in allTag)
{
myTag.onkeypress = dp;
}
}

Dave Sexton wrote:
> Hi,
>
> Interesting that works for you because I tried that and many variants but
> nothing worked for me (neither attachEvents nor direct assignment) but then
> again I was trying it with the WebBrowser control and the MSHTML PIA, so there
> could be inconstancies.
>
> Anyway, if you want to find the key that was pressed you need to access the
> event object on the IHTMLWindow2. Note however that in C# the event is a
> keyword so it must be accessed as follows (I think this only applies when
> using the PIA, IIRC):
>
> IHTMLWindow2 window = (IHTMLWindow2) winObj;
>
> // Using the Keys enumeration has worked for me in the past,
> // but you'll want to test it anyway just to be sure it works for you
> Keys keys = (Keys) window.@event.keyCode
>
> --
> Dave Sexton
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Amazingly I think I have it working. So for all you searching out
> > there. Try this:
> >
> > public class
> > {
> > DispatcherClass dp = new DispatcherClass();
> >
> > << do code to get the IHTMLElements >>
> > foreach (IHTMLElement myTag in allTag1)
> > {
> > myTag.onkeypress = dp;
> > }
> > }
> >
> > public DispatcherClass
> > {
> > [DispId(0)]
> > public void DefaultMethod()
> > {
> > // do your code
> > }
> > }
> > The key is the [DispId(0)]. This allows IDispatch to callback into my
> > C# code.
> >
> > Of course now I have the event firing I'm not exactly sure how to find
> > out which key was pressed. I also could not get
> > IHTMLElement2.attachEvents() to work. But that is for another day.
> >
> > Good luck.
> >
> >
> > Dave Sexton wrote:
> >> Hi,
> >>
> >> There is a lot of stuff on the web about this problem. I searched in
> >> groups.google.com for "dotnet default method" and read some MSDN articles
> >> as
> >> well (most pertaining to legacy VB).
> >>
> >> Basically, the HTML events require an IDispatch interface to invoke a
> >> default,
> >> parameterless method, which C# doesn't support. I tried a bunch of things
> >> using DispIdAttribute, ClassInterfaceAttribute and DispatchWrapper but I
> >> couldn't get it to work. Assignment always throws an InvalidCastException
> >> (presumably because I didn't go as far as implementing IDispatch
> >>
> >> In the 2.0 framework I use the HtmlElement.AttachEventHandler method, which
> >> allows me to supply an EventHandler delegate. Unfortunately, I doubt
> >> you'll
> >> be able to go that route because the class itself is dependant on the
> >> WebBrowser control, but you might want to take a peek at how it's
> >> accomplished
> >> in that class.
> >>
> >> --
> >> Dave Sexton
> >>
> >> <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> >I did try that.
> >> >
> >> > public delegate void F();
> >> > F f = delegate () { MessageBox.Show ("delegate");};
> >> > IHTMLElement2 h;
> >> > h.attachEvent ("oncut", f);
> >> >
> >> > Maybe the signature is not correct.
> >> >
> >> > I did try passing various other signatures for the delegate.
> >> >
> >> > If you have a specific example that would be great. I am stumped.
> >> > Duane
> >> >
> >> >
> >> > Dave Sexton wrote:
> >> >> Hi,
> >> >>
> >> >> The second parameter is the function pointer. Try passing in a
> >> >> delegate.
> >> >>
> >> >> --
> >> >> Dave Sexton
> >> >>
> >> >> <(E-Mail Removed)> wrote in message
> >> >> news:(E-Mail Removed)...
> >> >> >I have successfully installed a BHO in IE7. Using C#.
> >> >> >
> >> >> > Now I'm trying to figure out how to trap various events. onkeypress,
> >> >> > oncut, oncontextmenu, etc.
> >> >> >
> >> >> > I have tried calling in various IHTMLElement2.attachEvent, but no
> >> >> > success. attachEvent wants two parameters: event name, and object
> >> >> > pdisp.
> >> >> >
> >> >> > I cannot find the correct means to populate pdisp. Or is there
> >> >> > another
> >> >> > way to trap events from a BHO and C#?
> >> >> >
> >> >> > Any help would be greatly appreciated.
> >> >> >
> >> >> > Thanks.
> >> >> >
> >> >

> >


 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      26th Oct 2006
Hi,

Glad to help, but just FYI you don't have to attach an onkeypress handler to
every element.

Check out the section on even bubbling in the following article.

About the DHTML Object Model on MSDN:
http://msdn.microsoft.com/library/de...asp?frame=true

Also, you might be interested in implementing an Html Edit Designer if you
want to handle many events on many elements, or on a document that changes the
DOM frequently. I have gotten that to work using the WebBrowser control and
the MSHTML PIA, so I know it's possible, although it's commonly used for
browsers in design mode, but that's not necessary.

Implementing Edit Designers: The Basics on MSDN:
http://msdn.microsoft.com/library/de...asp?frame=true

--
Dave Sexton

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Fantastic. Thanks again for the push in the right direction. I now
> can see which key was pressed. Here is the basic code.
>
> public DispatcherClass(BHO callback)
> {
> m_callback = callback;
> }
> [DispId(0)]
> public void DefaultMethod()
> {
> Keys key = m_callback.CallBack();
> << do your code >>
> }
> =======================
> public class BHO
> {
> DispatcherClass dp;
>
> BHO()
> {
> dp = new DispatcherClass (this);
> }
>
> public Keys CallBack()
> {
> //m_window1 is the saved IHTMLWindow2 that I'm watching
> return (Keys)m_window1.@event.keyCode;
> }
>
> public someFunc()
> {
> << do code to get the IHTMLElements >>
> foreach (IHTMLElement myTag in allTag)
> {
> myTag.onkeypress = dp;
> }
> }
>
> Dave Sexton wrote:
>> Hi,
>>
>> Interesting that works for you because I tried that and many variants but
>> nothing worked for me (neither attachEvents nor direct assignment) but then
>> again I was trying it with the WebBrowser control and the MSHTML PIA, so
>> there
>> could be inconstancies.
>>
>> Anyway, if you want to find the key that was pressed you need to access the
>> event object on the IHTMLWindow2. Note however that in C# the event is a
>> keyword so it must be accessed as follows (I think this only applies when
>> using the PIA, IIRC):
>>
>> IHTMLWindow2 window = (IHTMLWindow2) winObj;
>>
>> // Using the Keys enumeration has worked for me in the past,
>> // but you'll want to test it anyway just to be sure it works for you
>> Keys keys = (Keys) window.@event.keyCode
>>
>> --
>> Dave Sexton
>>
>> <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Amazingly I think I have it working. So for all you searching out
>> > there. Try this:
>> >
>> > public class
>> > {
>> > DispatcherClass dp = new DispatcherClass();
>> >
>> > << do code to get the IHTMLElements >>
>> > foreach (IHTMLElement myTag in allTag1)
>> > {
>> > myTag.onkeypress = dp;
>> > }
>> > }
>> >
>> > public DispatcherClass
>> > {
>> > [DispId(0)]
>> > public void DefaultMethod()
>> > {
>> > // do your code
>> > }
>> > }
>> > The key is the [DispId(0)]. This allows IDispatch to callback into my
>> > C# code.
>> >
>> > Of course now I have the event firing I'm not exactly sure how to find
>> > out which key was pressed. I also could not get
>> > IHTMLElement2.attachEvents() to work. But that is for another day.
>> >
>> > Good luck.
>> >
>> >
>> > Dave Sexton wrote:
>> >> Hi,
>> >>
>> >> There is a lot of stuff on the web about this problem. I searched in
>> >> groups.google.com for "dotnet default method" and read some MSDN
>> >> articles
>> >> as
>> >> well (most pertaining to legacy VB).
>> >>
>> >> Basically, the HTML events require an IDispatch interface to invoke a
>> >> default,
>> >> parameterless method, which C# doesn't support. I tried a bunch of
>> >> things
>> >> using DispIdAttribute, ClassInterfaceAttribute and DispatchWrapper but I
>> >> couldn't get it to work. Assignment always throws an
>> >> InvalidCastException
>> >> (presumably because I didn't go as far as implementing IDispatch
>> >>
>> >> In the 2.0 framework I use the HtmlElement.AttachEventHandler method,
>> >> which
>> >> allows me to supply an EventHandler delegate. Unfortunately, I doubt
>> >> you'll
>> >> be able to go that route because the class itself is dependant on the
>> >> WebBrowser control, but you might want to take a peek at how it's
>> >> accomplished
>> >> in that class.
>> >>
>> >> --
>> >> Dave Sexton
>> >>
>> >> <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> >I did try that.
>> >> >
>> >> > public delegate void F();
>> >> > F f = delegate () { MessageBox.Show ("delegate");};
>> >> > IHTMLElement2 h;
>> >> > h.attachEvent ("oncut", f);
>> >> >
>> >> > Maybe the signature is not correct.
>> >> >
>> >> > I did try passing various other signatures for the delegate.
>> >> >
>> >> > If you have a specific example that would be great. I am stumped.
>> >> > Duane
>> >> >
>> >> >
>> >> > Dave Sexton wrote:
>> >> >> Hi,
>> >> >>
>> >> >> The second parameter is the function pointer. Try passing in a
>> >> >> delegate.
>> >> >>
>> >> >> --
>> >> >> Dave Sexton
>> >> >>
>> >> >> <(E-Mail Removed)> wrote in message
>> >> >> news:(E-Mail Removed)...
>> >> >> >I have successfully installed a BHO in IE7. Using C#.
>> >> >> >
>> >> >> > Now I'm trying to figure out how to trap various events.
>> >> >> > onkeypress,
>> >> >> > oncut, oncontextmenu, etc.
>> >> >> >
>> >> >> > I have tried calling in various IHTMLElement2.attachEvent, but no
>> >> >> > success. attachEvent wants two parameters: event name, and object
>> >> >> > pdisp.
>> >> >> >
>> >> >> > I cannot find the correct means to populate pdisp. Or is there
>> >> >> > another
>> >> >> > way to trap events from a BHO and C#?
>> >> >> >
>> >> >> > Any help would be greatly appreciated.
>> >> >> >
>> >> >> > Thanks.
>> >> >> >
>> >> >
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser Helper Object - BHO rogeepete Windows XP Internet Explorer 1 23rd Apr 2008 04:54 PM
How to create a browser helper object with a clickable icon at the corner of the browser? qwu2008@gmail.com Microsoft C# .NET 0 12th Sep 2006 04:38 PM
possible Browser Helper Object Rob R. Windows XP General 2 29th Jul 2004 10:08 PM
Browser Helper Object in VB.NET Joe Johnston Microsoft VB .NET 8 20th Nov 2003 12:44 PM
Re: Browser Helper object help Microsoft VB .NET 0 8th Nov 2003 07:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:22 PM.