 |
|
|
 |
|
|
 |
|
 |
Hi All,
i am working on project which requires logging user action on internet explorer.
I am able to get browsing event using BHO, but not able to log menu bar, toolbar events.
your valuable comments required.
Please help me!!
thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Dear Sumedh,
BHO provides event related to browser... and menu and tool bar are not part of browser... and even development of toolbar needs BHO..
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi EmersioN,
thanks for the comments,
can u provide some information/links about different ways for getting toolbar/menubar events.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
You can write Mouse hooks and on mouse events you can find active element by mouse position and you can have event details as well.. if control beneath is in tool bar then you can record it otherwise ignore it...
this is very typical way and hooks can crash your browser so becareful..
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Actually No... mshtml.HtmlImgClass gives you a HTML element IMG. Now form SRC attribute of IMG u can open stream and may get bytes of Image !!!
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I have read this page and impllemented the functionality but i couldn't got the right solution. i think i couldn't implemented it in right place.
Actually i am working with BHO, that works to get the URL of the site and access the contents/tags of iframe and for this i register it firstly.
public void OnDocumentComplete(object pDisp, ref object URL) { foreach (HTMLIFrame tempElement in document.getElementsByTagName ("iframe")) { System.Windows.Forms.MessageBox.Show(URL.ToString()); } }
public int SetSite(object site) { if (site != null) { webBrowser = (WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { webBrowser.DocumentComplete +=new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); webBrowser = null; } return 0; }
from this i am fetching the URL of the iframe but how can i access the tags of iframe?
and where i have to implement it?
Please give me a solution.
Thanx in advance.
Regards Harsh
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi harsh... do not use set site.. here is small snippet which will help you....
[Guid("Guid-Guid-Guid-Guid-Guid")] [BandObject("ToolBar", BandObjectStyle.Horizontal | BandObjectStyle.ExplorerToolbar, HelpText = "ToolBar")] [ComVisible(true), ClassInterface(ClassInterfaceType.None)] public partial class ToolBar : BandObject { public void ToolBar()
{ this.Load += new EventHandler(ToolBar_Load);
} void ToolBar_Load(object sender, EventArgs e) { try { this.Explorer.DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(Explorer_DownloadComplete); }catch(){} void Explorer_DownloadComplete() { try { IHTMLElementCollection elcol = htmlDoc.getElementsByTagName("iframe"); foreach (IHTMLElement iel in elcol) { HTMLFrameElement frm = (HTMLFrameElement)iel;
DispHTMLDocument doc = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frm).Document; MessageBox.Show(doc.body.innerHTML); } }catch(){ } }
Happy Coding...
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Emersion,
Here(below) is my complete code for getting an URL , and as you know that my next target to read the tags of iframe. and code mentioned by you is only to fetch the tags of iframe.
i have used this code but didnt get ant solution.
.........................................................................
IHTMLElementCollection elcol = htmlDoc.getElementsByTagName("iframe"); foreach (IHTMLElement iel in elcol) { HTMLFrameElement frm = (HTMLFrameElement)iel; DispHTMLDocument doc = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frm).Document; System.Windows.Forms.MessageBox.Show(doc.body.innerHTML); //do your processing here... } .........................................................................
and one thing more please describe me about BandObject class? and htmldoc object of which class? i think HtmlDocument, but will we assign any value in it before?
will you please mention that where i have to use your given code?
public void OnDocumentComplete(object pDisp, ref object URL) { foreach (HTMLIFrame tempElement in document.getElementsByTagName ("iframe")) { System.Windows.Forms.MessageBox.Show(URL.ToString()); } }
public int SetSite(object site) {
if (site != null) { webBrowser = (WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { webBrowser.DocumentComplete +=new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); webBrowser = null; } return 0; }
public int GetSite(ref Guid guid, out IntPtr ppvSite) { IntPtr punk = Marshal.GetIUnknownForObject(webBrowser); int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite); Marshal.Release(punk); return hr;
}
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction] public static void RegisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (registryKey == null) registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
string guid = type.GUID.ToString("B"); RegistryKey ourKey = registryKey.OpenSubKey(guid);
if (ourKey == null) ourKey = registryKey.CreateSubKey(guid);
ourKey.SetValue("Alright", 1); registryKey.Close(); ourKey.Close(); }
[ComUnregisterFunction] public static void UnregisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true); string guid = type.GUID.ToString("B");
if (registryKey != null) registryKey.DeleteSubKey(guid, false); }
}
Thanks in advance
Harsh.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi , Harsh
please read article by Pavel Zolnikov [^] on code project. this is nice article to understand BHO.. And the code i had posted..it is inheriting class from code of Pavel Zolnikov. He has done almost all things for us..including getSite and SetSite. And for rest of the the classes you must refer MSDN.
And final answer where to write a code? I had mentioned it in last answer to you... please refer that code again.. I have written a complete class demo that is inherited from BHo (of Pavel Zolnikov). and then Constructor, Load event of class and Document event as well.
HAppy Coding...
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi,
I have gone through the BandObject class, i found many things that are not useful for me , so i retrieved onle GetSite, SetSite function that i have already implemented and the remaining part u have given to me. i am using two functions fro registered and unregistered the dll from GAC. now dll not being registered.
"RegAsm : warning RA0000: Registering an unsigned assembly with /codebase can use your assembly to interface with other application that may be installed on the same computer."
something like this - this prob occured when we dont use public access modifier. but i am using public class ToolBar but sprob still remain same.
Waiting for ur reply
Harsh
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
here is my complete code, still it is not finding the tags of iframe. -------------------------------------------------------------------------
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using mshtml; using System.Web; using SHDocVw; using System.Diagnostics; using Microsoft.Win32;
namespace BHO_HelloWorld {
public class ToolBar : IObjectWithSite { SHDocVw.WebBrowser webBrowser; SHDocVw.WebBrowserClass Explorer = new WebBrowserClass(); public void ToolBar() { } public void Explorer_DownloadComplete(object pDisp, ref object URL) { try { System.Windows.Forms.MessageBox.Show(URL.ToString()); HTMLDocument htmlDoc = (HTMLDocument)this.Explorer.IWebBrowser_Document; IHTMLElementCollection elcol = htmlDoc.getElementsByTagName("iframe"); foreach (IHTMLElement iel in elcol) { HTMLFrameElement frm = (HTMLFrameElement)iel; DispHTMLDocument doc = (DispHTMLDocument)((SHDocVw.IWebBrowser2)frm).Document; System.Windows.Forms.MessageBox.Show(doc.body.innerHTML); //do your processing here... } } catch {//handle ex here } }//end of Explorer_DownloadComplete
public int SetSite(object site) {
if (site != null) { //System.Windows.Forms.MessageBox.Show("Harsh Kapoor"); webBrowser = (WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.Explorer_DownloadComplete); } else { // System.Windows.Forms.MessageBox.Show("HarshKapoor"); webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.Explorer_DownloadComplete); webBrowser = null; } return 0; }
public int GetSite(ref Guid guid, out IntPtr ppvSite) { IntPtr punk = Marshal.GetIUnknownForObject(webBrowser); int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite); Marshal.Release(punk); return hr;
}
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction] public static void RegisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (registryKey == null) registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
string guid = type.GUID.ToString("B"); RegistryKey ourKey = registryKey.OpenSubKey(guid);
if (ourKey == null) ourKey = registryKey.CreateSubKey(guid);
ourKey.SetValue("Alright", 1); registryKey.Close(); ourKey.Close(); }
[ComUnregisterFunction] public static void UnregisterBHO(Type type) { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true); string guid = type.GUID.ToString("B");
if (registryKey != null) registryKey.DeleteSubKey(guid, false); }
}//end of class
}
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello Harsh... Sorry for late reply..
I would like to suggest you...to inherit your tool bar...from
Pavel Zolnikov's Class.[^]
He has done most of the things and in Exact manner. please try to use it or Study it completely if you want to write your own.
Happy Coding !!
modified on Tuesday, January 27, 2009 11:20 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
i'm a noob to C# so sorry for the question
I'm using Pavel Zolnikov example. i've created a new class which inherit from HelloWorldBar there I have a function called ExplorerOnDocumentComplete. there I want to handle all the events. inside it i've entered your code
this is Pavel SetSite (the last line is mine)
. . try { object w; sp.QueryService( ref guid, ref riid, out w ); Explorer = (WebBrowserClass)Marshal.CreateWrapperOfType( w as IWebBrowser, typeof(WebBrowserClass) ); OnExplorerAttached(EventArgs.Empty); Explorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(ExplorerOnDocumentComplete);
does it should work that way? as my understanding if I want to rehook my events all the time then all the code (all the events I want to catch) should be inside my function, right?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
you should have code as like follows...
[Guid("AE07141B-45D4-4a98-5F68-0333EA26E115")] [BandObject("YourNewChildClass", BandObjectStyle.Horizontal | BandObjectStyle.ExplorerToolbar, HelpText = "YourNewChildClass")] [ComVisible(true), ClassInterface(ClassInterfaceType.None)] public partial class YourNewChildClass: BandObject {
. . . .
void YourNewChildClass_Load(object sender, EventArgs e) { try { this.Explorer.DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(Explorer_DownloadComplete); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
}
Happy Coding
!!
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
first of all, thanks EmersioN for your help I have 3 questions: 1. in the Mouse_Down event the browser stops after the messagebox. meaning when I'm clicking on a link(in explorer) i'm getting the messagebox but the browser doesnt redirect me to the page. what should I do? 2. how do I know which element fired the event? (button,checkbox, textbox, plain text)? 3. when i'm debugging ( by clicking F5 i'm getting an error "Error while trying to run the project: Unable to start debugging". do you know why i'm getting this ? (debuuging is working when i'm using "attach to process" )
thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
ok, thanks the post helped me but still dont know how to tell which element fired the event do I need to use the e.srcElement.innerHTML to know? or there is a better way ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
as i mentioned in first reply you can add html document completed (or load) event handler in load event of tool bar. and in html document completed(or load) event you can find element by id or name and can event handler for it.
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
for some reason this property is null what do I need to do to initialize it? I added: WebBrowserClass Explorer = new WebBrowserClass();
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi.. can you give exact piece of code and situation where this is occurring ?? do you mean
this.Explorer is null ?? please do provide some sort of your code.
EmersioN
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |