function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var sw: TShellWindows; i: integer; web: IWebBrowser2; x: Olevariant; t:string; begin try sw := TShellWindows.Create(nil); try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; //这里是URL格式,这里只管文件协议. if (pos('http', lowercase(web.LocationURL))> 0) then begin web := nil; continue ; end; if Pos(uppercase(Fatstr(Addr)), uppercase(web.LocationURL)) > 0 then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; sw.Free; end; except Result:=False; end; end; ================== WebNavigate('Http:\\www.xxx.com',True);
不好意思啊,直接复制我的程序了,没注意有个fatstr,,改了一下 function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var sw: TShellWindows; i: integer; web: IWebBrowser2; x: Olevariant; t:string; begin try sw := TShellWindows.Create(nil); try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; if (pos('http', lowercase(web.LocationURL))=1) then begin web := nil; continue ; end; if (uppercase(Addr)= uppercase(web.LocationURL) then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; sw.Free; end; except Result:=False; end; end;
用Findwindow找到Ie的句柄,然后用SendMessage()发键盘F5消息给IE就行了
unit ReFreashURL; interfaceuses SHDocVw, shellapi, Windows, SysUtils; function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;implementationfunction WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var sw: TShellWindows; i: integer; web: IWebBrowser2; x: Olevariant; t:string; begin try sw := TShellWindows.Create(nil); try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; if (pos('http', lowercase(web.LocationURL))=1) then begin web := nil; continue ; end; if (uppercase(Addr)= uppercase(web.LocationURL) then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; sw.Free; end; except Result:=False; end; end; =============================== WebNavigate(Addr,True) //找到就返回true,找不到返回false 第二个参数 True 时,如果找到则刷新,False时不刷新,
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, SHDocVw, shellapi;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; implementation{$R *.dfm} function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var sw: TShellWindows; i: integer; web: IWebBrowser2; x: Olevariant; t:string; begin try sw := TShellWindows.Create(nil); try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; if (pos('http', lowercase(web.LocationURL))=1) then begin web := nil; continue ; end; if (uppercase(Addr)= uppercase(web.LocationURL) then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; sw.Free; end; except Result:=False; end; end; procedure TForm1.Button1Click(Sender: TObject); begin WebNavigate('Http:\\www.baidu.com',True); end;end. 编译过不了???
if (uppercase(Addr)= uppercase(web.LocationURL) then 多了一个括号
楼主用这个吧,我刚才调了一下确实有问题,都怪我太懒了,负责我原来查找本地文件夹的代码,,现在改这个可以找http的,那个路径的判断有点死板,楼主可以自己改一下。unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,SHDocVw, shellapi;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; implementation {$R *.dfm}function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var //sw: TShellWindows; sw: IShellwindows; i: integer; web: IWebBrowser2; x: Olevariant; t:string; begin try //sw := TShellWindows.Create(nil); sw := CoShellWindows.Create; try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; if (pos('http', lowercase(web.LocationURL))<>1) then begin web := nil; continue ; end; if uppercase(Addr)= uppercase(web.LocationURL) then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; // sw.Free; end; except Result:=False; end; end; procedure TForm1.Button1Click(Sender: TObject); begin WebNavigate('Http://www.baidu.com',True); end; end.
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, SHDocVw, shellapi;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; implementation{$R *.dfm} function WebNavigate(Addr: string; openEx: Boolean=True):Boolean; var sw: TShellWindows; i: integer; web: IWebBrowser2; x: Olevariant; //t:string; begin try sw := TShellWindows.Create(nil); try for i := 0 to sw.Count - 1 do begin web := SW.Item(i) as IWebBrowser2; if (pos('http', lowercase(web.LocationURL))=1) then begin web := nil; continue ; end; if uppercase(Addr)= uppercase(web.LocationURL) then begin try web := SW.Item(i) as IWebBrowser2; if openEx Then web.Navigate(Addr, x, x, x, x); Result:=True; Break; except web := nil; end; end else web := nil; end; finally if web = nil Then Result:=False; sw.Free; end; except Result:=False; end; end; procedure TForm1.Button1Click(Sender: TObject); begin WebNavigate('http://www.baidu.com/s?wd=222',True); end;end. 按下按钮后,指定的网址并没有刷新?
可以呀,刚才是网址打错了 所以不行 另外,这个警告怎么去掉 [Warning] Unit1.pas(69): Return value of function 'WebNavigate' might be undefined 在有,这个代码,有无需要释放掉的变量,我不想内存存在泄漏 web.Navigate(Addr, x, x, x, x);这句是什么意思呀?另外,再出一百分,求一个我发帖时要的效果,即,打开网页,鼠标停在ie的刷新按钮上,要求每隔三分钟鼠标模拟按下一次. 这个按钮,不一定是ie的,也许是其它程序的.此帖中的50分,给CaiBirdy明天追加100分,CaiBirdy如果能实现最好,全数尽收.
bho
或者
hook
var sw: TShellWindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
t:string;
begin
try
sw := TShellWindows.Create(nil);
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
//这里是URL格式,这里只管文件协议.
if (pos('http', lowercase(web.LocationURL))> 0) then
begin
web := nil;
continue ;
end;
if Pos(uppercase(Fatstr(Addr)), uppercase(web.LocationURL)) > 0 then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
sw.Free;
end;
except
Result:=False;
end;
end;
==================
WebNavigate('Http:\\www.xxx.com',True);
不好意思啊,直接复制我的程序了,没注意有个fatstr,,改了一下
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
var sw: TShellWindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
t:string;
begin
try
sw := TShellWindows.Create(nil);
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
if (pos('http', lowercase(web.LocationURL))=1) then
begin
web := nil;
continue ;
end;
if (uppercase(Addr)= uppercase(web.LocationURL) then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
sw.Free;
end;
except
Result:=False;
end;
end;
interfaceuses SHDocVw, shellapi, Windows, SysUtils; function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;implementationfunction WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
var sw: TShellWindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
t:string;
begin
try
sw := TShellWindows.Create(nil);
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
if (pos('http', lowercase(web.LocationURL))=1) then
begin
web := nil;
continue ;
end;
if (uppercase(Addr)= uppercase(web.LocationURL) then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
sw.Free;
end;
except
Result:=False;
end;
end;
===============================
WebNavigate(Addr,True)
//找到就返回true,找不到返回false
第二个参数 True 时,如果找到则刷新,False时不刷新,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SHDocVw, shellapi;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
implementation{$R *.dfm}
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
var sw: TShellWindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
t:string;
begin
try
sw := TShellWindows.Create(nil);
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
if (pos('http', lowercase(web.LocationURL))=1) then
begin
web := nil;
continue ;
end;
if (uppercase(Addr)= uppercase(web.LocationURL) then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
sw.Free;
end;
except
Result:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebNavigate('Http:\\www.baidu.com',True);
end;end.
编译过不了???
多了一个括号
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,SHDocVw, shellapi;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
implementation
{$R *.dfm}function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
var
//sw: TShellWindows;
sw: IShellwindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
t:string;
begin
try
//sw := TShellWindows.Create(nil);
sw := CoShellWindows.Create;
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
if (pos('http', lowercase(web.LocationURL))<>1) then
begin
web := nil;
continue ;
end;
if uppercase(Addr)= uppercase(web.LocationURL) then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
// sw.Free;
end;
except
Result:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebNavigate('Http://www.baidu.com',True);
end;
end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SHDocVw, shellapi;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
implementation{$R *.dfm}
function WebNavigate(Addr: string; openEx: Boolean=True):Boolean;
var sw: TShellWindows;
i: integer;
web: IWebBrowser2;
x: Olevariant;
//t:string;
begin
try
sw := TShellWindows.Create(nil);
try
for i := 0 to sw.Count - 1 do
begin
web := SW.Item(i) as IWebBrowser2;
if (pos('http', lowercase(web.LocationURL))=1) then
begin
web := nil;
continue ;
end;
if uppercase(Addr)= uppercase(web.LocationURL) then
begin
try
web := SW.Item(i) as IWebBrowser2;
if openEx Then
web.Navigate(Addr, x, x, x, x);
Result:=True;
Break;
except
web := nil;
end;
end
else
web := nil;
end;
finally
if web = nil Then Result:=False;
sw.Free;
end;
except
Result:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebNavigate('http://www.baidu.com/s?wd=222',True);
end;end.
按下按钮后,指定的网址并没有刷新?
所以不行
另外,这个警告怎么去掉
[Warning] Unit1.pas(69): Return value of function 'WebNavigate' might be undefined
在有,这个代码,有无需要释放掉的变量,我不想内存存在泄漏
web.Navigate(Addr, x, x, x, x);这句是什么意思呀?另外,再出一百分,求一个我发帖时要的效果,即,打开网页,鼠标停在ie的刷新按钮上,要求每隔三分钟鼠标模拟按下一次.
这个按钮,不一定是ie的,也许是其它程序的.此帖中的50分,给CaiBirdy明天追加100分,CaiBirdy如果能实现最好,全数尽收.