Jump to content
Sign in to follow this  
Leudassdf

Problema ao adicionar texbox com BHO Internet explorer

Recommended Posts

Leudassdf

Boas pessoal,

Eu estou a tentar adicionar uma texbox a um website através do Browser Helper Object,no entanto como o website em que pretendo utilizar esta mesma texbox está cheio de frames eu não consigo visualizar a texbox. No entanto se eu for á pagina do google a texbox aparece. Pelo que consegui apurar a causa disto são aas frames no entanto nao consegui erceber porque e muito menos consegui resolver o problema. Se alguem souber como posso resolver este problema agradeço.

O codigo que tenho até agora:

Call bhoinput.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHDocVw;
using MSHTML;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Drawing;
namespace BHOInput
{
[ComVisible(true), Guid("8a194578-81ea-4850-9911-13ba2d71efbd"), ClassInterface(ClassInterfaceType.None)]
public class BHOInput : IObjectWithSite
{
	SHDocVw.WebBrowser BrowserIE;
	private object teste;
	public void OnDocumentComplete(object pDisp, ref object URL)
	{
		if (pDisp == teste)
		{
			if (URL.ToString().Contains("http://eu.eservice.asus.com/pf/Login1.do"))
			{
				try
				{
					//HtmlDocument doc = this.BrowserIE.Document;
					//doc.GetElementById("passwd").SetAttribute("Value", "123");
					System.Windows.Forms.MessageBox.Show("tese");
					TextBox txt = new System.Windows.Forms.TextBox();
					txt.Text = "testeiframe";
					txt.Location = new System.Drawing.Point(10, 150);


					String TextBox = "<div style='position:absolute; font-family:Comic Sans MS; font-size:14px; left:150px; top:100px; z-index:444; color:#000000; background:#FF9900; border:4px solid #888888;'>ola</div><input type='text' style='position:absolute; font-family:Comic Sans MS; font-size:14px; left:150px; top:150px; z-index:444; color:#000000; background:#FF9900; border:4px solid #888888;' value='TESTE'>";
					HTMLDocument documento = (HTMLDocument)BrowserIE.Document;
					documento.body.insertAdjacentHTML("afterBegin", TextBox);
				}
				catch {}
			}
		}
	}
	public int SetSite(object site)
	{
		if (site != null)
		{
			teste = site;
			BrowserIE = (SHDocVw.WebBrowser)site;
			BrowserIE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
		}
		else
		{
			BrowserIE.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
			BrowserIE = null;
		}
		return 0;
	}
	public int GetSite(ref Guid guid, out IntPtr ppvSite)
	{
		IntPtr punk = Marshal.GetIUnknownForObject(BrowserIE);
		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 RegistarBHO(Type type)
	{
		RegistryKey registar = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
		if (registar == null)
			registar = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
		string guid = type.GUID.ToString("B");
		RegistryKey ourKey = registar.OpenSubKey(guid, true);
		if (ourKey == null)
			ourKey = registar.CreateSubKey(guid);
		ourKey.SetValue("Alright", 1);
		registar.Close();
		ourKey.Close();
	}
	[ComUnregisterFunction]
	public static void RemoverRegistoBHO(Type type)
	{
		RegistryKey registar = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
		string guid = type.GUID.ToString("B");
		if (registar != null)
			registar.DeleteSubKey(guid, false);
	}
}
}

class IObjectWithSite.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace BHOInput
{
//GUID reference of IF
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]
//Declaration of the interface
public interface IObjectWithSite
{
	[PreserveSig]
	int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
	[PreserveSig]
	int GetSite(ref Guid guid, out IntPtr ppvSite);
}
}

Share this post


Link to post
Share on other sites
brunobola

Tenta utilizar uma cópia local do site ou testar num site mais básico e utiliza ferramentas de debugind por exemplo para o chrome tens a consola de programador e outros têm outros recursos.

Tens ainda para o Firefox um excelente que é o Firebug.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.