|
I need to write a .NET MDI web browser that supports content filtering but I don't quite know where to start. I would like to filter content before it is displayed in the WebBrowser control but I don't know the best practice for doing this.
I want to change the HTML to remove links to sounds, Flash animations, images and whatever else is defined by the user.
It doesn't look as though any of the WebBrowser events will work. Same with the MSHTML DOM events.
Should I be doing this even farther up-stream? Perhaps using a proxy server object and filtering the content there?
- John
|
|
|
|
|
Two options :
- change programmatically IE settings, ( only while your app is running of course), so that animations and/or images are not downloaded or played.
Search codeproject for that. Someone showed how to do this in the past. (it is not a matter of hacking down the registry, because it would require the user relaunches the browser).
- you can host the web browser control, and subscribe for navigationcomplete events or the like. Doing so, you can access the HTML tree with the DOM API. You've got a starting point here[^]. And you've got hooking techniques here[^] and here[^].
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Thanks a lot Stephane. The two articles you posted will do the trick I think. I don't like the first because I believe it's inappropriate to globally modify IE settings. What if my app crashes and the changes don't get "undone."
I wasn't aware of the NavigateComplete2 bug in .NET but that would definitely explain why my modifications were not being reflected in the HTML in the browser.
If you were to write a browser application that would allow users to create customized filtering rules, would you utilize the hooking techniques in your articles or is there a different approach?
- John
|
|
|
|
|
Quite honestly, if I had the time I would not use IE at all. Better use a recompiled Mozilla or other programmable browsers with source code.
And put web page filtering on top of it.
What has stopped me many times already with programming IE is that there are many cases where the IE API doesn't work as expected. For instance, when you have frames in the web page, several events are not triggered at all, or you have to subscribe special things. None of this is documented. So it takes time, and there is no guarantee at all you succeed.
Besides that, IE uses multiple threads. One thread for each picture being downloaded for instance, which means it is hard to stop the process as a whole.
If you go start programming IE, then you may consider this scenario :
- I assume you've got the target URL
- use MSHTML as a COM object to download the html code from that URL. (you also could use the wininet library). Store it as a file. To do this, look for the MSDN sample called "Walkall" (C++ code).
- filter the html code
- add the <base href="URL"> tag inside the HTML code, in order to mimic the right base domain.
- ask IE to load this html code in the browser : document.load(...)
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Can anyone help...
Can anyone point me to a site with free .Net components specifically an Outlook bar.
Newby question: How can I align controls on the form. I want a panel to be aligned left on the form, but the Align menu options never become enabled.
TIA

|
|
|
|
|
Jinwah wrote:
Can anyone point me to a site with free .Net components specifically an Outlook bar.
Sure, right here: C# OutlookBar[^]
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
Jinwah wrote:
How can I align controls on the form. I want a panel to be aligned left on the form, but the Align menu options never become enabled.
Aligning aligns two or more controls to each other, not to the form. Thus if you select two or more controls, you'll get your align buttons. What you really want is Docking... check out the Dock property for your control.
Paul
|
|
|
|
|
Hi,
I'm thinking of capturing some regions of my screen
into a Bitmap object. Does anyone have any ideas?
Thanks
Li-kai Liu
|
|
|
|
|
Hi
Eric Gunnerson has a library available on GotDotNet.com[^]. The zip is called Win32window.zip, was a bit tricky to find. You can email me if you cant find it. Unfortunately its a bit long too paste
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
 try this...
public Bitmap CaptureWindow(string windowTitle)<br />
{<br />
RECT rect = new RECT();<br />
IntPtr windowDC;<br />
IntPtr dc1;<br />
IntPtr hWnd;<br />
<br />
if (windowTitle == null)<br />
{<br />
hWnd = FindWindow(null, "DISPLAY");<br />
windowDC = GetWindowDC(hWnd);<br />
rect.right = Screen.PrimaryScreen.Bounds.Width;<br />
rect.bottom = Screen.PrimaryScreen.Bounds.Height;<br />
}<br />
else<br />
{<br />
hWnd = FindWindow(null, windowTitle);<br />
windowDC = GetWindowDC(hWnd);<br />
int returnCode = GetWindowRgnBox(hWnd, ref rect);<br />
}<br />
<br />
Graphics g1 = Graphics.FromHdc(windowDC);<br />
Bitmap MyImage = new Bitmap(rect.right, rect.bottom, g1);<br />
Graphics g2 = Graphics.FromImage(MyImage);<br />
<br />
dc1 = g1.GetHdc();<br />
IntPtr dc2 = g2.GetHdc();<br />
<br />
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376);<br />
<br />
g1.ReleaseHdc(dc1);<br />
g2.ReleaseHdc(dc2);<br />
<br />
ReleaseDC(hWnd, windowDC);<br />
<br />
return MyImage;<br />
}<br />
<br />
[DllImportAttribute("gdi32.dll")]<br />
private static extern bool BitBlt(<br />
IntPtr hdcDest,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
IntPtr hdcSrc,
int nXSrc,
int nYSrc,
System.Int32 dwRop
);<br />
<br />
[DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr CreateDC(<br />
string lpszDriver,
string lpszDevice,
string lpszOutput,
IntPtr lpInitData
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr FindWindow(<br />
string lpClassName,
string lpWindowName
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr GetWindowDC(<br />
IntPtr hWnd
);<br />
<br />
[DllImportAttribute("User32.dll")]<br />
private static extern IntPtr ReleaseDC(<br />
IntPtr hWnd,
IntPtr hdc
);<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
struct RECT<br />
{<br />
public Int32 left; <br />
public Int32 top; <br />
public Int32 right; <br />
public Int32 bottom; <br />
}<br />
<br />
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]<br />
private static extern int GetWindowRgnBox(<br />
IntPtr hWnd,
ref RECT rect
);
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Philip Fitzsimons wrote:
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
}
OK, tell me, why dont you use the Rectangle struct defined in the .NET framework?
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
1. 'cause it did not occur to me.
2. 'cause I just translated the API directly, I was not trying to be clever
good point.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
No, I was just wondering. In my experience Rectangle and the other Drawing structs have been fine for marshalling. I have seen people this alot though...even MS people
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
are you saying we can re-write this
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern int GetWindowRgnBox(
IntPtr hWnd, // handle to window
ref RECT rect // rectangle
);
to
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern int GetWindowRgnBox(
IntPtr hWnd, // handle to window
ref Rectangle rect // rectangle
);
But wouldn't it be relatively confusing because the last two field actually mean different things (width, height in Rectangle, but right, bottom in RECT)...
|
|
|
|
|
Li-kai Liu (Angus) wrote:
are you saying we can re-write this
No! I was wrong. Thanx for pointing it out. For some strange bizarre reason, my brain recorded wrong info Or maybe I'm thinking of something completely different. I have tried to find it, but it was one of those snippets I wrote for someone, but never saved it. In fact, I found 16 blank WindowsApplictions in my code directory.
CHeers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Thanks your guys
I'm playing around with philips's code now. looks pretty nice.
When I tried to spot out the location of Win32windows.zip on
gotdotnet.com, I got lost... not well organized as codeproject
So, leppie, would you mind sending it to my mailbox at
ykliu@email-home.com?
Thanks again
Li-kai Liu
|
|
|
|
|
BTW, is that possible to include the cursor in the captured image??
|
|
|
|
|
I don't believe so, its handled by windows.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
I respect your ideas on this issue. Neither sounds very savory though.
I'd like to do what tools such as WebWasher and other popup and ad killers do. They filter the content before it arrives at the browser.
The two solutions you mentioned sound easier, but I'd rather it was elegant and right. I believe that WebWasher and similar tools modify (sic) IE's proxy setting and all communication is routed through the application.
I may go with something along these lines. It would eliminate some of the headaches that I would experience using Mozilla or the document.load() method.
Thanks again for your response. You've helped me greatly.
- John
|
|
|
|
|
BonTon wrote:
The two solutions you mentioned sound easier, but I'd rather it was elegant and right. I believe that WebWasher and similar tools modify (sic) IE's proxy setting and all communication is routed through the application.
Yes, I haven't talked about the solution where you have a local proxy server that forwards requests and gets pages back from the server.T That's easy code, merely multi-threaded socket. What is the problem here ? Usually it slowers down IE so abruptedly so that you end up uninstallin g it.
It's fun to code (I have done one a couple years ago), but there are side effects in the end.
Besides that, you need to change the IE proxy settings to make sure your proxy gets called, which is likely to raise trouble : I've got a lot of bad feedback about it from users.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Hey all,
I'm working on a mid-sized project and trying to do some class modeling. I was wondering if there is a good test that I can use when deciding if I should base a class on an actual interface data type as opposed to just having the class outright. For example, having:
public interface ICustomer{
...
}
public class Customer: ICustomer{
....
}
Is it a good idea to have interfaces (the datatype) for each class we model?
Thanks much
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
C# interfaces are not as great as COM interfaces. COM interfaces were supposed to act like a contract, and by the way do separate the interface from the actual implementation.
Using C# this is no longer true, as there is no more "header" files.
The only thing good about C# interfaces is that your class can derive from more than one interface, whereas your class cannot derive from more than one class (same Java limitation).
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
As C# is currently not having a const keyword for return values, I certainly would make an interface for structures that I want to pass as readonly.
Another thing to consider is whether the implementing structure needs to subclass something other than ICustomer, e.g; CPenquin: public ICustomer and CHuman: public ICustomer...
I also find code more readable when you pass interfaces with a limited number of members.
And last: using interfaces makes your code very flexible.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
You define an interface when you have two or more classes implementing common behavoir.
For example "Customer" and "Supplier" might both implement a IContact interface with methods for setting their address, name etc.
You only want to define an interface when there is more than one class that implements that interface, or if there might be in the future.
|
|
|
|
|
I have to agree with Stephane.
I always try look for places where interfaces will be beneficial, but rarely find such places. One example of the top of my head is for "late-binding". Other than that I find them only really useful in Collections. I'm still pretty new to C# (6 months) so maybe they will start making more sense later.
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|