2015.1.25 Delphi打开网址链接的几种方法

2015.1.25 Delphi打开网址链接的几种方法
  Delphi打开网址链接的几种方法
1、使用
shellapi打开系统中默认的浏览器
              首先需在头部引用 shellapi单元即在uses中添加shellapi,这里我们需要知道有3个api函数可以运行可执行文件WinExec、ShellExecut和CreateProcess。
              下面为 ShellExecute的标准用法
             ShellExecute(Application.Handle, nil, 'http://www.baidu.com', nil, nil, SW_SHOWNORMAL);
             从左往右开始,
Application.Handle代表应用程序主窗口作为windows消息窗口的父窗口;第一个 nil为执行默认“open”操作; ' http://www.baidu.com '是要打开的网址,一般为打开应用程序的名称;第二个 nil代表若上一个是个可执行文件则指定命令行参数,不然为nil;第三个nil用于指定默认目录; SW_SHOWNORMAL代表程序初始化窗口显示的方式,该方式为用原来大小和方式显示,并进行活动状态。
           其实 
ShellExecute(Application.Handle, nil, ' http://www.baidu.com ', nil, nil, SW_SHOWNORMAL);是 ShellExecut的特殊用法,当 ' http://www.baidu.com '这里不是应用程序名称时,是http:协议参数格式时,该函数将打开默认浏览器的兵连接到指定url地址,若用户安装多个浏览器,将另外根据注册表中设置打开哪个
2: 用IE浏览器打开的3种方法:
方法1:
ShellExecute(Application.Handle, 'open','Iexplore.exe',' http://www.baidu.com ',nil,SW_SHOWNORMAL);
方法2:
{uses SHDocVw;}
插入个按键,其按下函数如下:
var

IE : OleVariant;
begin
IE := CoInternetExplorer.Create;
IE.Visible := True;
IE.Navigate2(' http://www.baidu.com ');
end;
方法3:
{uses  comobj;}
var
Ie:Variant
begin
Ie:=CreateOleObject('InternetExplorer.Application');
Ie.visible:=True;
Ie.left:=300; 
Ie.top:=200; 
Ie.height:=400;
Ie.width:=600;
Ie.menubar:=0; //隐藏菜单栏
Ie.toolbar:=0; //隐藏工具栏
Ie.addressbar:=0; //隐藏地址栏
//
Ie.statubar:=0; //不可调整大小
Ie.resizable:=0;
Ie.navigate(URL);
end;

begin
OpenInIe(' http://www.baidu.com ');
end;
3、用delphi中自带的
WebBrowser控件
WebBrowser1.Navigate(' http://www.baidu.com');  // WebBrowser1.Navigate( '...' );   //打开指定页面
 

4、用Delphi第三方控件EmbeddedWB
 
比Delphi自带的Webbrowser要强悍,其实就是在Webbrowser上的二次开发,附安装方法:
 
EmbeddedWB安装方法:
 
1.下载压缩包,飘易下载的是EmbeddedWB v14.67.0版本,下载地址:http://www.delphifans.com/SoftView/SoftView_2705.html。 
 
 2.解压整个压缩包到 libEmbeddedWB 下; 
 
 3.复制 libEmbeddedWB 下的Packages目录中的EmbeddedWebBrowser_D2007.dpk(因为飘易使用的是DELPHI2007)到Source目录里; 


4.用Delphi7开发环境打开 EmbeddedWebBrowser_D2007.dpk 文件,按Optios按钮,作如下调整: 
 
Directories/Conditionals标签Unit Output Dir=“D:Program FilesCodeGearRAD Studio5.0libEmbeddedWBSource”(具体路径自行决定); 
 
5.按Compile, 再按Install; 
 
6.不要保存变化了的dpk文件及压缩包; 
 
7.在具体的编译工程时,需检查该源目录(D:Program FilesCodeGearRAD Studio5.0libEmbeddedWBSource)在 Delphi IDE 的 “Search Path” 路径里(Project -> Options -> irectories/Conditionals -> Search Path); 如果没有,添加这个源目录路径。否则,在使用该控件的时候,出现“File not found: ‘SHDocVw_EWB.dcu’” 错误。 
 
8.可以正常使用了。

Delphi第三方控件EmbeddedWB,这是一个不错的浏览器控件,比Delphi自带的Webbrowser要强悍 EmbeddedWB安装方法: 1.下载压缩包,飘易下载的是EmbeddedWB v14.67.0版本,下载地址:http://www.delphifans.com/SoftView/SoftView_2705.html。 2.解压整个压缩包到 lib\EmbeddedWB 下; 3.复制 lib\EmbeddedWB 下的Packages目录中的EmbeddedWebBrowser_D2007.dpk(因为飘易使用的是DELPHI2007)到Source目录里; 4.用Delphi7开发环境打开 EmbeddedWebBrowser_D2007.dpk 文件,按Optios按钮,作如下调整: Directories/Conditionals标签Unit Output Dir=“D:\Program Files\CodeGear\RAD Studio\5.0\lib\EmbeddedWB\Source”(具体路径自行决定); 5.按Compile 再按Install; 6.不要保存变化了的dpk文件及压缩包; 7.在具体的编译工程时,需检查该源目录(D:\Program Files\CodeGear\RAD Studio\5.0\lib\EmbeddedWB\Source)在 Delphi IDE 的 "Search Path" 路径里(Project -> Options -> irectories/Conditionals -> Search Path); 如果没有,添加这个源目录路径。否则,在使用该控件的时候,出现“File not found: 'SHDocVw_EWB.dcu'” 错误。 8.可以正常使用了。 这里还有一篇别人的“Embedded Web Browser Delphi组件的安装”,不过是把TEmbeddedWB控件安装到 Delphi7 里的。 下面是D2005 installing steps:1.After downloading Unzip the package. 2. Put the folder that contain the package in the path "..:\Borland\BDS\3.0\lib" 3. Open Delphi IDE and press in the menu bar On: File --> "Open" In the open dialog navigate to the path where you store your package to the source folder("..:\Borland\BDS\3.0\lib\EmbeddedWB_D2005\Source"). 5.Choose file name "EmbeddedWebBrowser_D2005.dpk" and press open. 6.In the project manager (in the right corner) point with your mouse on the top file ("EmbeddedWebBrowser_D2005.bdsproj"). Then Right click and choose "Build" 7. And last In the same file & menu Press install. 8. Do not save the package changes. 9. You should make sure that the source folder is in the Delphi IDE "Search Path". If not You must add it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值