473,230 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Browser Helper Object

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.

Oct 25 '06 #1
7 7056
Hi,

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

--
Dave Sexton

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>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.

Oct 25 '06 #2
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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.
Oct 25 '06 #3
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

<dw*******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
>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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
>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.

Oct 25 '06 #4
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

<dw*******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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.
Oct 26 '06 #5
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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

<dw*******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegr oups.com...
>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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
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.


Oct 26 '06 #6
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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

<dw*******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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.
Oct 26 '06 #7
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

<dw*******@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
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

<dw*******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegr oups.com...
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

<dw*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
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.

Oct 26 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JohnFol | last post by:
I am trying to make use of BHO's (and no not to write spyware). It seems all articles relate to C++, whereas my background si in VB.Net I've managed to understand that I need the following i/face...
3
by: Andrew Mayo | last post by:
(note: reason for posting here; browser helper object is written in C++; C++ developers tend to know the intricacies of message handling; this looks like a Windows messaging issue) Microsoft...
1
by: VP | last post by:
Could you guys please resolve this problem for me? My web form is accessing a Excel spreadsheet. I can read text info from (each cell) an excel spreadsheet. But, there's a Shape object in excel,...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
2
by: Joe Johnston | last post by:
I need a Browser Helper object written in VB. Please point me at a good example. Joe MCPx3
3
by: Joe Johnston | last post by:
I need a Browser Helper object written in VB.NET. Please point me at a good example. Joe MCPx3
8
by: Joe Johnston | last post by:
I need a Browser Helper object written in VB.NET Please point me at a good example. Joe MCPx3 ~ Hoping this MSDN ng three day turnaround is true. Additional info: What is a BHO? In its...
0
by: Sujoan | last post by:
Hi, I have added a button to the standard toolbar in Internet Explorer.I have a Browser Helper Object(Basically gets the source code of the web page) that works fine everytime web page gets...
1
by: Matthew Connor | last post by:
Hi all! I don't expect a complete run-down on such a broad question, but if someone could send me a link or just point me in the right direction, I would be very appreciative. I need to write a...
0
by: qwu2008 | last post by:
All, I wanted to create a browser helper object that has a clickable icon at the right corner of the browser (similar to the Google notebook icon at the right corner of the browser). When the user...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.