I used
WebBrowser
component from Toolbox to my Form in C#.
I have decided to reduce memory usage and I need to take its images off.
I found no function to do that in:
System.Windows.Forms.WebBrowser
Can anyone help me?
John Simmons / outlaw programmer wrote:
Are you allowing the user to browse, or are you providing the content programatically?
This program has two modes.
Regarding to its adjusted options, the user may see the webbrowser images or not. But, he/she can always see the webbrowser and the location that it is navigated in.
Christian Graus wrote:
I can't imagine either wanting to browse the web with no images, or having a computer with such a small amount of memory that I couldn't handle the images on the average website. I think you're chasing something totally unnecessary. However, the most basic[^] web search gives tons of info, so I guess there's enough of a reason that plenty of people are trying to do it.
I am running a BOT that runs a series of instructions on a webbrowser and the [professional] user have to know what the BOT is doing. On the other hand, this BOT may be run on a dedicated server and there is RAM and CPU usage limitation. In addition, running many instances of this program worsens the problem. Therefore the thing I am looking for is absolutely necessary. There are many websites but none of them worked. I'm looking for a person that have done such a work before.
:rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:
:rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:
:rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:
:rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:
Thank you
I solved the problem by modifying an example to a library that makes its usage easy. Just main class has to be derived from
myForm
instead of
Form
and also attribution
[ComVisible(true)]
has to be added before it. The function
BrowserLoadImages
helps the programmer to get permission to or prevent browser from loading images. It also is extendable.
using library::thumbsdown:
...
[ComVisible(true)]
public partial class Form1 : myFormSpace.myForm
{
...
BrowserLoadImages(this.webBrowser1, checkBox_DownloadImages.Checked);
...
library code::thumbsdown:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace myFormSpace
{
public enum BrowserOptions : uint
{
None = 0,
AlwaysOffline = 0x10000000,
BackgroundSounds = 0x00000040,
DontRunActiveX = 0x00000200,
IgnoreCache = 0x00002000,
IgnoreProxy = 0x00004000,
Images = 0x00000010,
NoActiveXDownload = 0x00000400,
NoBehaviours = 0x00008000,
NoCharSets = 0x00010000,
NoClientPull = 0x20000000,
NoJava = 0x00000100,
NoFrameDownload = 0x00080000,
NoScripts = 0x00000080,
OfflineIfNotConnected = 0x80000000,
UTF8 = 0x00040000,
Videos = 0x00000020
}
#region COM Interfaces
[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct MSG
{
public IntPtr hwnd;
public int message;
public IntPtr wParam;
public IntPtr lParam;
public int time;
public int pt_x;
public int pt_y;
}
[ComVisible(true), Guid("0000011B-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleContainer
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int ParseDisplayName([In, MarshalAs(UnmanagedType.Interface)] Object pbc,
[In, MarshalAs(UnmanagedType.LPWStr)] String pszDisplayName, [Out,
MarshalAs(UnmanagedType.LPArray)] int[] pchEaten, [Out,
MarshalAs(UnmanagedType.LPArray)] Object[] ppmkOut);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int EnumObjects([In, MarshalAs(UnmanagedType.U4)] uint grfFlags, [Out,
MarshalAs(UnmanagedType.LPArray)] Object[] ppenum);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int LockContainer([In, MarshalAs(UnmanagedType.Bool)] Boolean fLock);
}
[ComVisible(true), Guid("00000118-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleClientSite
{
[PreserveSig]
int SaveObject();
[PreserveSig]
int GetMoniker([In, MarshalAs(UnmanagedType.U4)] int dwAssign, [In, MarshalAs(UnmanagedType.U4)] int dwWhichMoniker, [MarshalAs(UnmanagedType.Interface)] out object moniker);
[PreserveSig]
int GetContainer(out object container);
[PreserveSig]
int ShowObject();
[PreserveSig]
int OnShowWindow(int fShow);
[PreserveSig]
int RequestNewObjectLayout();
}
[ComVisible(true), ComImport(),
Guid("00000112-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IOleObject
{
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetClientSite([In, MarshalAs(UnmanagedType.Interface)] IOleClientSite
pClientSite);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetClientSite([Out, MarshalAs(UnmanagedType.Interface)] out IOleClientSite site);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetHostNames([In, MarshalAs(UnmanagedType.LPWStr)] String
szContainerApp, [In, MarshalAs(UnmanagedType.LPWStr)] String
szContainerObj);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Close([In, MarshalAs(UnmanagedType.U4)] uint dwSaveOption);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetMoniker([In, MarshalAs(UnmanagedType.U4)] uint dwWhichMoniker, [In,
MarshalAs(UnmanagedType.Interface)] Object pmk);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetMoniker([In, MarshalAs(UnmanagedType.U4)] uint dwAssign, [In,
MarshalAs(UnmanagedType.U4)] uint dwWhichMoniker, [Out, MarshalAs(UnmanagedType.Interface)] out Object moniker);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int InitFromData([In, MarshalAs(UnmanagedType.Interface)] Object
pDataObject, [In, MarshalAs(UnmanagedType.Bool)] Boolean fCreation, [In,
MarshalAs(UnmanagedType.U4)] uint dwReserved);
int GetClipboardData([In, MarshalAs(UnmanagedType.U4)] uint dwReserved, out
Object data);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int DoVerb([In, MarshalAs(UnmanagedType.I4)] int iVerb, [In] IntPtr lpmsg,
[In, MarshalAs(UnmanagedType.Interface)] IOleClientSite pActiveSite, [In,
MarshalAs(UnmanagedType.I4)] int lindex, [In] IntPtr hwndParent, [In] RECT
lprcPosRect);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int EnumVerbs(out Object e);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int OleUpdate();
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int IsUpToDate();
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetUserClassID([In, Out] ref Guid pClsid);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetUserType([In, MarshalAs(UnmanagedType.U4)] uint dwFormOfType, [Out,
MarshalAs(UnmanagedType.LPWStr)] out String userType);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetExtent([In, MarshalAs(UnmanagedType.U4)] uint dwDrawAspect, [In]
Object pSizel);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetExtent([In, MarshalAs(UnmanagedType.U4)] uint dwDrawAspect, [Out]
Object pSizel);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Advise([In, MarshalAs(UnmanagedType.Interface)] System.Runtime.InteropServices.ComTypes.IAdviseSink pAdvSink, out
int cookie);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Unadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int EnumAdvise(out Object e);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetMiscStatus([In, MarshalAs(UnmanagedType.U4)] uint dwAspect, out int
misc);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetColorScheme([In] Object pLogpal);
}
[ComImport, Guid("B196B288-BAB4-101A-B69C-00AA00341D07"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleControl
{
[PreserveSig]
int GetControlInfo([Out] object pCI);
[PreserveSig]
int OnMnemonic([In] ref MSG pMsg);
[PreserveSig]
int OnAmbientPropertyChange(int dispID);
[PreserveSig]
int FreezeEvents(int bFreeze);
}
#endregion COM Interfaces
[ComVisible(true)]
public class myForm : Form, myFormSpace.IOleClientSite
{
public BrowserOptions webBrowserOptions = BrowserOptions.DontRunActiveX | BrowserOptions.NoClientPull | BrowserOptions.NoJava | BrowserOptions.NoActiveXDownload;
[DispId(-5512)]
public virtual int IDispatch_Invoke_Handler()
{
System.Diagnostics.Debug.WriteLine("-5512");
return (int)webBrowserOptions;
}
#region IOleClientSite Members
public int SaveObject()
{
return 0;
}
public int GetMoniker(int dwAssign, int dwWhichMoniker, out object moniker)
{
moniker = this;
return 0;
}
public int GetContainer(out object container)
{
container = this;
return 0;
}
public int ShowObject()
{
return 0;
}
public int OnShowWindow(int fShow)
{
return 0;
}
public int RequestNewObjectLayout()
{
return 0;
}
#endregion
public void BrowserLoadImages(WebBrowser wBrowser,bool showImages)
{
if (showImages)
webBrowserOptions |= BrowserOptions.Images;
else
webBrowserOptions &= ~BrowserOptions.Images;
IOleControl obj = (IOleControl)wBrowser.ActiveXInstance;
obj.OnAmbientPropertyChange(-5512);
}
}
}