WebBrowser拦截网页Alter消息
2011-01-28 13:53
357 查看
实现IDocHostShowUI接口
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; namespace WindowsFormsApplication7 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } MyWebBrowser MyWebBrowser1 = new MyWebBrowser(); private void Form1_Load(object sender, EventArgs e) { this.Controls.Add(MyWebBrowser1); MyWebBrowser1.Visible = true; MyWebBrowser1.Navigate("about:blank"); MyWebBrowser1.Document.Write("<mce:script type="text/javascript"><!-- alert('我就是确定按钮啊') // --></mce:script>"); } } public class MyWebBrowser : WebBrowser { #region ExtendedWebBrowserSite class ExtendedWebBrowserSite : WebBrowser.WebBrowserSite, UnsafeNativeMethods.IDocHostShowUI { public ExtendedWebBrowserSite(WebBrowser host) : base(host) { } void UnsafeNativeMethods.IDocHostShowUI.ShowMessage(ref UnsafeNativeMethods._RemotableHandle hwnd, string lpstrText, string lpstrCaption, uint dwType, string lpstrHelpFile, uint dwHelpContext, out int plResult) { plResult = 0; if (lpstrText == "我就是确定按钮啊") { if (MessageBox.Show("是否要屏蔽Alert对话框", "提示", MessageBoxButtons.YesNo) == DialogResult.No) { MessageBox.Show(lpstrText, lpstrCaption); } } } void UnsafeNativeMethods.IDocHostShowUI.ShowHelp(ref UnsafeNativeMethods._RemotableHandle hwnd, string pszHelpFile, uint uCommand, uint dwData, UnsafeNativeMethods.tagPOINT ptMouse, object pDispatchObjectHit) { } } protected override WebBrowserSiteBase CreateWebBrowserSiteBase() { return new ExtendedWebBrowserSite(this); } #endregion } public class UnsafeNativeMethods { #region IDocHostShowUI [StructLayout(LayoutKind.Explicit, Pack = 4)] public struct __MIDL_IWinTypes_0009 { // Fields [FieldOffset(0)] public int hInproc; [FieldOffset(0)] public int hRemote; } [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct _RemotableHandle { public int fContext; public __MIDL_IWinTypes_0009 u; } [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct tagPOINT { public int x; public int y; } [ComImport, Guid("C4D244B0-D43E-11CF-893B-00AA00BDCE1A"), InterfaceType((short)1)] public interface IDocHostShowUI { [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void ShowMessage([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrText, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrCaption, [In] uint dwType, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrHelpFile, [In] uint dwHelpContext, [ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.LONG_PTR")] out int plResult); [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] void ShowHelp([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string pszHelpFile, [In] uint uCommand, [In] uint dwData, [In] tagPOINT ptMouse, [Out, MarshalAs(UnmanagedType.IDispatch)] object pDispatchObjectHit); } #endregion } }
相关文章推荐
- axWebBrowser拦截网页Alter消息
- Delphi中WebBrowser拦截网页Alert对话框消息(转)
- Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法
- Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法(通过COM来改造)
- Delphi中WebBrowser拦截网页Alert对话框消息
- Delphi : 使用ApplicationEvents来拦截窗体消息,阻止WebBrowser右键菜单
- Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法
- Delphi中WebBrowser拦截网页Alert对话框消息(转)
- Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法
- 解决 winform打开网页 和WebBrowser打开链接360误报拦截的问题
- Delphi : WebBrowser改造,对网页中Alter等对话框的改造方法
- WCF消息拦截,利用消息拦截做身份验证服务
- 微信iOS消息拦截插件教程-Tweak HelloWorld
- 利用Webbrowser把网页保存为图片
- 谁是克星?4款网页木马拦截工具大比武
- C#网页数据采集(二)WebBrowser
- 用webBrowser打开网页出现脚本错误怎么办?
- 如何解决浏览器弹出窗口的拦截(如:网页支付)
- 微信公众帐号开发教程第7篇-文本消息中使用网页超链接