110,502
社区成员
发帖
与我相关
我的任务
分享
public class WebBrowser1 : WebBrowser
{
private const int DISPID_AMBIENT_DLCONTROL = -5512;
private int _controlFlags;
protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
{
return new WebBrowserSite1(this);
}
[DispId(DISPID_AMBIENT_DLCONTROL), Browsable(false)]
public int ControlFlags
{
get
{
return _controlFlags;
}
set
{
if (_controlFlags == value)
return;
_controlFlags = value;
IOleControl ctl = (IOleControl)ActiveXInstance;
ctl.OnAmbientPropertyChange(DISPID_AMBIENT_DLCONTROL);
}
}
// we want our site class, not the default one
protected class WebBrowserSite1 : WebBrowserSite, IReflect
{
private Dictionary<int, PropertyInfo> _dispidCache;
private WebBrowser1 _host;
public WebBrowserSite1(WebBrowser1 host)
: base(host)
{
_host = host;
}
object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
{
object ret = null;
// Check direct IDispatch call using a dispid (see http://msdn.microsoft.com/en-us/library/de3dhzwy.aspx)
const string dispidToken = "[DISPID=";
if (name.StartsWith(dispidToken))
{
int dispid = int.Parse(name.Substring(dispidToken.Length, name.Length - dispidToken.Length - 1));
if (_dispidCache == null)
{
// WebBrowser has many properties, so we build a dispid cache on it
_dispidCache = new Dictionary<int, PropertyInfo>();
foreach (PropertyInfo pi in _host.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if ((!pi.CanRead) || (pi.GetIndexParameters().Length > 0))
continue;
object[] atts = pi.GetCustomAttributes(typeof(DispIdAttribute), true);
if ((atts != null) && (atts.Length > 0))
{
DispIdAttribute da = (DispIdAttribute)atts[0];
_dispidCache[da.Value] = pi;
}
}
}
PropertyInfo property;
if (_dispidCache.TryGetValue(dispid, out property))
{
ret = property.GetValue(_host, null);
}
}
return ret;
}
FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr)
{
return this.GetType().GetFields(bindingAttr);
}
MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr)
{
return this.GetType().GetMethods(bindingAttr);
}
PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr)
{
return this.GetType().GetProperties(bindingAttr);
}
FieldInfo IReflect.GetField(string name, BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
MemberInfo[] IReflect.GetMember(string name, BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
MethodInfo IReflect.GetMethod(string name, BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
MethodInfo IReflect.GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
PropertyInfo IReflect.GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
{
throw new NotImplementedException();
}
PropertyInfo IReflect.GetProperty(string name, BindingFlags bindingAttr)
{
throw new NotImplementedException();
}
Type IReflect.UnderlyingSystemType
{
get { throw new NotImplementedException(); }
}
}
[Flags]
public enum AbBrowserDownloadControlFlags : int
{
/// <summary>
/// No flags are set.
/// </summary>
None = 0,
/// <summary>
/// The browser will operate in offline mode. Equivalent to DLCTL_FORCEOFFLINE.
/// </summary>
AlwaysOffline = unchecked((int)0x10000000),
/// <summary>
/// The browser will play background sounds. Equivalent to DLCTL_BGSOUNDS.
/// </summary>
BackgroundSounds = unchecked((int)0x00000040),
/// <summary>
/// Specifies that the browser will not run Active-X controls. Use this setting
/// to disable Flash movies. Equivalent to DLCTL_NO_RUNACTIVEXCTLS.
/// </summary>
DontRunActiveX = unchecked((int)0x00000200),
/// <summary>
/// Specifies that the browser should fetch the content from the server. If the server's
/// content is the same as the cache, the cache is used.Equivalent to DLCTL_RESYNCHRONIZE.
/// </summary>
IgnoreCache = unchecked((int)0x00002000),
/// <summary>
/// The browser will force the request from the server, and ignore the proxy, even if the
/// proxy indicates the content is up to date.Equivalent to DLCTL_PRAGMA_NO_CACHE.
/// </summary>
IgnoreProxy = unchecked((int)0x00004000),
/// <summary>
/// Specifies that the browser should download and display images. This is set by default.
/// Equivalent to DLCTL_DLIMAGES.
/// </summary>
Images = unchecked((int)0x00000010),
/// <summary>
/// Disables downloading and installing of Active-X controls.Equivalent to DLCTL_NO_DLACTIVEXCTLS.
/// </summary>
NoActiveXDownload = unchecked((int)0x00000400),
/// <summary>
/// Disables web behaviours.Equivalent to DLCTL_NO_BEHAVIORS.
/// </summary>
NoBehaviours = unchecked((int)0x00008000),
/// <summary>
/// The browser suppresses any HTML charset specified.Equivalent to DLCTL_NO_METACHARSET.
/// </summary>
NoCharSets = unchecked((int)0x00010000),
/// <summary>
/// Indicates the browser will ignore client pulls.Equivalent to DLCTL_NO_CLIENTPULL.
/// </summary>
NoClientPull = unchecked(0x20000000),
/// <summary>
/// The browser will not download or display Java applets.Equivalent to DLCTL_NO_JAVA.
/// </summary>
NoJava = unchecked((int)0x00000100),
/// <summary>
/// The browser will download framesets and parse them, but will not download the frames
/// contained inside those framesets.Equivalent to DLCTL_NO_FRAMEDOWNLOAD.
/// </summary>
NoFrameDownload = unchecked((int)0x00080000),
/// <summary>
/// The browser will not execute any scripts.Equivalent to DLCTL_NO_SCRIPTS.
/// </summary>
NoScripts = unchecked((int)0x00000080),
/// <summary>
/// If the browser cannot detect any internet connection, this causes it to default to
/// offline mode.Equivalent to DLCTL_OFFLINEIFNOTCONNECTED.
/// </summary>
OfflineIfNotConnected =unchecked((int)0x80000000),
/// <summary>
/// Specifies that UTF8 should be used.Equivalent to DLCTL_URL_ENCODING_ENABLE_UTF8.
/// </summary>
UTF8 = unchecked((int)0x00040000),
/// <summary>
/// The browser will download and display video media.Equivalent to DLCTL_VIDEOS.
/// </summary>
Videos = unchecked((int)0x00000020)
}
}