⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 102503_05.htm

📁 对于学习很有帮助
💻 HTM
字号:
<html>
<head>
<link REL="stylesheet" HREF="/style.css" TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算机世界日报:
用Delphi创建Internet快捷方式
</title>
<!--***********-->
</head>

<body bgcolor="#FFFFFF" >














<p><br>
<font color="#b904e8"><b><em><a href="class.htm">返回</a></em></b></font>
<center>
<font color="#0000c0"><h2>
用Delphi创建Internet快捷方式
</h2></font>
<h3>
西安交通大学
<br>刘明华
</h3>
</center>
<p><font color="#ffffff">----</font>
在Windows中,为了方便文件或者文件夹的访问,我们常常为某些文件或者文件夹建立快捷方式(shortcut)。同样,在Internet Explorer中,我们也可以为自己喜爱的网址建立Internet快捷方式(Internet Shortcut)。只要点击快捷方式,Internet Explorer就会启动,并联接到相应的网站。事实上,除了Internet Explorer可以创建Internet快捷方式之外,在我们的应用程序中也同样可以实现此功能。在本文中,我将要向读者介绍如何在Delphi程序中为网址建立Internet快捷方式。
<p><font color="#ffffff">----</font>
<b>Internet快捷方式的格式</b>
<p><font color="#ffffff">----</font>
为了分析Internet快捷方式的文件格式,我们可以先用Internet Explorer为某个网址建立一个快捷方式,然后在DOS窗口中用DIR命令找到Internet快捷方式所对应的文件,并且用edit查看文件的内容。不难发现,Internet快捷方式的文件格式与INI文件的格式是一样的,只不过它的扩展名必须是 .URL罢了。
Internet快捷方式的文件格式如下:
<pre>
[DEFAULT]
BASEURL=

[InternetShortcut]
URL=
WorkingDirectory=
ShowCommand=
IconIndex=
IconFile=
Modified=
HotKey=
</pre>
<p><font color="#ffffff">----</font>

其中BASEURL、URL和WorkingDirectory这3项的含义是不言而明的。ShowCommand规定Internet Explorer启动后窗口的初始状态:7表示最小化,3表示最大化;如果没有ShowCommand这一项的话则表示正常大小。IconFile和IconIndex用来为Internet快捷方式指定图标;如果你不想指定图标,Windows会使用缺省的Internet快捷方式图标。HotKey指定一个整数值;HotKey的值及其含义如下:
<pre>
833  - Ctrl + Shift + A
834  - Ctrl + Shift + B
835  - Ctrl + Shift + C
836  - Ctrl + Shift + D
837  - Ctrl + Shift + E
838  - Ctrl + Shift + F
1601 - Ctrl + Alt + A
1602 - Ctrl + Alt + B
1603 - Ctrl + Alt + C
1604 - Ctrl + Alt + D
1605 - Ctrl + Alt + E
1606 - Ctrl + Alt + F
...

一个简单的Internet快捷方式只需要在
[InternetShortcut]节中包含URL项就可以了,例:
[InternetShortcut]
URL=http://www.yahoo.com
</pre>
<p><font color="#ffffff">----</font>
<b>快捷方式的创建</b>
<p><font color="#ffffff">----</font>
接下来,我们来看一个非常简单的Delphi例子。此程序将在Windows的桌面上建一个一个名为“计算机世界”的快捷方式,它指向《计算机世界》的首页;快捷方式的图标使用Windows 98/95中System目录(或者Windows NT中的System32目录)下的shell32.dll动态联接库中的第41号图标。
<p><font color="#ffffff">----</font>
	由于Internet快捷方式的文件格式与INI文件的是相同的,我们可以使用Delphi的TiniFile类来读写.URL文件的内容。而要使快捷方式出现在桌面上,我们只要把.URL文件保存在Windows桌面所对应的那个目录之下即可。当前用户的桌面目录可以从注册表中获取,此信息保存在Windows注册表HKEY_CURRENT_USER 根键下的Software\Microsoft\Windows
<br>\CurrentVersion\Explorer\Shell Folders主键的Desktop项中。
<p><font color="#ffffff">----</font>
示例程序的单元文件的代码如下:
<pre>
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes,
  Graphics, Controls, Forms, Dialogs,7
  StdCtrls, Registry, IniFiles;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
   ini:TIniFile;
   Reg:TRegistry;
   DesktopPath, FileName, S:String;
   Buf:array[0..max_path]of char;
begin

//获取当前用户Desktop文件夹的路径
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_CURRENT_USER;
try
   Reg.OpenKey('Software\Microsoft\Windows
\CurrentVersion\Explorer\Shell Folders',False);
   if Reg.ValueExists('Desktop') then 
DesktopPath:=Reg.ReadString('Desktop');
finally
   Reg.Free;
end;
if (DesktopPath<  >'')and(DesktopPath
[Length(DesktopPath)]<  >'\')
   then DesktopPath:=DesktopPath+'\';

//将Buf清零
FillChar(Buf,SizeOf(Buf),0);
//获取Win98/95中的System
文件夹或者NT中的System32文件夹的路径
GetSystemDirectory(Buf,SizeOf(Buf));
S:=Buf;
if (S<  >'')and(S[Length(S)]<  >'\') then S:=S+'\';
S:=S+'shell32.dll';

//Internet快捷方式的文件名(扩展名必须是URL)
FileName:=DesktopPath+'计算机世界.url';
ini:=TIniFile.Create(FileName);
//指定URL
ini.WriteString('InternetShortcut','URL',
'http://www.computerworld.com.cn');
//指定图标文件
ini.WriteString('InternetShortcut','IconFile',S);
ini.WriteString('InternetShortcut','IconIndex','41');
ini.Free;
end;

end.

</pre>



 



<p align="right"><small><em>中国计算机世界出版服务公司版权所有</em></small> 
<br>
</p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -