如题
解决方案 »
- delphi如何做游戏内存修改器
- 开发数据库方面的程序用Delphi还是VB好?为什么?
- 求算法哦!救命用!关于年月日转化为天数,要求判断闰年!
- 请各位大虾推荐一下新手入门的好书
- 关于连接远程数据库问题!!???希望大家献出自己的是怎么连接远程数据库的?!!!
- 有没有这样一本书,对Delphi的 vcl源代码作了一些分析和解释,哪有的下!
- 请问程序执行(显示From)时,先执行哪个函数,onshow还是oncreate???
- delphi中如何知道句柄中的值
- 请问如何能编译只有一个UNIT的程序?没有FORM.
- 救命?memo容量为32768有无比此容量更大的.
- 请问TTreeView怎么用?
- 请教,今天发现的一个奇怪的问题
unit GraphicsExpand;interface
uses
Forms , Registry , Graphics , ShellAPI , Controls , SysUtils , Windows , Dialogs;Function GetExeByOpenFile(FileName:String):String; //得到打开这个文件的EXE文件
Function GetExeIcoByOpenFile(FileName:String):integer; //得到这个文件对应的EXE里的图标号
Function AddFileIcoToImgLst(FileName : String ; ImageList : TImageList) : integer;
//把这个文件的图标增加到ImageList中去。
implementationFunction AddFileIcoToImgLst(FileName : String ; ImageList : TImageList) : integer;
var
Count , IcoIndex : integer;
Ico : Ticon;
ExFile : String;
begin
Result := -1;
ExFile := GetExeByOpenFile(FileName);
IcoIndex := GetExeIcoByOpenFile(FileName);
Count := ExtractIcon( Application.Handle, PChar(ExFile),$FFFFFFFF);
Ico := Ticon.Create;
if( IcoIndex < Count ) then begin
Ico.Handle := ExtractIcon( Application.Handle, PChar(ExFile), IcoIndex );
ImageList.AddIcon(Ico);
Result := ImageList.Count -1;
end;
Ico.Free;
end;Function GetStrByOpenFile(FileName:String):String;
var
Reg : Tregistry;
FEName , RegNe: String;
begin
Result := '%SystemRoot%\System32\shell32.dll,0';
FeName := ansiuppercase(Trim(extractfileext(FileName)));
if FEName='.EXE' then Result := Trim(FileName)
else if copy(Trim(FileName),Length(Trim(FileName)),1)='\' then Result := '%SystemRoot%\System32\shell32.dll,3'
else if FEName='' then Result := '%SystemRoot%\System32\shell32.dll,0'
else begin
if copy(FEName,1,1)<>'.' then FEName := '.'+FEName;
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CLASSES_ROOT;
if Reg.OpenKey(FEName,True) then begin
RegNE := Reg.ReadString('')+'\\DefaultIcon';
Reg.CloseKey;
if RegNe <> '\\DefaultIcon' then begin
Reg.OpenKey(RegNE,True);
Result := Reg.ReadString('');
Reg.CloseKey;
end;
end;
Reg.Free;
end;
end;Function GetExeIcoByOpenFile(FileName:String):integer;
var
Tmp , cStr : String;
begin
Result := 0;
Tmp := '';
cStr := GetStrByOpenFile(FileName);
if cStr<>'' then
while True do begin
if pos(copy(cStr,Length(cStr),1),'-0123456789')>0 then
begin
Tmp := copy(cStr,Length(cStr),1) + Tmp;
cStr := copy(cStr,1,Length(cStr)-1)
end
else begin
if Tmp<>'' then Result := strtoint(Tmp);
Break;
end;
end;
end;Function GetExeByOpenFile(FileName:String):String;
var
cStr : String;
begin
cStr := GetStrByOpenFile(FileName);
Result := cStr;
if (cStr<>'') and (Pos(',',cStr)>0) then
while True do begin
if copy(cStr,Length(cStr),1)<>',' then
cStr := copy(cStr,1,Length(cStr)-1)
else begin
Result := copy(cStr,1,Length(cStr)-1);
Break;
end;
end;
end;end.//使用方法:
AddFileIcoToImgLst('DD.DOC',ImageList);
就把Word的图标加到ImageList中了,就可以直接从ImageList中得到图标了三。
:)
var
Reg : Tregistry;
FEName , RegNe: String;
begin
Result := '%SystemRoot%\System32\shell32.dll,0';
看到这一句没有,没有关联的当然是取这个图标了。
这段代码还有个小问题,如果在注册表中关联的程序加上""就取不到图标了,比如c:\aa.exe在注册表中写成"c:\aa.exe",这样被关联的文件还是可以用aa.exe打开,但图标却是那种没有被关联的文件的图标,而且用你的代码得不到任何图标,当然解决也很简单,就是判断一下
(Count := ExtractIcon( Application.Handle, PChar(ExFile),$FFFFFFFF);)中的count是否为0,为零就把ExFile赋值为'%SystemRoot%\System32\shell32.dll,0'就可以了。:)
你也太黑了吧,问题都没帮我解决居然要我结贴?:)
好吧,算了,问到这份上我也该收手了,给分。