如何获取ie中的source code,url ?(高手请答)(200分)

  • 主题发起人 主题发起人 光棍
  • 开始时间 开始时间

光棍

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写一个监控程序,需要实现两个功能:<br>1.当鼠标移动到ie上面时,按一下热键就能能获取该网页的源文件,<br>并显示在监控程序的memo控件中。<br>2.当鼠标移动到ie某链接上时,可以捕获该url并添加在监控程序的listbox控件中<br>希望高手能讲解一下思路<br>
 
i qant know it too
 
右以通过剪切版实现数据传送。
 
到网络版中检索一下,已有这样的回答了。<br>要用到com接口。。。
 
<br>下面是我的一篇稿件,是关于添加一个ComboBox到IE任务栏中的,里面的图片我删除了,如果对你有帮助,别忘了给分 :-)<br><br>我们知道一些Internet软件能将自身功能集成在IE中,象网络蚂蚁。当设置了浏览器点击整合以后。如果用户点击IE页面中的指向.Exe、.Zip文件的连接后,蚂蚁会自动启动,下载连接指向地址的文件。这就是利用了IE扩展的功能实现的。<br>实现IE扩展的基本方法如下:建立一个COM服务器,编写代码使COM对象实现系统规定的若干接口(这些接口在Delphi的库中已经定义好了)。然后注册服务器并将COM对象的信息写入系统注册表中规定的位置。IE在运行时会通过注册表信息调用相应的COM对象中的方法从而实现IE扩展。<br>在下面的实例中,将建立一个IE工具栏(Explorer Bars)。在工具栏中放置一个按钮和一个下拉框,当用户点击按钮后,程序会自动获取IE页面中的所有电子邮件地址连接并将它添加到下拉列表框中。在这个范例内可以学习到如何在一个COM服务器中建立多个COM对象、在COM对象中实现多接口以及一些InternetExplorer对象的编程方法。<br><br>需要实现的接口<br>实现添加工具栏功能的COM对象需要实现以下的接口:<br>IDeskBand <br>IObjectWithSite <br>IPersistStream <br><br>IDeskBand接口用于处理工具栏,例如工具栏大小的改变,用户选择显示或隐藏工具栏等。接口在ShlObj.pas下有定义。<br>IObjectWithSite接口用于处理包含工具栏的对象, 在ActiveX.pas下有定义。<br>IPersistStream接口用于处理附加的信息。该接口并不需要,所以所有的方法都返回E_NOTIMPL,接口在ActiveX.pas下有定义。<br>这些接口的详细信息在微软的MSDN中都有详细的描述以及范例。<br><br>提示<br>MSDN(Microsoft Develop Network)是微软提供的Windows开发手册,也是最完整和翔实的Windows开发手册,包含了开发微软各个系统的帮助,Bug列表,范例等等。对于Windows下的程序员,无论是否使用微软的开发工具,都应该在自己的机器中安装MSDN。<br> <br>IE扩展的实现<br>同上面建立COM服务器一样,我们首先要建立一个ActiveX Library。将其保存为MailIEBand.Dpr;然后建立一个COM Object,将其保存为BandUnit.pas;然后建立一个Form,这个窗口将作为子窗口显示在IE工具栏中,将窗口的BorderStyle属性改为bsNone,添加一个TButton组件和一个TComboBox组件,将TButton的Caption属性改为获取全部,然后将窗口文件其保存为IEForm.pas。<br>在BandUnit中,需要建立一个实现上面提到的接口的TComObject对象。如下:<br>TGetMailBand = class(TComObject, IDeskBand, IObjectWithSite, IPersistStreamInit)<br><br>另外由于需要在COM服务器注册时添加一些注册表信息,所以还需要建立一个继承自TComObjectFactory类的对象,在对象的UpdateRegistry事件中编写代码添加附加的注册表信息。<br>下面的程序清单3-1到3-3是实现COM服务器的全部程序代码:<br><br>程序清单3-1 MailIEBand.dpr<br>library MailIEBand;<br><br>uses<br>&nbsp; ComServ,<br>&nbsp; BandUnit in 'BandUnit.pas',<br>&nbsp; IEForm in 'IEForm.pas' {Form1},<br>&nbsp; MailIEBand_TLB in 'MailIEBand_TLB.pas';<br><br>exports<br>&nbsp; DllGetClassObject,<br>&nbsp; DllCanUnloadNow,<br>&nbsp; DllRegisterServer,<br>&nbsp; DllUnregisterServer;<br><br>{$R *.TLB}<br><br>{$R *.RES}<br><br>begin<br>end.<br><br>程序清单3-2 BandUnit.pas<br><br>unit BandUnit;<br><br>interface<br><br>uses<br>&nbsp; Windows, Sysutils, Messages, Registry, Shellapi, ActiveX, Classes, ComObj,<br>&nbsp; &nbsp;Shlobj, Dialogs, Commctrl,ShDocVW,IEForm;<br><br>type<br>&nbsp; TGetMailBand = class(TComObject, IDeskBand, IObjectWithSite, IPersistStreamInit)<br>&nbsp; private<br>&nbsp; &nbsp; &nbsp; frmIE:TForm1;<br>&nbsp; &nbsp; &nbsp; m_pSite:IInputObjectSite;<br> &nbsp; m_hwndParent:HWND;<br> &nbsp; m_hWnd:HWND;<br> &nbsp; m_dwViewMode:Integer;<br>&nbsp; &nbsp; &nbsp; m_dwBandID:Integer;<br>&nbsp; &nbsp;protected<br><br>&nbsp; &nbsp;public<br>&nbsp; &nbsp; {Declare IDeskBand methods here}<br>&nbsp; &nbsp; &nbsp; function GetBandInfo(dwBandID, dwViewMode: DWORD; var pdbi: TDeskBandInfo):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function ShowDW(fShow: BOOL): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function CloseDW(dwReserved: DWORD): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function ResizeBorderDW(var prcBorder: TRect; punkToolbarSite: IUnknown;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fReserved: BOOL): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function GetWindow(out wnd: HWnd): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function ContextSensitiveHelp(fEnterMode: BOOL): HResult; stdcall;<br><br>&nbsp; &nbsp; &nbsp; {Declare IObjectWithSite methods here}<br>&nbsp; &nbsp; &nbsp; function SetSite(const pUnkSite: IUnknown ):HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function GetSite(const riid: TIID; out site: IUnknown):HResult;stdcall;<br><br>&nbsp; &nbsp; &nbsp; {Declare IPersistStream methods here}<br>&nbsp; &nbsp; &nbsp; function GetClassID(out classID: TCLSID): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function IsDirty: HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function InitNew: HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function Load(const stm: IStream): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function Save(const stm: IStream; fClearDirty: BOOL): HResult; stdcall;<br>&nbsp; &nbsp; &nbsp; function GetSizeMax(out cbSize: Largeint): HResult; stdcall;<br>&nbsp; end;<br><br>const<br>&nbsp; Class_GetMailBand: TGUID = '{954F618B-0DEC-4D1A-9317-E0FC96F87865}';<br>&nbsp; //以下是系统接口的IID<br>&nbsp; IID_IUnknown: TGUID = (<br>&nbsp; &nbsp; &nbsp; D1:$00000000;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));<br>&nbsp; IID_IOleObject: TGUID = (<br>&nbsp; &nbsp; &nbsp; D1:$00000112;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));<br>&nbsp; IID_IOleWindow: TGUID = (<br>&nbsp; &nbsp; &nbsp; D1:$00000114;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));<br><br>&nbsp; IID_IInputObjectSite : TGUID = (<br>&nbsp; &nbsp; &nbsp; D1:$f1db8392;D2:$7331;D3:$11d0;D4:($8C,$99,$00,$A0,$C9,$2D,$BF,$E8));<br>&nbsp; sSID_SInternetExplorer : TGUID = '{0002DF05-0000-0000-C000-000000000046}';<br>&nbsp; sIID_IWebBrowserApp : TGUID= '{0002DF05-0000-0000-C000-000000000046}';<br><br>&nbsp; //面板所允许的最小宽度和高度。<br>&nbsp; MIN_SIZE_X = 54;<br>&nbsp; MIN_SIZE_Y = 22;<br>&nbsp; EB_CLASS_NAME = 'GetMailAddress';<br>implementation<br><br>uses ComServ;<br><br><br>function TGetMailBand.GetWindow(out wnd: HWnd): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;wnd:=m_hWnd;<br>&nbsp; &nbsp;Result:=S_OK;<br>end;<br><br>function TGetMailBand.ContextSensitiveHelp(fEnterMode: BOOL): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=E_NOTIMPL;<br>end;<br><br>function TGetMailBand.ShowDW(fShow: BOOL): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;if m_hWnd&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; if fShow then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(m_hWnd,SW_SHOW)<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowWindow(m_hWnd,SW_HIDE);<br>&nbsp; &nbsp;Result:=S_OK;<br>end;<br><br>function TGetMailBand.CloseDW(dwReserved: DWORD): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;if frmIE&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; frmIE.Destroy;<br>&nbsp; &nbsp;Result:= S_OK;<br>end;<br><br>function TGetMailBand.ResizeBorderDW(var prcBorder: TRect;<br>&nbsp; &nbsp; &nbsp; punkToolbarSite: IUnknown;fReserved: BOOL): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=E_NOTIMPL;<br>end;<br><br>function TGetMailBand.SetSite(const pUnkSite: IUnknown):HResult;stdcall;<br>var<br>&nbsp; &nbsp;pOleWindow:IOleWindow;<br>&nbsp; &nbsp;pOLEcmd:IOleCommandTarget;<br>&nbsp; &nbsp;pSP:IServiceProvider;<br>&nbsp; &nbsp;rc:TRect;<br>begin<br>&nbsp; &nbsp;if Assigned(pUnkSite) then begin<br>&nbsp; &nbsp; &nbsp; m_hwndParent := 0;<br><br>&nbsp; &nbsp; &nbsp; m_pSite:=pUnkSite as IInputObjectSite;<br>&nbsp; &nbsp; &nbsp; pOleWindow := PunkSIte as IOleWindow;<br>&nbsp; &nbsp; &nbsp; //获得父窗口IE面板窗口的句柄<br>&nbsp; &nbsp; &nbsp; pOleWindow.GetWindow(m_hwndParent);<br><br>&nbsp; &nbsp; &nbsp; if(m_hwndParent=0)then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := E_FAIL;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; //获得父窗口区域<br>&nbsp; &nbsp; &nbsp; GetClientRect(m_hwndParent, rc);<br><br>&nbsp; &nbsp; &nbsp; if not Assigned(frmIE) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//建立TIEForm窗口,父窗口为m_hwndParent<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;frmIE:=TForm1.CreateParented(m_hwndParent);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_Hwnd:=frmIE.Handle;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetWindowLong(frmIE.Handle, GWL_STYLE, GetWindowLong(frmIE.Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GWL_STYLE) Or WS_CHILD);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//根据父窗口区域设置窗口位置<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with frmIE do begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Left :=rc.Left ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Top:=rc.top;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width:=rc.Right - rc.Left;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Height:=rc.Bottom - rc.Top;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;frmIE.Visible := True;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//获得与浏览器相关联的Webbrowser对象。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pOLEcmd:=pUnkSite as IOleCommandTarget;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pSP:=pOLEcmd as &nbsp;IServiceProvider;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(pSP)then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pSP.QueryService(IWebbrowserApp, IWebbrowser2,frmIE.IEThis);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br><br>&nbsp; &nbsp;Result := S_OK;<br>end;<br><br>function TGetMailBand.GetSite(const riid: TIID; out site: IUnknown):HResult;stdcall;<br>begin<br>&nbsp; &nbsp;if Assigned(m_pSite) then result:=m_pSite.QueryInterface(riid, site)<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp;Result:= E_FAIL;<br>end;<br><br>function TGetMailBand.GetBandInfo(dwBandID, dwViewMode: DWORD; var pdbi: TDeskBandInfo):<br>&nbsp; &nbsp; &nbsp; HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=E_INVALIDARG;<br>&nbsp; &nbsp;if not Assigned(frmIE) then frmIE:=TForm1.CreateParented(m_hwndParent);<br>&nbsp; &nbsp;if(@pdbi&lt;&gt;nil)then begin<br>&nbsp; &nbsp; &nbsp; m_dwBandID := dwBandID;<br>&nbsp; &nbsp; &nbsp; m_dwViewMode := dwViewMode;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_MINSIZE)&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptMinSize.x := MIN_SIZE_X;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptMinSize.y := MIN_SIZE_Y;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_MAXSIZE)&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptMaxSize.x := -1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptMaxSize.y := -1;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_INTEGRAL)&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptIntegral.x := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptIntegral.y := 1;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_ACTUAL)&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptActual.x := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.ptActual.y := 0;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_MODEFLAGS)&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.dwModeFlags := DBIMF_VARIABLEHEIGHT;<br><br>&nbsp; &nbsp; &nbsp; if(pdbi.dwMask and DBIM_BKCOLOR)&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pdbi.dwMask := pdbi.dwMask and (not DBIM_BKCOLOR);<br>&nbsp; &nbsp;end;<br>end;<br><br><br>function TGetMailBand.GetClassID(out classID: TCLSID): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;classID:= Class_GetMailBand;<br>&nbsp; &nbsp;Result:=S_OK;<br>end;<br><br>function TGetMailBand.IsDirty: HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=S_FALSE;<br>end;<br><br>function TGetMailBand.InitNew: HResult;<br>begin<br>&nbsp; Result := E_NOTIMPL;<br>end;<br><br>function TGetMailBand.Load(const stm: IStream): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=S_OK;<br>end;<br><br>function TGetMailBand.Save(const stm: IStream; fClearDirty: BOOL): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=S_OK;<br>end;<br><br>function TGetMailBand.GetSizeMax(out cbSize: Largeint): HResult; stdcall;<br>begin<br>&nbsp; &nbsp;Result:=E_NOTIMPL;<br>end;<br><br><br>//TIEClassFac类实现COM组件的注册<br>type<br>&nbsp; &nbsp;TIEClassFac=class(TComObjectFactory) //<br>&nbsp; &nbsp;public<br>&nbsp; &nbsp; &nbsp; procedure UpdateRegistry(Register: Boolean); override;<br>&nbsp; &nbsp;end;<br><br>procedure TIEClassFac.UpdateRegistry(Register: Boolean);<br>var<br>&nbsp; ClassID: string;<br>&nbsp; a:Integer;<br>begin<br>&nbsp; &nbsp;inherited UpdateRegistry(Register);<br>&nbsp; &nbsp;if Register then begin<br>&nbsp; &nbsp; &nbsp;ClassID:=GUIDToString(Class_GetMailBand);<br>&nbsp; &nbsp; &nbsp;with TRegistry.Create do<br>&nbsp; &nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//添加附加的注册表项<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenKey('/SOFTWARE/Microsoft/Internet Explorer/Toolbar',False);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteBinaryData(GUIDToString(Class_GetMailBand),a,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenKey('/SOFTWARE/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved',True);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteString (GUIDToString(Class_GetMailBand),EB_CLASS_NAME);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RootKey:=HKEY_CLASSES_ROOT;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenKey('/CLSID/'+GUIDToString(Class_GetMailBand),False);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteString('',EB_CLASS_NAME);<br>&nbsp; &nbsp; &nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Free;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else begin<br>&nbsp; &nbsp; &nbsp; with TRegistry.Create do<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenKey('/SOFTWARE/Microsoft/Internet Explorer/Toolbar',False);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DeleteValue(GUIDToString(Class_GetMailBand));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OpenKey('/Software/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved',False);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DeleteValue(GUIDToString(Class_GetMailBand));<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Free;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br>end;<br><br>initialization<br>&nbsp; &nbsp;TIEClassFac.Create(ComServer, TGetMailBand, Class_GetMailBand,<br>&nbsp; &nbsp; &nbsp; 'GetMailAddress', '', ciMultiInstance, tmApartment);<br>end.<br><br>程序清单3-3 IEForm.pas<br><br>unit IEForm;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; SHDocVw,MSHTML, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; procedure FormResize(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; IEThis:IWebbrowser2;<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormResize(Sender: TObject);<br>begin<br>&nbsp; With Button1 do begin<br>&nbsp; &nbsp; Left := 0;<br>&nbsp; &nbsp; Top := 0;<br>&nbsp; &nbsp; Height:=Self.ClientHeight;<br>&nbsp; end;<br>&nbsp; With ComboBox1 do begin<br>&nbsp; &nbsp; Left := Button1.Width +3;<br>&nbsp; &nbsp; Top := 0;<br>&nbsp; &nbsp; Height:=Self.ClientHeight;<br>&nbsp; &nbsp; Width:=Self.ClientWidth - Left;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; doc:IHTMLDocument2;<br>&nbsp; all:IHTMLElementCollection;<br>&nbsp; len,i,flag:integer;<br>&nbsp; item:IHTMLElement;<br>&nbsp; vAttri:Variant;<br>begin<br>&nbsp; if Assigned(IEThis)then begin<br>&nbsp; &nbsp; ComboBox1.Clear;<br>&nbsp; &nbsp; //获得Webbrowser对象中的文档对象<br>&nbsp; &nbsp; doc:=IEThis.Document as IHTMLDocument2;<br>&nbsp; &nbsp; //获得文档中所有的HTML元素集合<br>&nbsp; &nbsp; all:=doc.Get_all;<br><br>&nbsp; &nbsp; len:=all.Get_length;<br><br>&nbsp; &nbsp; //访问HTML元素集合中的每一个元素<br>&nbsp; &nbsp; for i:=0 to len-1 do begin<br>&nbsp; &nbsp; &nbsp; item:=all.item(i,varempty) as IHTMLElement;<br>&nbsp; &nbsp; &nbsp; //如果该元素是一个链接<br>&nbsp; &nbsp; &nbsp; if item.Get_tagName = 'A'then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; flag:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; vAttri:=item.getAttribute('protocol',flag); &nbsp; &nbsp; //获得链接属性<br>&nbsp; &nbsp; &nbsp; &nbsp; //如果是mailto链接则将链接的目标地址添加到ComboBox1<br>&nbsp; &nbsp; &nbsp; &nbsp; if vAttri = 'mailto:'then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vAttri:=item.getAttribute('href',flag);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ComboBox1.Items.Add(vAttri);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>end.<br><br>编译工程,关闭所有的IE窗口,然后点击Delphi菜单的Run | Register ActiveX Server 项注册服务器。然后打开IE,点击菜单 察看 | 工具栏 项,可以看到子菜单中多了一个GetMailAddress项,选中改项,工具栏就出现在IE工具栏中,如图:<br><br>&nbsp;<br>图1-6 IE工具栏<br><br>点击 获取地址 按钮,就可以将当前页面中的Mail地址统统添加到ComboBox1中。<br>注意上面的IEForm.pas引用到了MSHTML,微软IE的整个结构如下图所示:<br>&nbsp;<br>图1-7 IE基本架构<br><br>其中MSHTML是位于SHDOCVW和HTML页面之间的对象。SHDOCVW对象用于处理页面的显示,而MSHTML用于处理页面的语法分析。它可以将页面中的标记(例如&lt;P&gt;&lt;/P&gt;、&lt; A href&gt;&lt;/A&gt;)转换为元素,同时它MSHTML又是一个COM服务器,允许客户端访问。所以上面TForm1.Button1Click部分的代码:<br><br>if Assigned(IEThis)then begin<br>&nbsp; &nbsp; ComboBox1.Clear;<br>&nbsp; &nbsp; //获得Webbrowser对象中的文档对象<br>&nbsp; &nbsp; doc:=IEThis.Document as IHTMLDocument2;<br>&nbsp; &nbsp; //获得文档中所有的HTML元素集合<br>&nbsp; &nbsp; all:=doc.Get_all;<br><br>&nbsp; &nbsp; len:=all.Get_length;<br><br>&nbsp; &nbsp; //访问HTML元素集合中的每一个元素<br>&nbsp; &nbsp; for i:=0 to len-1 do begin<br>&nbsp; &nbsp; &nbsp; item:=all.item(i,varempty) as IHTMLElement;<br>&nbsp; &nbsp; &nbsp; //如果该元素是一个链接<br>&nbsp; &nbsp; &nbsp; if item.Get_tagName = 'A'then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; flag:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; vAttri:=item.getAttribute('protocol',flag); &nbsp; &nbsp; //获得链接属性<br>&nbsp; &nbsp; &nbsp; &nbsp; //如果是mailto链接则将链接的目标地址添加到ComboBox1<br>&nbsp; &nbsp; &nbsp; &nbsp; if vAttri = 'mailto:'then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vAttri:=item.getAttribute('href',flag);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ComboBox1.Items.Add(vAttri);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>就是通过MSHTML定义的接口访问页面中的元素并获得链接元素中的地址。<br><br>
 
学了点东东
 
dana大哥的回答忽视一个问题:FRAME<br><br>此方法不能解决带Frame or iFrame的页面。
 
我也正为此事发愁,有谁知道别忘了告诉我一声! &nbsp;
 
想看VC源码吗?49.5KB,MSDN上当下来的,人家现成写好的。<br>到msdn可看到截图。<br><br>想要Delphi的,那么去http://www.euromind.com/iedelphi/<br>查资料吧。
 
http://eagleboost.myrice.com/issues/Materials/Materials.htm
 
&lt;font color="#FF0000"&gt;<br>大家帮帮忙,给看一下&lt;/font&gt;&lt;/p&gt;<br><br>&lt;p align="left"&gt;<br>&amp;nbsp;<br>&lt;font color="#FF0000" size="4"&gt;<br>&lt;a href="http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=506445"&gt;<br>“寻找简单的方法,filter消息”&lt;/a&gt;<br>&lt;/font&gt;&lt;/p&gt;<br><br>&lt;p align="left"&gt;如有违反论坛规则,还请版主砍掉并批评指出&lt;/p&gt;
 
这是我做的程序的源代码,要使用mshtml,SHdocvw单元,这可是我查了n本书,上了n个外国网站才学到的呀.<br>procedure TMainfrm.SbtnAntiClick(Sender: TObject);<br>var<br>xwin:IShellWindows;<br>xweb:iWebbrowser2;<br>i:integer;<br>tempdoc:IHTMLdocument2;<br>tempnumofwebpage:Integer;<br>url:AnsiString;<br>begin<br>//此处要对全局变量CUrwebpage清空<br>LBCurwebpage.Clear;<br>NumOfCurWebPage:=0;<br>tempnumofwebpage:=0;<br>Notebookpage.ActivePage:='Nbanti';<br>//列表初始化<br>xWin:=CoShellWindows.Create;<br>&nbsp;for i:=0 to xWin.Count-1 do<br>&nbsp; begin<br>&nbsp; &nbsp;xWeb:=xWin.Item(i) as IWebbrowser2;//注意<br>&nbsp; &nbsp;url:=xweb.LocationURL;<br>&nbsp; if (((leftstr(url,7)='http://')<br>&nbsp; &nbsp; &nbsp;or (leftstr(url,7)='file://')) and (xweb&lt;&gt;nil)and (not IsLocalDrive(url))) &nbsp;then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp;tempdoc:=xweb.document as IHtmlDocument2;<br>&nbsp; &nbsp; &nbsp; &nbsp;CurWebpage[NumOfCurWebPage].WPurl:=xweb.LocationURL;<br>&nbsp; &nbsp; &nbsp; &nbsp;CurWebpage[NumOfCurWebPage].WPtitle:=tempdoc.body.title;<br>&nbsp; &nbsp; &nbsp; &nbsp;CurWebPage[NumOfCurWebPage].WPIdoc:=tempdoc;<br>&nbsp; &nbsp; &nbsp; &nbsp;Inc(NumOfCurWebPage);<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; on exception do<br>&nbsp; &nbsp; &nbsp; &nbsp; //showmessage('IE没打开!');<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>tempnumofwebpage:=NumOfCurWebPage;<br>//填装列表<br>while (tempnumofwebpage&gt;=0) do<br>&nbsp;begin<br>&nbsp; &nbsp;LBCurwebpage.Items.Add(CurWebpage[tempnumofwebpage-1].WPurl);<br>&nbsp; &nbsp;Dec(tempnumofwebpage);<br>&nbsp;end;<br>if NumOfCurWebPage=0 then LBCurwebpage.Clear;<br>end;
 
to dana<br>你贴出来的不是你的稿件,是我写的书里面的一章中的内容。我曾经将书的稿件给过几个朋友,不知道你是不是其中的一个。<br><br>至于遍历frames,参考:<br>http://blog.joycode.com/technofantasy/posts/13483.aspx
 
后退
顶部