要用的com和bho,好好学习把。】
不过一般都是用c++开发的,用.net没有多大意义哦

解决方案 »

  1.   

    推荐的入门级的文章哦 How to attach to Browser Helper Object (BHO) with C# in two minutes
    Introduction
    Microsoft provided Browser Helper Object (BHO) to let developers "drive" Internet Explorer. The first BHO was introduced in 1997 with IE 4.0. I have been writing programs on BHO for months. It could be quite depressing at the very first beginning to learn all those things. Hereby, I am writing this article to help beginners like me get familiar with BHO as soon as possible. Background 
    My personal interest is actually C++. C++ programs can be a lot less memory-consuming than C# programs. But C# does provide better service on BHO comparing to C++. My first BHO program was written in C++. It took me quite a while to figure out how to handle BHO under V C++. But C# only takes me few minutes. Meanwhile, C# has lots of pleasant designs such as foreach and type conversion. Process 
    To set up a BHO Hello World Project, Lets first start a C# Class Library, as BHO is written in .dll attached to IE. You dont need a Visual Studio 2005, C# express is totally enough. 
     
    After we have this empty project, let's add one folder named BHO and an empty .csfile into the folder. 
     The first file has to been named IObjectWithSite to notify that this is a BHO project. To know more about this interface, please refer to http://msdn2.microsoft.com/en-us/library/Aa768220.aspxWe also need to add two functions GetSite: Gets the last site set with IObjectWithSite::SetSite. If there is no known site, the object returns a failure code.SetSite: Provides the site's IUnknown pointer to the object.
            public interface IObjectWithSite
    {
                [PreserveSig]
                int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
                [PreserveSig]
                int GetSite(ref Guid guid, out IntPtr ppvSite);
            } Don't forget using System.Runtime.InteropServices;  
    Add another .cs file named BHO.cs Add a class called BHO in the newly added file(BHO.cs) . The class contains the interface IObjectWithSite    class BHO:IObjectWithSite
      
    To use BHO we need to have two references, SHDocVw.dll and MSHTML.dll.You can find them at Windows\System32 folderSHDocVw is Microsoft Shell Doc Object and Control LibraryMSHTML is: All interfaces for accessing the Dynamic HTML (DHTML) Object Model are based on IDispatch and are the basis of access to the object model that is also used by scripts. http://msdn2.microsoft.com/en-us/library/bb498651.aspxusing SHDocVw;
    using mshtml;
    using System.Runtime.InteropServices;   
    namespace BHO_HelloWorld

    class BHO:IObjectWithSite
    {}}
        
    have "using SHDocVw" is not enough, you need to add references to the project.  Add SHDocVw  Later we are going to use MessageBox, we also need to add Windows Form reference Now under BHO.cs:
    we add two variables into the class, WebBrowser and HTMLDocument. Just like their name, you could easily figure out what do they do. Besides the two methods we defined in the IObjectWithSite interface, we also need to add OnDocumentComplete. You can name the function anything you want as long as the parameters are the same as what's defined in CDHtmlDialog class. Later you need to carfully attach to an EventHandler. For the consistency of code, we name it OnDocumentComplete. OnDocumentComplete is a function of CDHtmlDialog Class http://msdn2.microsoft.com/en-us/library/8bed8k60(VS.80).aspx . It will be triggered if the HTMLDocument downloading is complete, in other words, when your page is loaded. You can also use Navigate() or OnBeforeNavigate(). Please refer to http://msdn2.microsoft.com/en-us/library/8k5z3ekh(VS.80).aspx to find out what you need exactly. class BHO: IObjectWithSite

     WebBrowser webBrowser;
    HTMLDocument document;
    publiv void OnDocumentComplete(object pDisp, ref object URL)
    {
     

    public void SetSite(object site)
    {
    }
     
    public int GetSite(ref Guid guid, out IntPtr ppvSite)
    {
     
    }}Under the IObjectWithSite.cs:you need to point out the GUID of IE for thei program, so it can attach to IE. 
        [
        ComVisible(true),
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
        Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
        ]        public interface IObjectWithSite
            {
                [PreserveSig]
                int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
                [PreserveSig]
                int GetSite(ref Guid guid, out IntPtr ppvSite);
            }Also, you need to assian a GUID for your own program under BHO.cs. You can use System.Guid.NewGuid() method to get one, which is really neat comparing to C++.     [
        ComVisible(true),
        Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
        ClassInterface(ClassInterfaceType.None)
        ]
      
      

  2.   

    推荐的入门级的文章哦 How to attach to Browser Helper Object (BHO) with C# in two minutes
    Introduction
    Microsoft provided Browser Helper Object (BHO) to let developers "drive" Internet Explorer. The first BHO was introduced in 1997 with IE 4.0. I have been writing programs on BHO for months. It could be quite depressing at the very first beginning to learn all those things. Hereby, I am writing this article to help beginners like me get familiar with BHO as soon as possible. Background 
    My personal interest is actually C++. C++ programs can be a lot less memory-consuming than C# programs. But C# does provide better service on BHO comparing to C++. My first BHO program was written in C++. It took me quite a while to figure out how to handle BHO under V C++. But C# only takes me few minutes. Meanwhile, C# has lots of pleasant designs such as foreach and type conversion. Process 
    To set up a BHO Hello World Project, Lets first start a C# Class Library, as BHO is written in .dll attached to IE. You dont need a Visual Studio 2005, C# express is totally enough. 
     
    After we have this empty project, let's add one folder named BHO and an empty .csfile into the folder. 
     The first file has to been named IObjectWithSite to notify that this is a BHO project. To know more about this interface, please refer to http://msdn2.microsoft.com/en-us/library/Aa768220.aspxWe also need to add two functions GetSite: Gets the last site set with IObjectWithSite::SetSite. If there is no known site, the object returns a failure code.SetSite: Provides the site's IUnknown pointer to the object.
            public interface IObjectWithSite
    {
                [PreserveSig]
                int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
                [PreserveSig]
                int GetSite(ref Guid guid, out IntPtr ppvSite);
            } Don't forget using System.Runtime.InteropServices;  
    Add another .cs file named BHO.cs Add a class called BHO in the newly added file(BHO.cs) . The class contains the interface IObjectWithSite    class BHO:IObjectWithSite
      
    To use BHO we need to have two references, SHDocVw.dll and MSHTML.dll.You can find them at Windows\System32 folderSHDocVw is Microsoft Shell Doc Object and Control LibraryMSHTML is: All interfaces for accessing the Dynamic HTML (DHTML) Object Model are based on IDispatch and are the basis of access to the object model that is also used by scripts. http://msdn2.microsoft.com/en-us/library/bb498651.aspxusing SHDocVw;
    using mshtml;
    using System.Runtime.InteropServices;   
    namespace BHO_HelloWorld

    class BHO:IObjectWithSite
    {}}
        
    have "using SHDocVw" is not enough, you need to add references to the project.  Add SHDocVw  Later we are going to use MessageBox, we also need to add Windows Form reference Now under BHO.cs:
    we add two variables into the class, WebBrowser and HTMLDocument. Just like their name, you could easily figure out what do they do. Besides the two methods we defined in the IObjectWithSite interface, we also need to add OnDocumentComplete. You can name the function anything you want as long as the parameters are the same as what's defined in CDHtmlDialog class. Later you need to carfully attach to an EventHandler. For the consistency of code, we name it OnDocumentComplete. OnDocumentComplete is a function of CDHtmlDialog Class http://msdn2.microsoft.com/en-us/library/8bed8k60(VS.80).aspx . It will be triggered if the HTMLDocument downloading is complete, in other words, when your page is loaded. You can also use Navigate() or OnBeforeNavigate(). Please refer to http://msdn2.microsoft.com/en-us/library/8k5z3ekh(VS.80).aspx to find out what you need exactly. class BHO: IObjectWithSite

     WebBrowser webBrowser;
    HTMLDocument document;
    publiv void OnDocumentComplete(object pDisp, ref object URL)
    {
     

    public void SetSite(object site)
    {
    }
     
    public int GetSite(ref Guid guid, out IntPtr ppvSite)
    {
     
    }}Under the IObjectWithSite.cs:you need to point out the GUID of IE for thei program, so it can attach to IE. 
        [
        ComVisible(true),
        InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
        Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")
        ]        public interface IObjectWithSite
            {
                [PreserveSig]
                int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
                [PreserveSig]
                int GetSite(ref Guid guid, out IntPtr ppvSite);
            }Also, you need to assian a GUID for your own program under BHO.cs. You can use System.Guid.NewGuid() method to get one, which is really neat comparing to C++.     [
        ComVisible(true),
        Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
        ClassInterface(ClassInterfaceType.None)
        ]
      
      

  3.   

    http://www.codeproject.com/useritems/Attach_BHO_with_C_.asp