When an Ad Flash is flying over the browser and blocking the contents that you wish to read, it is really annoying. There had been quite a lot of different approaches to block Flash but we were not able to utilize those existing Flash blocker's functionality, well, since after many web sites started using Flash as their menu system, a tool for multimedia and so on. We can not blindly block them all. It become a "Catch-22".
Selectively Toggling Block/Unblock Flash
I am not a Flash expert, but there are two kinds of Flash, windowed Flash and windowless Flash. Windowed Flash is known to be faster than the latter while windowless Flash can have the transparency feature. The new Flash blocking method that I will show here will only apply for windowed Flash, but windowless Flash will be addressed later.
My approach is simply using the CBT hook and the window message subclassing feature. When BHO is being loaded into the IE site through
IObjectWithSite::SetSite, a CBT 'thread specific' hook is installed to monitor new window creation events, especially whose window class name is '
MacromediaFlashPlayerActiveX'. When a Flash window is found to be being created in the CBT hook procedure, a Flash window is subclassed again with a new message procedure ("FilterFlash.h"). In the new subclassed procedure's
WM_PAINT message handler, the '[Blocked Flash]' message in the white background will be displayed instead of the actual Flash contents. But if the user clicks on a specific Flash window, the clicked Flash's original window message procedure will be restored to display the Flash contents. Simple!
Note how I handled
WM_NCCREATE in "FiltherFlash.h". It is important to call Flash's original message procedure then subclass the Flash window 'again' since after calling Flash's original message procedure, our subclassing is getting reset somehow. Other than this, it's just simple windows subclassing and standard CBT hook procedure that everyone are already accustomed to.
Windowless Flash is mostly advertisement. Since they don't have a window, it is not possible to apply the above method to windowless Flash. So, I just copied the Flash blocking routine from John Osborn's Popup Blocker to hide Flash and animated GIFs. It is not a perfect method as windowless Flash can still be seen for a short time before the HTML page is completed loading, but it does work decently. As 'most' windowless Flash are ads, it seems reasonable to remove windowless Flash always. But, in case you want a certain Flash to be seen, I provided a temporary Flash blocking suspension key (customizable and one of ALT, CTRL, or SHIFT key).
I wrote this add-in for myself a year ago, and I've been used this for the whole last year without any problem. This add-in has proven to be very useful for me, and my little hope is that someone can port this to third party browsers so that I can use this feature while I am using them.