个性化Folder Icon(Delphi)

2008-04-09 04:27:58来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


抛弃Windows的默认图标吧,让自己的程序所在的目录拥有个性化的Folder Icon!
其实作起来简单得很,实际上只需要一个Desktop.ini文件即可,下面我会从两个方面说明。

1. 手动方式:

首先要在需要改变的文件夹中创建一个Desktop.ini文件,例子如下
[.ShellClassInfo]
ConfirmFileOp=0
InfoTip=我自己的文件夹
IconIndex=0
IconFile=MyFolder.ico
解释:
参数ConfirmFileOp设为0--防止用户在移动或删除此文件夹时弹出的“你正在删除系统目录”的警告。
参数IconFile指定为将要改变的图标文件的位置,可以是Icon、Bmp、exe或者dll文件,上例中的图标文件也放置到同一目录中。
参数IconIndex就可以指定文件的索引,如果此图标文件是Icon文件的话,IconIndex就设为0。
参数InfoTip用来设定此Folder在Windows中的Tooltip。

下一步打开CMD(命令提示符),输入
attrib s i:\MyFolder
i:\MyFolder指的就是我要改图标的目录的路径。此项操作是让你的文件夹成为系统文件夹。

好了,经过手动处理后现在的目录已经改变了风格。

2. 编程方式:

这种方式是用我喜欢的Delphi来实现的,实现起来也同样Easy。
一个用来操作Ini文件的建立,另一个的功能等同于手动方式中的attrib s。

unit Unit1;

interface

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

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
MyIniFile: TIniFile;
begin
//以下几步用于创建Desktop.ini文件
//不存在ini文件时,会自己创建ini
MyIniFile := TIniFile.Create(ExtractFilePath(Application.ExeName ) ''''Desktop.ini'''');
MyIniFile.WriteString(''''.ShellClassInfo'''', ''''ConfirmFileOp'''', ''''0'''');
MyIniFile.WriteString(''''.ShellClassInfo'''', ''''InfoTip'''', ''''我的文件夹因此而改变'''');
MyIniFile.WriteString(''''.ShellClassInfo'''', ''''IconIndex'''', ''''0'''');
MyIniFile.WriteString(''''.ShellClassInfo'''', ''''IconFile'''', ExtractFileName(Application.ExeName));
MyIniFile.Free;
//让文件夹成为系统文件夹
SetFileAttributes(PChar(ExtractFilePath(Application.ExeName)), GetFileAttributes(PChar(ExtractFilePath(Application.ExeName))) OR FILE_ATTRIBUTE_SYSTEM);
end;

end.


如果你使用的是主窗口的图标的话,Delphi编译后的程序的图标的索引是0。

本示例在Win2000和Delphi6中调试通过

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:QuickReport基本知识

下一篇:2002-08-06 Borland发布Delphi 7 Studio,支持Microsoft .NET