unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,DDEman,ShellAPi,ComObj, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; Button3: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; DDE:TDdeClientConv;implementation{$R *.dfm}{ TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin DDE:=TDdeClientConv.Create(Self); end;procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(Handle,'open','www.sina.com',nil,nil,SW_SHOWNORMAL); //先打开sina,第一个网站 end;procedure TForm1.Button2Click(Sender: TObject); begin if DDE.SetLink('Iexplore', 'WWW_OpenURL') then begin DDE.OpenLink; DDE.RequestData('www.163.com'); //在原窗口打开163,即指向你的第二个网站 DDE.CloseLink; end; end; end.DDE.SetLink:设置会话链接,返回bool值,链接成功找到ie窗口,false标识未找到ie窗口
var str:string; begin if DDE.SetLink('Iexplore', 'WWW_GetWindowInfo') then begin DDE.OpenLink; str := StrPas(DDE.RequestData('1'));//str将得到网址和标题 ShowMessage(str); DDE.CloseLink; end; end;
uses ComObj; procedure TForm1.Button1Click(Sender: TObject); var IE:Variant; begin IE:=CreateOleObject('InternetExplorer.Application'); IE.Visible:=True; IE.Navigate('www.126.com'); while ie.ReadyState<3 do //等待网页加载完毕。 application.ProcessMessages; showmessage('这个是标题:'+IE.LocationName); if pos('网易',IE.LocationName)>0 then//如果标题中存在 网易 两个字,则进行跳转到百度: IE.Navigate('www.baidu.com'); end; 如果你想控制已经开启的外部浏览器或第三方浏览器,你这点分不足以使我继续为你服务。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,DDEman,ShellAPi,ComObj, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
DDE:TDdeClientConv;implementation{$R *.dfm}{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
DDE:=TDdeClientConv.Create(Self);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle,'open','www.sina.com',nil,nil,SW_SHOWNORMAL); //先打开sina,第一个网站
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if DDE.SetLink('Iexplore', 'WWW_OpenURL') then
begin
DDE.OpenLink;
DDE.RequestData('www.163.com'); //在原窗口打开163,即指向你的第二个网站
DDE.CloseLink;
end;
end;
end.DDE.SetLink:设置会话链接,返回bool值,链接成功找到ie窗口,false标识未找到ie窗口
var
str:string;
begin
if DDE.SetLink('Iexplore', 'WWW_GetWindowInfo') then
begin
DDE.OpenLink;
str := StrPas(DDE.RequestData('1'));//str将得到网址和标题
ShowMessage(str);
DDE.CloseLink;
end;
end;
ShellExecute(Handle,'open','www.sina.com',nil,nil,SW_SHOWNORMAL);
把新浪网址换'www.sina.com'试试,我刚试过,没问题
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,DDEman,ShellAPi,ComObj, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
DDE:TDdeClientConv;implementation{$R *.dfm}{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
DDE:=TDdeClientConv.Create(Self);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle,'open','www.sina.com',nil,nil,SW_SHOWNORMAL); //先打开sina,第一个网站
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if DDE.SetLink('Iexplore', 'WWW_OpenURL') then
begin
DDE.OpenLink;
DDE.RequestData('www.163.com'); //在原窗口打开163,即指向你的第二个网站
DDE.CloseLink;
end;
end;
end.支持
如:打开新浪的时候程序不做动作,当打开163的时候,能通过分析网页标题上“网易”两个字自动把页面转到csdn这里来呀?
procedure TForm1.Button1Click(Sender: TObject);
var IE:Variant;
begin
IE:=CreateOleObject('InternetExplorer.Application');
IE.Visible:=True;
IE.Navigate('www.126.com');
while ie.ReadyState<3 do //等待网页加载完毕。
application.ProcessMessages;
showmessage('这个是标题:'+IE.LocationName);
if pos('网易',IE.LocationName)>0 then//如果标题中存在 网易 两个字,则进行跳转到百度:
IE.Navigate('www.baidu.com');
end;
如果你想控制已经开启的外部浏览器或第三方浏览器,你这点分不足以使我继续为你服务。
我现在就是想弄个程序监控电脑要是打开网站的话就检查网站的标题,让后让网页跳转到指定的网站上面。你能指导下吗,分不够可以令加。