110,539
社区成员
发帖
与我相关
我的任务
分享
//定义IObjectWithSite接口
[
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);
}
//接口功能实现
[ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO:IObjectWithSite
{
WebBrowser webBrowser;
public void OnWebBrowser_FileDownload(ref bool Cancel)
{
System.Windows.Forms.MessageBox.Show("这是一个下载文件"); //此处无任何响应
webBrowser.Quit();
}
#region BHO Internal Functions
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction]
public static void RegisterBHO(Type type){//注册此组件//}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type){//解除此组件//}
public int SetSite(object site)
{
if (site != null)
{
webBrowser = (WebBrowser)site;
webBrowser.FileDownload+=new DWebBrowserEvents2_FileDownloadEventHandler(this.OnWebBrowser_FileDownload);//挂载事件处理
}
else
{
webBrowser.FileDownload -= new DWebBrowserEvents2_FileDownloadEventHandler(this.OnWebBrowser_FileDownload);
webBrowser = null;
}
return 0;
}
public int GetSite(ref Guid guid, out IntPtr ppvSite){//getsite实现}