zoukankan      html  css  js  c++  java
  • 黄聪:C#禁止Webbrowser中的脚本错误提示,自动屏蔽弹出窗口

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    
    namespace Hcsem
    {
    
        public class MyWebBrowser : System.Windows.Forms.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;
                    //TODO:自定义 
                }
                void UnsafeNativeMethods.IDocHostShowUI.ShowHelp(ref UnsafeNativeMethods._RemotableHandle hwnd, string pszHelpFile, uint uCommand, uint dwData, UnsafeNativeMethods.tagPOINT ptMouse, object pDispatchObjectHit)
                {
                    //TODO:自定义 
                }
            }
    
            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
    
        }
    }
  • 相关阅读:
    Java-IO之DeflaterOutputStream和InflaterOutputStream
    myeclipse 破解步骤
    通过Nginx,Tomcat访问日志(access log)记录请求耗时
    关于封装了gevent的request grequest库的使用与讨论
    关于python性能相关测试cProfile库
    python threading模块使用 以及python多线程操作的实践(使用Queue队列模块)
    python格式化字符串Type Error: Format Requires Mapping 的问题
    关于flask自带web应用服务器Werkzeug 使用requests请求时出现的错误。
    关于python 自带csv库的使用心得 附带操作实例以及excel下乱码的解决
    pycharm5.0 快捷键大全osx
  • 原文地址:https://www.cnblogs.com/huangcong/p/4172154.html
Copyright © 2011-2022 走看看