如何用DELPHI编程实现禁止浏览器弹出广告窗口?(50分)

  • 主题发起人 主题发起人 macrolen
  • 开始时间 开始时间
M

macrolen

Unregistered / Unconfirmed
GUEST, unregistred user!
同上....[:)]
 
可以,但需要管理员输入禁止弹出的网页的名称或所含有的内容,<br>在Webbrowser控件的新弹开窗口事件中加以判断,就可以啦
 
有原代码么?参考一下,急着用呢!macrolen@163.net
 
我做的浏览器现在并没有禁止,用户自己关去好了。<br>如果判别内容,会影响网页打开速度。<br>建议判断网址或网页名,控件中很方便的能得到
 
我曾经有一个用VC编的,运行后最小化到系统托盘后就再也没有广告弹出了![:(]
 
macrolen:万一那不是广告是重要的通知,你的程序可以分辨出来吗?
 
确实不好分辨<br>其实好多是判断新弹出的窗口有没有<br>菜单栏,没有的关闭<br>很可能误关的<br>
 
判断新弹出的窗口有没有菜单栏,没有的 第一次 别关,<br>询问,如果用户决定关,<br>记住标题的字串,以后再出现就关掉它好了。
 
看样子很复杂呀!其实我也不管它弹出的是不是广告,只要是在浏览时自动弹出的小窗口就关闭。<br>我做了一个,可连我点开连接的窗口都关闭了。谁有原码?给我研究研究!谢了![:)]
 
其实真正的好方法只能是看网址.看标题的话岂不是要等收到网页的信息才关,那不是浪费带宽吗?<br>针对国内的情况,也就是163的比较严重,它的网址是固定的,当跳出新窗口,看它的连接请求,如果符合过滤条件,关闭。<br>为了扩展性,可以把过滤网址写在一个文本文件里嘛。
 
源码方法的话参见本页面http://www.euromind.com/iedelphi/ie5tools/bho.htm<br><br>我个人认为应该输入网址列表,检查以后就可以关闭了吗。
 
下面是源码<br>unit unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,<br>&nbsp; Menus, ShellAPI, ExtCtrls;<br><br>const<br>&nbsp; ICON_ID = 1;<br>&nbsp; ICONEVENT = WM_USER + 1;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br>&nbsp; &nbsp; Pause: TMenuItem;<br>&nbsp; &nbsp; Continue: TMenuItem;<br>&nbsp; &nbsp; Quit: TMenuItem;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject); &nbsp; &nbsp;<br>&nbsp; &nbsp; procedure PauseClick(Sender: TObject);<br>&nbsp; &nbsp; procedure ContinueClick(Sender: TObject);<br>&nbsp; &nbsp; procedure QuitClick(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure InstallIcon;<br>&nbsp; &nbsp; procedure UnInstallIcon;<br>&nbsp; &nbsp; procedure IconOnClick(var message: TMessage); message ICONEVENT;<br>&nbsp; &nbsp; procedure ENumChildWindows(hand: HWND);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; IconData: TNotifyIconData;<br><br>implementation<br><br>{$R *.DFM}<br><br>{ TForm1 }<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; InstallIcon; //安装图标<br>&nbsp; Width:=0;<br>&nbsp; SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnInstallIcon; //卸载图标<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>&nbsp; h: HWnd;<br>&nbsp; Text: array [0..255] of char;<br>begin<br>&nbsp; h:=GetWindow(Handle, GW_HWNDFIRST);<br>&nbsp; while h &lt;&gt; 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; if GetWindowText(h, @Text, 255)&gt;0 then<br>&nbsp; &nbsp; if GetClassName(h, @Text, 255)&gt;0 then<br>&nbsp; &nbsp; if (StrPas(Text)='CabinetWClass') or (StrPas(Text)='IEFrame') then<br>&nbsp; &nbsp; &nbsp; ENumChildWindows(h);<br>&nbsp; &nbsp; h:=GetWindow(h, GW_HWNDNEXT);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.PauseClick(Sender: TObject);<br>begin<br>&nbsp; Timer1.Enabled:=False;<br>&nbsp; Pause.Checked:=true;<br>&nbsp; Continue.Checked:=False;<br>end;<br><br>procedure TForm1.ContinueClick(Sender: TObject);<br>begin<br>&nbsp; Timer1.Enabled:=True;<br>&nbsp; Pause.Checked:=False;<br>&nbsp; Continue.Checked:=true;<br>end;<br><br>procedure TForm1.QuitClick(Sender: TObject);<br>begin<br>&nbsp; Close;<br>end;<br><br>//安装图标<br>procedure TForm1.InstallIcon;<br>begin<br>&nbsp; IconData.cbSize:=SizeOf(IconData);<br>&nbsp; IconData.Wnd:=Handle;<br>&nbsp; IconData.uID:=ICON_ID;<br>&nbsp; IconData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>&nbsp; IconData.uCallBackMessage:=ICONEVENT;<br>&nbsp; IconData.hIcon:=Form1.Icon.Handle;;<br>&nbsp; IconData.szTip:='广告窗口杀手';<br>&nbsp; Shell_NotifyIcon(NIM_ADD, @IconData );<br>end;<br><br>//卸载图标<br>procedure TForm1.UnInstallIcon;<br>begin<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @IconData );<br>end;<br><br>//在图标上按下鼠标<br>procedure TForm1.IconOnClick(var message: TMessage);<br>var<br>&nbsp; p: TPoint;<br>begin<br>&nbsp; if (message.lParam = WM_LBUTTONDOWN) or (message.lParam = WM_RBUTTONDOWN) then<br>&nbsp; begin<br>&nbsp; &nbsp; GetCursorPos(p);<br>&nbsp; &nbsp; PopupMenu1.Popup(p.x ,p.y);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.ENumChildWindows(hand: HWND);<br>var<br>&nbsp; h: HWND;<br>&nbsp; s: Array[0..255] of char;<br>&nbsp; IsPopWindow: Bool;<br>begin<br>&nbsp; IsPopWindow:=True;<br>&nbsp; h:=GetWindow(hand,GW_child);<br>&nbsp; while h&gt;0 do<br>&nbsp; begin<br>&nbsp; &nbsp; GetClassName(h, s, 256);<br>&nbsp; &nbsp; if (StrPas(s)='WorkerA') or (StrPas(s)='WorkerW') then<br>&nbsp; &nbsp; If IsWindowVisible(h) then<br>&nbsp; &nbsp; &nbsp; IsPopWindow:=False;<br>&nbsp; &nbsp; h:=GetWindow(h,GW_HWNDNEXT);<br>&nbsp; end;<br>&nbsp; if IsPopWindow then<br>&nbsp; &nbsp; PostMessage(hand,WM_CLOSE,0,0);<br>end;<br><br>end.<br><br><br>
 
(转载自playicq)<br>让弹出式广告就地正法 &nbsp;<br>作者: tomore &nbsp;提出时间: 2002年6月6日 15:01 &nbsp;访问数:84 &nbsp; <br>大小:1,842字节<br><br><br>&nbsp;简介:<br>每当我浏览网站的时候,那扑面而来的广告窗口总是弄得我心烦意乱.<br>我下定决心要自己编一个查杀广告的程序.经过我的观察,<br>发现了广告窗口和正常IE窗口的区别主要在于广告窗口没有标题栏和状态栏<br>(其实它们也有,如果你不明白,请继续往下看!) <br><br>祭出我自编的软件-探索者(其实只不过是窗口类的显示器,当然也能看密码),<br>发现正常浏览窗口的类名是IEFRAME和CabinetWClass,而广告窗口的类名是CabinetWClass,<br>听说在Windows2000中也是IEFrame(未经证实).<br>其实是什么都无所谓,只要在程序中查找这两个类就可以了. <br><br>procedure TForm1.Timer1Timer(Sender: TObject); <br><br>var <br><br>mainHD,WorkAHD:THandle; <br><br>begin <br><br>// Kill AD. <br><br>mainHD:=FindWIndowEx(0,0,'CabinetWClass',nil); <br><br>if Mainhd&lt;&gt;0 then <br><br>begin <br><br>WorkAHD:=FindWindowEx(Mainhd,0,'WorkerA',nil); ////WorkerA类,具体关联见下图 <br><br>if WorkAHD=0 then PostMessage(Mainhd,WM_CLOSE,0,0); <br><br>end; <br><br>end; <br><br>通过在Timer事件中调用FindWindowEx函数可以查找到运行窗口的句柄,<br>具体介绍请见Delphi的Win32 API帮助.当我满心欢喜的运行程序时却发现广告窗口<br>一如往常的弹出,哪里出了错?继续祭出我的"探索者",先把IE浏览器的框架结构搞清楚,<br>功夫不负有心人,经过一下午的时间,终于让我找到了:<br>调试,却发现原来广告窗口同样具有上图的结构,这也让我的程序设计进程停滞不前,<br>经过两个晚上的思考,我终于想到另一个API函数:GetWindowRect,<br>它可以得到一个窗口的物理尺寸结构.马上调试,终于发现: <br><br>1.广告窗口的WorkerA类和Shell DocObject View类的rect.top的值是相同的; <br>2.正常IE窗口的WorkerA类和Shell DocObject View类的rect.top的值是不相同的; <br>马上更改代码,代码如下: <br><br>procedure TForm1.Timer1Timer(Sender: TObject); <br>var <br><br>mainHD,WorkAHD,ViewHD:THandle; <br><br>y_workA,y_view:integer; <br><br>rect1,rect2:TRect; <br><br>begin <br><br>// Kill AD. <br><br>mainHD:=FindWIndowEx(0,0,'CabinetWClass',nil); <br><br>if Mainhd&lt;&gt;0 then <br><br>begin <br><br>WorkAHD:=FindWindowEx(Mainhd,0,'WorkerA',nil); <br><br>GetwindowRect(WorkAHD,rect1); <br><br>y_workA:=rect1.top; <br><br>ViewHD:=FindWindowEx(mainHD,0,'Shell DocObject View',nil); <br><br>if viewHD&lt;&gt;0 then ////注1: <br><br>begin <br><br>GetwindowRect(ViewHD,rect2); <br><br>y_view:=rect2.top; <br><br>if y_View-y_WorkA&lt;5 then PostMessage(Mainhd,WM_CLOSE,0,0); <br><br>end; <br><br>end; <br><br>end; <br><br>程序的主要核心部分我已经给出来了,至于其它的,像:如何把程序添加到启动菜单,<br>最小化到任务栏中等等,这方面的介绍很多,我就不多言了. <br><br>本程序在Windows98SE和Delphi5.0下调试通过. <br><br>注1:其实资源管理器的类名也是"CabinetWClass",<br>但它不具有"Shell DocObject View".<br>如果不判断这一点,那么运行程序后,你连资源管理器也打不开了. &nbsp;<br>
 
只要能判断窗口中显示的 HTML 内容就行。<br>不过要怎么得到?...
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ExtCtrls, StdCtrls,registry;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; ieclassname:string;<br>&nbsp; deskwidth,deskheight:integer;<br>&nbsp; //strs:tstrings;<br>implementation<br><br>{$R *.dfm}<br>function enumchildprocs(wnd:hwnd;lparam:lparam):boolean;stdcall;<br>var<br>buffer1:array[0..255] of char;<br>begin<br>result:=true;<br>getclassname(wnd,buffer1,255);<br>//strs.Add(buffer1);<br>end;<br>&nbsp;function getiever(key:string):string;<br>&nbsp;var<br>&nbsp;reg:tregistry;<br>&nbsp;begin<br>&nbsp;reg:=tregistry.Create ;<br>&nbsp;reg.RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp;if reg.OpenKey('software/microsoft/internet explorer',false) then<br>&nbsp;begin<br>&nbsp;try<br>&nbsp;result:=reg.ReadString(key);<br>&nbsp;except<br>&nbsp;result:='';<br>&nbsp;end;<br>&nbsp;end<br>&nbsp;else<br>&nbsp;reg.Free;<br>&nbsp;end;<br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>h:thandle;<br>t:trect;<br>begin<br>timer1.Interval :=1000;<br>timer1.Enabled :=false;<br>//if getiever('version')[1]='5' then<br>//ieclassname:='CabinetWclass';<br>//if getiever('version')[1]='5' then<br>//ieclassname:='IEFrame';<br>//if getiever('version')[1]='6' then<br>ieclassname:='IEFrame';<br>h:=findwindow('progman',nil);<br>getwindowrect(h,t);<br>deskwidth:=t.Right-t.Left;<br>deskheight:=t.Bottom-t.Top;<br>//strs:=tstringlist.Create; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>iehandle,iehandle1,ie:thandle;<br>style:longint;<br>ierect:trect;<br>closeie:boolean;<br>i,c,h:integer;<br>ietext:array[0..255] of char;<br>begin<br>c:=0;<br>iehandle:=findwindow(pchar(ieclassname),nil);<br>//iehandle1:=findwindow('IEFrame',nil);<br>//strs.Clear;<br>//enumchildwindows(iehandle,@enumchildprocs,0);<br>{for i:=0 to strs.Count-1 do<br>begin<br>if strs='ReBarWindow32' then<br>begin<br>c:=1;<br>end;<br>end;<br>if c=0 then<br>begin<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;}<br>{iehandle1:=ChildWindowFromPointEx(iehandle,point(50,100),CWP_SKIPINVISIBLE);<br>ie:=FindWindowEx(iehandle,0,nil,'地址(&amp;D)');<br>if ie=0 then<br>begin<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;}<br>if iehandle&lt;&gt;0 then<br>begin<br>closeie:=false;<br>style:=getwindowlong(iehandle,gwl_style);<br>getwindowrect(iehandle,ierect);<br>if ((style and ws_sizebox)&lt;&gt;ws_sizebox) then<br>closeie:=true<br>else<br>with ierect do<br>begin<br>if (right-left&gt;160) and (right-left&lt;500) and (bottom-top&gt;37) and (bottom-top&lt;400) then<br>closeie:=true;<br>end;<br>if ((ierect.right-ierect.left)&gt;(deskwidth+10)) or ((ierect.Bottom-ierect.Top)&gt;(deskheight+10)) &nbsp;then<br>closeie:=true;<br>if &nbsp;((ierect.right-ierect.left)&lt;(deskwidth-10)) and ((ierect.right-ierect.left)&gt;(deskwidth div 2)) and ((ierect.Bottom-ierect.Top)&lt;(deskheight div 2 +30)) then<br>closeie:=true;<br>h:=getwindowtext(iehandle,ietext,256);<br>if (pos('脱机时无法使用',trim(ietext))&gt;0) or (pos('about:blank',ietext)&gt;0) or (pos('无法连接',ietext)&gt;0) or (pos('找不到服务器',ietext)&gt;0) &nbsp;then<br>closeie:=true;<br>end;<br>if closeie=true then<br>postmessage(iehandle,wm_syscommand,sc_close,0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>timer1.Enabled :=true;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>timer1.Enabled :=false;<br>end;<br>end.<br>
 
http://mydelphi.8u8.com/ym2.htm<br>Delphi园地<br>广告窗口杀手源码
 
后退
顶部