大概是这样,api函数
ExtractAssiocaticon
ExtractAssiocaticon
解决方案 »
- 再发一帖,关于API拦截,侠进。
- 如何做出漂亮的按钮
- 我用DLL作共享数据联接模板,怎么调用DLL,其form怎么便用数据联接?
- 谁知道adoconnection的open时,如果服务器关闭,会触发哪个异常?
- 高手帮忙,多线程下载数据却无法更新.
- 对您来说可能很简单,取DateTime部分内容的问题!在线等待,即答即得分!
- 有谁能救我的命!懂得Z39.50协议的请进来,高分有送!
- 求tcp包穿透防火墙例子
- 关于数据库的一个怪问题。
- 如何取得isapi当前*.dll所在的路径?
- 我用query更新数据时,提示table is read only!,请告述我怎么解决?
- 怎样完成向导式,“上一步,下一步“式的窗口!
不行,他只是提取文件内的图标
~~~~~
var theIcon:TIcon;
h:HIcon;
IconIndex:word;
begin
IconIndex:=0;
theIcon := TIcon.Create;
try
h:= ExtractAssociatedIcon(HInstance, 'C:\autoexec.bat', IconIndex);
if h<>0 then begin
theicon.handle:=h;
DrawIcon(image1.Canvas.Handle,0,0,h);
end;
finally
theicon.free;
end;
end;
//win2000,xp,98下用这个
procedure TForm1.Button2Click(Sender: TObject);
var
h:hicon;
IconIndex:word;
ShFileInfo: TSHFILEINFO;
begin
iconindex:=0;
ShGetFileInfo(pchar('c:\autoexec.bat'), 0, SHFileInfo, SizeOf(SHFileInfo),
SHGFI_ICON);
h := SHFileInfo.hIcon;
Drawicon(image1.Canvas.handle ,0,0,h);
end;
uses
Registry, ShellApi;function StrLeft(const mStr: string; mDelimiter: string): string;
begin
Result := Copy(mStr, 1, Pos(mDelimiter, mStr) - 1);
end; { StrLeft }function StrRight(const mStr: string; mDelimiter: string): string;
begin
if Pos(mDelimiter, mStr) <= 0 then
Result := ''
else Result := Copy(mStr, Pos(mDelimiter, mStr) + Length(mDelimiter), MaxInt);
end; { StrRight }function FileIcon(mFileName: TFileName): THandle; { 返回文件的图标 }
var
vRegistry: TRegistry;
vExtension, vIconFileName: TFileName;
vIconIndex: Integer;
vExtDescription: string;
var
vBuffer: array[0 .. MAX_PATH] of Char;
vSysPath: string;
begin
Result := 0;
if not FileExists(mFileName) then Exit; GetSystemDirectory(vBuffer, MAX_PATH + 1);
vSysPath := string(vBuffer) + '\'; vRegistry := TRegistry.Create;
try
vExtension := UpperCase(ExtractFileExt(mFilename));
if (vExtension = '.EXE') or (vExtension = '.ICO') or (vExtension = '.IME') then begin
vIconFileName := mFilename;
vIconIndex := 0;
end else begin
vRegistry.RootKey := HKEY_CLASSES_ROOT;
if vRegistry.OpenKey(vExtension, False) then begin
vExtDescription := vRegistry.ReadString('');
vRegistry.OpenKey('\' + vExtDescription, False);
vRegistry.OpenKey('DefaultIcon', False);
vIconFileName := vRegistry.ReadString('');
vIconIndex := StrToIntDef(StrRight(vIconFileName, ','), 0);
vIconFileName := StrLeft(vIconFileName, ',');
end else begin
vIconFileName := vSysPath + 'Shell32.dll';
vIconIndex := 0;
end;
end;
Result := ExtractIcon(HInstance, PChar(vIconFileName), UINT(vIconIndex));
finally
vRegistry.Free;
end;
end; { FileIcon }procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then //添加一个打开文件对话框控件
Image1.Picture.Icon.Handle := FileIcon(OpenDialog1.FileName); //加一IMAGE
end;
procedure GetSystemImageList(imagelist:TImageList);
var
SysIL: THandle;
SFI: TSHFileInfo;
begin
// 取小图标,如果将SHGFI_SMALLICON替换成
//SHGFI_LARGEICON则表示取大图标
SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
if SysIL <> 0 then begin
//将imagelist的图像列表句柄指向系统图像句柄
imagelist.Handle := SysIL;
//防止组件释放时释放图像句柄,很重要
imagelist.ShareImages := TRUE;
end;
end;第二步 取得要处理文件的图标索引
//取一个文件的图标索引
function GetIconIndex(const AFile: string; Attrs: DWORD): integer;
//Attrs可以为表示文件或路径FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_DIRECTORY
var
SFI: TSHFileInfo;
begin
SHGetFileInfo(PChar(AFile), Attrs, SFI, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
Result := SFI.iIcon;
end;
//获取一个文件的imageindex;
function GetIconIndex(const APath: string; Attrs: DWORD): integer;
var
SFI: TSHFileInfo;
begin
if FileExists(APath) or DirectoryExists(APath) then
// If the file or directory exists, just let Windows figure out it's attrs.
SHGetFileInfo(PChar(APath), 0, SFI, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX)
else
// File doesn't exist, so Windows doesn't know what to do with it. We have
// to tell it by passing the attributes we want, and specifying the
// SHGFI_USEFILEATTRIBUTES flag so that the function knows to use them.
SHGetFileInfo(PChar(APath), Attrs, SFI, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
Result := SFI.iIcon;
end;实例调用:
//如在TreeView中得到c:\mydir的图标,因为是路径所以要加上路径的标志
aNode.ImageIndex := GetIconIndex('c:\mydir\',
FILE_ATTRIBUTE_NORMAL or FILE_ATTRIBUTE_DIRECTORY);
//如在TreeView中得到c:\index.html的图标
aNode.ImageIndex := GetIconIndex('c:\index.html',FILE_ATTRIBUTE_NORMAL);
"获取一个系统(如win2000)中已经注册的文件类型的图标!就好像 工具-文件夹选项-文件类型 那样可以看到系统的所有图标" 看到 "工具-文件夹选项-文件类型 那样可以看到系统的所有图标" [[所有]] 这几个字吗? 你的答案一年前我就搞定了,现在我要的是一个系统所有的文件类型的图标,不是单个或者指定文件的图标,难道我把整个硬盘的文件全都遍历一遍找出所有文件的图标吗?假如我的硬盘80G呢,你不要告诉我去遍历一遍啊! 你的那些代码老早我就在CSDN找到了,你以为我不会去试吗!所以麻烦你看清楚在骂,但最后我还是感激你的回复,CSDN也需要你这样的热心人.
请用NetAnts下载!
抱歉,我的语气可能过激了,而且,系统所有注册文件类型的图标,在“系统图标列表”中都有对应的图标!只是你没有好好利用起来。
[email protected]
另外Kingron(戒网中……)确实是无私奉献的大虾,小弟衷心佩服!!!最后怎样给你加分,我的这个帖子已经结帐了???