如何在IE里获取当前URL和网站名称! ( 积分: 200 )

  • 主题发起人 主题发起人 cnzjjzx
  • 开始时间 开始时间
C

cnzjjzx

Unregistered / Unconfirmed
GUEST, unregistred user!
想写个象IE“收藏”一样的插件,如何在IE中获取当前打开页面的URL和网站的名称(<title>..</title>中的内容)!
分数不多200分送人,诚心请教
 
想写个象IE“收藏”一样的插件,如何在IE中获取当前打开页面的URL和网站的名称(<title>..</title>中的内容)!
分数不多200分送人,诚心请教
 
下面是我以前写的获取当前打开页面的URL
procedure TFrm_main.Timer1Timer(Sender: TObject);
var
fwnd,hwnd:thandle;
buf2,buf:array[0..250] of char;
begin
fwnd:=GetForegroundWindow;
hwnd:=fwnd;
tishi:=1;
Getclassname(fwnd,buf,sizeof(buf));
Getwindowtext(fwnd,buf2,sizeof(buf2));
if (pos('任务管理器',strpas(buf2))>0) then
Postmessage(hwnd,WM_Close,0,0);
if (strpas(buf)='CabinetWClass') or(strpas(buf)='IEFrame') or (pos('Netscape',strpas(buf2))>0) or (pos('MyIE',strpas(buf2))>0) or (pos('Opera',strpas(buf2))>0) or (pos('Tencent',strpas(buf2))>0) or (pos('浏览',strpas(buf2))>0) then
begin
if (stop>0)and((strpas(buf)='IEFrame') or (pos('Netscape',strpas(buf2))>0) or (pos('MyIE',strpas(buf2))>0) or (pos('Opera',strpas(buf2))>0) or (pos('Tencent',strpas(buf2))>0)) then
begin
Postmessage(hwnd,WM_Close,0,0);
if oldwnd<>hwnd then
begin
application.MessageBox('现已关闭上网功能!','提示',mb_ok);
oldwnd:=hwnd;
end;
end
else if not (EnumChildWindows(fwnd,@enumchildproc,0)) then
begin
Postmessage(hwnd,WM_Close,0,0);
if (oldwnd<>hwnd) and (tishi=1) then
begin
//application.MessageBox('发现输入非法网站,现已关闭!','提示',mb_ok);
Application.CreateForm(TF_CloseIEPrompt, F_CloseIEPrompt);
F_CloseIEPrompt.Show;
oldwnd:=hwnd;
end;
end;
end;
end;
function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
var buf:array[0..250] of char;
rsize:integer;
str:string;
begin
result:=true;
Getclassname(hwnd,buf,sizeof(buf));
if strpas(buf)='Edit' then
begin
rsize:=sendmessage(hwnd,WM_GETTEXT,sizeof(buf),integer(@buf));
if rsize>0 then
begin
str:=buf; //这就是当前打开页面的URL
if (filter(buf)) then
begin
result:=false;
end;
end;
end;
end;
 
车超你好,你发的代码看的不是很懂,能不能告诉我你的QQ号,好请教?
 
借地问个问题:
是否可以取的获取当前打开页面的URL中显示页面的标签值呢?
 
从新帮你整理过了
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
var
Form1: TForm1;
strUrl:string;

implementation

{$R *.dfm}

function EnumChildProc(hwnd:HWND;IParam:LPARAM):bool;stdcall;
var buf:array[0..250] of char;
rsize:integer;
str:string;
begin
result:=true;
Getclassname(hwnd,buf,sizeof(buf));
if strpas(buf)='Edit' then
begin
rsize:=sendmessage(hwnd,WM_GETTEXT,sizeof(buf),integer(@buf));
if rsize>0 then
begin
strUrl:=buf; //这就是当前打开页面的URL
end;
end;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
var
fwnd,hwnd:thandle;
buf2,buf:array[0..250] of char;
begin
fwnd:=GetForegroundWindow;
hwnd:=fwnd;
Getclassname(fwnd,buf,sizeof(buf));
EnumChildWindows(fwnd,@enumchildproc,0);
Edit1.text := strUrl;

end;

end.
运行后把ie的窗体激活在Edit1.text就显示url了,不过这种方法不是最好的方法,我觉得通过截取socket的方法才比较好
本人qq:365282022
 
取网站的名称(<title>..</title>中的内容)我没做过,不过估计也不是很难
请参考http://community.csdn.net/Expert/topic/4163/4163798.xml?temp=.2369806
 
学习,试一下
 
获取IE当前打开的页面网址

uses SHDocVw, MSHTML;

procedure TForm1.Button1Click(Sender: TObject);
var
ShellWindow: IShellWindows;
nCount,I: Integer;
IE1: IWebBrowser2;
IDoc1: IHTMLDocument2;
spDisp: IDispatch;
begin
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;
for I := 0 to nCount - 1 do
begin
spDisp := ShellWindow.Item(I);
if spDisp = nil then Continue;
spDisp.QueryInterface(IWebBrowser2, IE1);
if IE1 <> nil then
begin
IE1.Document.QueryInterface(IHTMLDocument2,IDoc1);
if IDoc1<>nil then
Edit1.Text:=IDoc1.url; //获取IE当前网址
Break;
end;
end;
end;
 
学习学习,
长知识
 
多谢了...:)
 

Similar threads

回复
0
查看
989
不得闲
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
887
DelphiTeacher的专栏
D
后退
顶部