m_adil
asked on
File icon
Hi,
How can i get the icon associated with a file and the type of the file like we see in explorer.
How can i get the icon associated with a file and the type of the file like we see in explorer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use this code instead,,, you have to use PChar instead of string,
procedure TForm1.Button1Click(Sender : TObject);
var
Index: Word;
H: Integer;
PFileName: PChar;
FileName: string;
begin
Index:= 0;
PFileName:= StrAlloc(100);
FileName:= 'c:\Autoexec.bat';
StrCopy(PFileName, PChar(FileName));
Image1.Picture.Icon.Handle :=
ExtractAssociatedIcon(HIns tance, PFileName, Index);
end;
procedure TForm1.Button1Click(Sender
var
Index: Word;
H: Integer;
PFileName: PChar;
FileName: string;
begin
Index:= 0;
PFileName:= StrAlloc(100);
FileName:= 'c:\Autoexec.bat';
StrCopy(PFileName, PChar(FileName));
Image1.Picture.Icon.Handle
ExtractAssociatedIcon(HIns
end;
ASKER
Thanks!
But how to get 16x16 size icon of the file, and how can I add this icon to List View control. As List view normally requires image list to show icons. And how to get the file type(the one we see in type column of the explorer). Any example. I'll increase the points
But how to get 16x16 size icon of the file, and how can I add this icon to List View control. As List view normally requires image list to show icons. And how to get the file type(the one we see in type column of the explorer). Any example. I'll increase the points
I'm not sure, but you can make the TImage component 16X16 and set it's stretch property to true
ASKER
Still waiting for a complete answer.
Is it too tough? No body else has passed a single comment.
Is it too tough? No body else has passed a single comment.
Actually, Motaz has answer your question.
save this unit as file and register it in component pallete
unit FindIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Registry, ShellApi;
type TeiResult = (eiDefaultIcon,eiExeIcon,e iNoExtensi onIcon, eiExtensionIcon);
TeiIcon = (eiGetFolderOpen, eiGetFolderClose, eiGetDefault,eiGetExe, eiGetNoExt);
TeiSetIcon = set of TeiIcon;
type
TRFindIcon = class(TComponent)
private
{ Private declarations }
FShellfile: string;
FFileName: string;
FLargeIcon, FLargeFolderCloseIcon,
FLargeFolderOpenIcon, FLargeNoExtIcon, FLargeDefaultIcon,
FLargeExeIcon, FSmallIcon, FSmallNoExtIcon,
FSmallFolderCloseIcon, FSmallFolderOpenIcon,
FSmallDefaultIcon, FSmallExeIcon: TICon;
FLastIconResult: TeiResult;
FDefaultChanged: boolean;
procedure SetLargeDefaultIcon (value: TIcon);
procedure SetLargeExeIcon (value: TIcon);
procedure SetLargeNoExtIcon (value: TIcon);
procedure SetSmallDefaultIcon (value: TIcon);
procedure SetSmallNoExtIcon (value: TIcon);
procedure SetSmallExeIcon (value: TIcon);
procedure SetFileName (value: string);
function GetIcons: TeiResult;
protected
{ Protected declarations }
public
{ Public declarations }
procedure SetLargeFolderOpenIcon (value: TIcon);
procedure SetLargeFolderCloseIcon (value:TIcon);
procedure SetSmallFolderOpenIcon (value: TIcon);
procedure SetSmallFolderCloseIcon (value:TIcon);
property SmallFolderOpenIcon: TIcon read FSmallFolderOpenIcon write SetSmallFolderOpenIcon;
property SmallFolderCloseIcon: TIcon read FSmallFolderCloseIcon write SetSmallFolderCloseIcon;
property LargeFolderOpenIcon: TIcon read FLargeFolderOpenIcon write SetLargeFolderOpenIcon;
property LargeFolderCloseIcon: TIcon read FLargeFolderCloseIcon write SetLargeFolderCloseIcon;
property LargeIcon: TIcon read FLargeIcon;
property SmallIcon: TIcon read FSmallIcon;
property LastIconResult: TeiResult read FLastIconResult;
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure GetDefaultIcon; overload;
procedure GetDefaultIcon (kind: TeiSetIcon); overload;
published
{ Published declarations }
property FileName: string read FFileName write SetFileName;
property LargeDefaultIcon: TIcon read FLargeDefaultIcon write SetLargeDefaultIcon;
property LargeExeIcon: TIcon read FLargeExeIcon write SetLargeExeIcon;
property LargeNoExtIcon: TIcon read FLargeNoExtIcon write SetLargeNoExtIcon;
property SmallDefaultIcon: TIcon read FSmallDefaultIcon write SetSmallDefaultIcon;
property SmallExeIcon: TIcon read FSmallExeIcon write SetSmallExeIcon;
property SmallNoExtIcon: TIcon read FSmallNoExtIcon write SetSmallNoExtIcon;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Ideias ', [TRFindIcon]);
end;
constructor TRFindIcon.Create (AOwner: TComponent);
begin
inherited Create (AOwner);
FLargeIcon := TIcon.Create;
FLargeNoExtIcon := TIcon.Create;
FLargeExeIcon := TIcon.Create;
FLargeFolderOpenIcon := TIcon.Create;
FLargeFolderCloseIcon := TIcon.Create;
FLargeDefaultIcon := TIcon.Create;
FSmallIcon := TIcon.Create;
FSmallNoExtIcon := TIcon.Create;
FSmallExeIcon := TIcon.Create;
FSmallFolderOpenIcon := TIcon.Create;
FSmallFolderCloseIcon := TIcon.Create;
FSmallDefaultIcon := TIcon.Create;
FLargeIcon.ReleaseHandle;
FLargeNoExtIcon.ReleaseHan dle;
FLargeExeIcon.ReleaseHandl e;
FLargeFolderOpenIcon.Relea seHandle;
FLargeFolderCloseIcon.Rele aseHandle;
FLargeDefaultIcon.ReleaseH andle;
FSmallIcon.ReleaseHandle;
FSmallNoExtIcon.ReleaseHan dle;
FSmallExeIcon.ReleaseHandl e;
FSmallFolderOpenIcon.Relea seHandle;
FSmallFolderCloseIcon.Rele aseHandle;
FSmallDefaultIcon.ReleaseH andle;
GetDefaultIcon;
end;
procedure TRFindIcon.GetDefaultIcon;
var Reg: TRegistry;
handlelarge, handlesmall: array [1..5] of HICON;
begin
Reg:=TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey ('\SOFTWARE\Microsoft', false);
if Reg.KeyExists ('Windows NT') then
begin
Reg.OpenKey ('Windows NT\CurrentVersion', false);
fshellfile := '\system32\shell32.dll';
end
else
begin
Reg.OpenKey ('Windows\CurrentVersion', false);
fshellfile := '\system\shell32.dll';
end;
fshellfile := Reg.ReadString('SystemRoot ') + fshellfile;
Reg.Free;
ExtractIconEx(Pchar(fshell file), 0, HandleLarge[1],HandleSmall [1],5);
FLargeDefaultIcon.Handle := HandleLarge[1];
FLargeNoExtIcon.Handle := CopyIcon (HandleLarge[1]);
FLargeExeIcon.Handle := HandleLarge[3];
FLargeFolderCloseIcon.Hand le := HandleLarge[4];
FLargeFolderOpenIcon.Handl e := HandleLarge[5];
DestroyIcon (HandleLarge[2]);
DestroyIcon (HandleSmall [2]);
FSmallDefaultIcon.Handle := HandleSmall[1];
FSmallNoExtIcon.Handle := CopyIcon (HandleSmall[1]);
FSmallExeIcon.Handle := HandleSmall[3];
FSmallFolderCloseIcon.Hand le := HandleSmall[4];
FSmallFolderOpenIcon.Handl e := HandleSmall[5];
FDefaultChanged := true;
end;
procedure TRFindIcon.GetDefaultIcon (kind: TeiSetIcon);
var HandleLarge, HandleSmall: array [1..5] of HICON;
f: integer;
begin
ExtractIconEx(Pchar(fshell file), 0, HandleLarge[1],HandleSmall [1],5);
if eiGetDefault in kind then
begin
FLargeDefaultIcon.ReleaseH andle;
FSmallDefaultIcon.ReleaseH andle;
FLargeDefaultIcon.Handle := CopyIcon(HandleLarge[1]);
FSmallDefaultIcon.Handle := CopyIcon(HandleSmall[1]);
end;
if eiGetNoExt in kind then
begin
FLargeNoExtIcon.ReleaseHan dle;
FSmallNoExtIcon.ReleaseHan dle;
FLargeNoExtIcon.Handle := CopyIcon (HandleLarge[1]);
FSmallNoExtIcon.Handle := CopyIcon (HandleSmall[1]);
end;
if eiGetExe in kind then
begin
FLargeExeIcon.ReleaseHandl e;
FSmallExeIcon.ReleaseHandl e;
FLargeExeIcon.Handle := CopyIcon(HandleLarge[3]);
FSmallExeIcon.Handle := CopyIcon (HandleSmall[3]);
end;
if eiGetFolderOpen in kind then
begin
FLargeFolderOpenIcon.Relea seHandle;
FSmallFolderOpenIcon.Relea seHandle;
FLargeFolderOpenIcon.Handl e := CopyIcon (HandleLarge[5]);
FSmallFolderOpenIcon.Handl e := CopyIcon (HandleSmall[5]);
end;
if eiGetFolderClose in kind then
begin
FLargeFolderCloseIcon.Rele aseHandle;
FSmallFolderCloseIcon.Rele aseHandle;
FLargeFolderCloseIcon.Hand le := HandleLarge[4];
FSmallFolderCloseIcon.Hand le := HandleSmall[4];
end;
for f := 1 to 5 do
begin
DestroyIcon (HandleLarge[f]);
DestroyIcon (HandleSmall [f]);
end;
FDefaultChanged := true;
end;
procedure TRFindIcon.SetFileName(val ue: string);
begin
if (LowerCase (ExtractFileExt(value)) = LowerCase (ExtractFileExt(FFileName) ))
and (not FDefaultChanged) then exit;
FFileName := value;
FLastIconResult := GetIcons;
end;
procedure TRFindIcon.SetLargeNoExtIc on (value: TIcon);
begin
FLargeNoExtIcon.Assign(val ue);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeDefault Icon (value: TIcon);
begin
FLargeDefaultIcon.Assign(v alue);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeExeIcon (value: TIcon);
begin
FLargeExeIcon.Assign(value );
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeFolderO penIcon (value: TIcon);
begin
FLargeFolderOpenIcon.Assig n(value);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeFolderC loseIcon (value: TIcon);
begin
FLargeFolderCloseIcon.Assi gn(value);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallNoExtIc on (value: TIcon);
begin
FSmallNoExtIcon.Assign(val ue);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallDefault Icon (value: TIcon);
begin
FSmallDefaultIcon.Assign(v alue);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallExeIcon (value: TIcon);
begin
FSmallExeIcon.Assign(value );
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallFolderO penIcon (value: TIcon);
begin
FSmallFolderOpenIcon.Assig n(value);
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallFolderC loseIcon (value: TIcon);
begin
FSmallFolderCloseIcon.Assi gn(value);
FDefaultChanged := true;
end;
destructor TRFindIcon.Destroy;
begin
FLargeIcon.Free;
FLargeExeIcon.Free;
FLargeFolderOpenIcon.Free;
FLargeFolderCloseIcon.Free ;
FLargeDefaultIcon.Free;
FSmallIcon.Free;
FSmallExeIcon.Free;
FSmallFolderOpenIcon.Free;
FSmallFolderCloseIcon.Free ;
FSmallDefaultIcon.Free;
inherited destroy;
end;
function TRFindIcon.GetIcons: TeiResult;
var handlelarge,
handlesmall: HICON;
temp, fileExtension, IconFileName: string;
iconindex, commapos: integer;
Reg: TRegistry;
begin
FDefaultChanged := false;
Reg := TRegistry.Create;
FileExtension := ExtractFileExt(FFileName);
if FileExtension = '' then
begin
FLargeIcon.Assign (FLargeNoExtIcon);
FSmallIcon.Assign (FSmallNoExtIcon);
result := eiNoExtensionIcon;
exit;
end;
if Lowercase(FileExtension) = '.exe'then
begin
FLargeIcon.Assign(FLargeEx eIcon);
FSmallIcon.Assign (FSmallExeIcon);
result := eiExeIcon;
exit;
end;
try
with Reg do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey(FileExtension, false);
temp := ReadString('');
OpenKey('\' + temp, false);
temp := ReadString('');
OpenKey('DefaultIcon', false);
IconFileName := ReadString('');
commapos := Pos (',',IconFileName);
IconIndex := strtointDef(Copy (IconFileName,commapos+1,L ength (IconFileName)-commapos),- 1);
if iconindex = -1 then
begin
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
result := eiNoExtensionIcon;
exit;
end;
IconFileName := Copy(IconFileName,1,commap os-1);
if ExtractIconEx(Pchar(IconFi leName), IconIndex, HandleLarge,HandleSmall,1) = NULL then
begin
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
result := eiNoExtensionIcon;
exit;
end;
FLargeIcon.Handle := HandleLarge;
FSmallIcon.Handle := HandleSmall;
end;
Result := eiExtensionIcon;
except
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
Result := eiDefaultIcon;
end;
Reg.Free;
end;
end.
unit FindIcon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Registry, ShellApi;
type TeiResult = (eiDefaultIcon,eiExeIcon,e
TeiIcon = (eiGetFolderOpen, eiGetFolderClose, eiGetDefault,eiGetExe, eiGetNoExt);
TeiSetIcon = set of TeiIcon;
type
TRFindIcon = class(TComponent)
private
{ Private declarations }
FShellfile: string;
FFileName: string;
FLargeIcon, FLargeFolderCloseIcon,
FLargeFolderOpenIcon, FLargeNoExtIcon, FLargeDefaultIcon,
FLargeExeIcon, FSmallIcon, FSmallNoExtIcon,
FSmallFolderCloseIcon, FSmallFolderOpenIcon,
FSmallDefaultIcon, FSmallExeIcon: TICon;
FLastIconResult: TeiResult;
FDefaultChanged: boolean;
procedure SetLargeDefaultIcon (value: TIcon);
procedure SetLargeExeIcon (value: TIcon);
procedure SetLargeNoExtIcon (value: TIcon);
procedure SetSmallDefaultIcon (value: TIcon);
procedure SetSmallNoExtIcon (value: TIcon);
procedure SetSmallExeIcon (value: TIcon);
procedure SetFileName (value: string);
function GetIcons: TeiResult;
protected
{ Protected declarations }
public
{ Public declarations }
procedure SetLargeFolderOpenIcon (value: TIcon);
procedure SetLargeFolderCloseIcon (value:TIcon);
procedure SetSmallFolderOpenIcon (value: TIcon);
procedure SetSmallFolderCloseIcon (value:TIcon);
property SmallFolderOpenIcon: TIcon read FSmallFolderOpenIcon write SetSmallFolderOpenIcon;
property SmallFolderCloseIcon: TIcon read FSmallFolderCloseIcon write SetSmallFolderCloseIcon;
property LargeFolderOpenIcon: TIcon read FLargeFolderOpenIcon write SetLargeFolderOpenIcon;
property LargeFolderCloseIcon: TIcon read FLargeFolderCloseIcon write SetLargeFolderCloseIcon;
property LargeIcon: TIcon read FLargeIcon;
property SmallIcon: TIcon read FSmallIcon;
property LastIconResult: TeiResult read FLastIconResult;
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
procedure GetDefaultIcon; overload;
procedure GetDefaultIcon (kind: TeiSetIcon); overload;
published
{ Published declarations }
property FileName: string read FFileName write SetFileName;
property LargeDefaultIcon: TIcon read FLargeDefaultIcon write SetLargeDefaultIcon;
property LargeExeIcon: TIcon read FLargeExeIcon write SetLargeExeIcon;
property LargeNoExtIcon: TIcon read FLargeNoExtIcon write SetLargeNoExtIcon;
property SmallDefaultIcon: TIcon read FSmallDefaultIcon write SetSmallDefaultIcon;
property SmallExeIcon: TIcon read FSmallExeIcon write SetSmallExeIcon;
property SmallNoExtIcon: TIcon read FSmallNoExtIcon write SetSmallNoExtIcon;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Ideias
end;
constructor TRFindIcon.Create (AOwner: TComponent);
begin
inherited Create (AOwner);
FLargeIcon := TIcon.Create;
FLargeNoExtIcon := TIcon.Create;
FLargeExeIcon := TIcon.Create;
FLargeFolderOpenIcon := TIcon.Create;
FLargeFolderCloseIcon := TIcon.Create;
FLargeDefaultIcon := TIcon.Create;
FSmallIcon := TIcon.Create;
FSmallNoExtIcon := TIcon.Create;
FSmallExeIcon := TIcon.Create;
FSmallFolderOpenIcon := TIcon.Create;
FSmallFolderCloseIcon := TIcon.Create;
FSmallDefaultIcon := TIcon.Create;
FLargeIcon.ReleaseHandle;
FLargeNoExtIcon.ReleaseHan
FLargeExeIcon.ReleaseHandl
FLargeFolderOpenIcon.Relea
FLargeFolderCloseIcon.Rele
FLargeDefaultIcon.ReleaseH
FSmallIcon.ReleaseHandle;
FSmallNoExtIcon.ReleaseHan
FSmallExeIcon.ReleaseHandl
FSmallFolderOpenIcon.Relea
FSmallFolderCloseIcon.Rele
FSmallDefaultIcon.ReleaseH
GetDefaultIcon;
end;
procedure TRFindIcon.GetDefaultIcon;
var Reg: TRegistry;
handlelarge, handlesmall: array [1..5] of HICON;
begin
Reg:=TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey ('\SOFTWARE\Microsoft', false);
if Reg.KeyExists ('Windows NT') then
begin
Reg.OpenKey ('Windows NT\CurrentVersion', false);
fshellfile := '\system32\shell32.dll';
end
else
begin
Reg.OpenKey ('Windows\CurrentVersion',
fshellfile := '\system\shell32.dll';
end;
fshellfile := Reg.ReadString('SystemRoot
Reg.Free;
ExtractIconEx(Pchar(fshell
FLargeDefaultIcon.Handle := HandleLarge[1];
FLargeNoExtIcon.Handle := CopyIcon (HandleLarge[1]);
FLargeExeIcon.Handle := HandleLarge[3];
FLargeFolderCloseIcon.Hand
FLargeFolderOpenIcon.Handl
DestroyIcon (HandleLarge[2]);
DestroyIcon (HandleSmall [2]);
FSmallDefaultIcon.Handle := HandleSmall[1];
FSmallNoExtIcon.Handle := CopyIcon (HandleSmall[1]);
FSmallExeIcon.Handle := HandleSmall[3];
FSmallFolderCloseIcon.Hand
FSmallFolderOpenIcon.Handl
FDefaultChanged := true;
end;
procedure TRFindIcon.GetDefaultIcon (kind: TeiSetIcon);
var HandleLarge, HandleSmall: array [1..5] of HICON;
f: integer;
begin
ExtractIconEx(Pchar(fshell
if eiGetDefault in kind then
begin
FLargeDefaultIcon.ReleaseH
FSmallDefaultIcon.ReleaseH
FLargeDefaultIcon.Handle := CopyIcon(HandleLarge[1]);
FSmallDefaultIcon.Handle := CopyIcon(HandleSmall[1]);
end;
if eiGetNoExt in kind then
begin
FLargeNoExtIcon.ReleaseHan
FSmallNoExtIcon.ReleaseHan
FLargeNoExtIcon.Handle := CopyIcon (HandleLarge[1]);
FSmallNoExtIcon.Handle := CopyIcon (HandleSmall[1]);
end;
if eiGetExe in kind then
begin
FLargeExeIcon.ReleaseHandl
FSmallExeIcon.ReleaseHandl
FLargeExeIcon.Handle := CopyIcon(HandleLarge[3]);
FSmallExeIcon.Handle := CopyIcon (HandleSmall[3]);
end;
if eiGetFolderOpen in kind then
begin
FLargeFolderOpenIcon.Relea
FSmallFolderOpenIcon.Relea
FLargeFolderOpenIcon.Handl
FSmallFolderOpenIcon.Handl
end;
if eiGetFolderClose in kind then
begin
FLargeFolderCloseIcon.Rele
FSmallFolderCloseIcon.Rele
FLargeFolderCloseIcon.Hand
FSmallFolderCloseIcon.Hand
end;
for f := 1 to 5 do
begin
DestroyIcon (HandleLarge[f]);
DestroyIcon (HandleSmall [f]);
end;
FDefaultChanged := true;
end;
procedure TRFindIcon.SetFileName(val
begin
if (LowerCase (ExtractFileExt(value)) = LowerCase (ExtractFileExt(FFileName)
and (not FDefaultChanged) then exit;
FFileName := value;
FLastIconResult := GetIcons;
end;
procedure TRFindIcon.SetLargeNoExtIc
begin
FLargeNoExtIcon.Assign(val
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeDefault
begin
FLargeDefaultIcon.Assign(v
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeExeIcon
begin
FLargeExeIcon.Assign(value
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeFolderO
begin
FLargeFolderOpenIcon.Assig
FDefaultChanged := true;
end;
procedure TRFindIcon.SetLargeFolderC
begin
FLargeFolderCloseIcon.Assi
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallNoExtIc
begin
FSmallNoExtIcon.Assign(val
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallDefault
begin
FSmallDefaultIcon.Assign(v
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallExeIcon
begin
FSmallExeIcon.Assign(value
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallFolderO
begin
FSmallFolderOpenIcon.Assig
FDefaultChanged := true;
end;
procedure TRFindIcon.SetSmallFolderC
begin
FSmallFolderCloseIcon.Assi
FDefaultChanged := true;
end;
destructor TRFindIcon.Destroy;
begin
FLargeIcon.Free;
FLargeExeIcon.Free;
FLargeFolderOpenIcon.Free;
FLargeFolderCloseIcon.Free
FLargeDefaultIcon.Free;
FSmallIcon.Free;
FSmallExeIcon.Free;
FSmallFolderOpenIcon.Free;
FSmallFolderCloseIcon.Free
FSmallDefaultIcon.Free;
inherited destroy;
end;
function TRFindIcon.GetIcons: TeiResult;
var handlelarge,
handlesmall: HICON;
temp, fileExtension, IconFileName: string;
iconindex, commapos: integer;
Reg: TRegistry;
begin
FDefaultChanged := false;
Reg := TRegistry.Create;
FileExtension := ExtractFileExt(FFileName);
if FileExtension = '' then
begin
FLargeIcon.Assign (FLargeNoExtIcon);
FSmallIcon.Assign (FSmallNoExtIcon);
result := eiNoExtensionIcon;
exit;
end;
if Lowercase(FileExtension) = '.exe'then
begin
FLargeIcon.Assign(FLargeEx
FSmallIcon.Assign (FSmallExeIcon);
result := eiExeIcon;
exit;
end;
try
with Reg do
begin
RootKey := HKEY_CLASSES_ROOT;
OpenKey(FileExtension, false);
temp := ReadString('');
OpenKey('\' + temp, false);
temp := ReadString('');
OpenKey('DefaultIcon', false);
IconFileName := ReadString('');
commapos := Pos (',',IconFileName);
IconIndex := strtointDef(Copy (IconFileName,commapos+1,L
if iconindex = -1 then
begin
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
result := eiNoExtensionIcon;
exit;
end;
IconFileName := Copy(IconFileName,1,commap
if ExtractIconEx(Pchar(IconFi
begin
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
result := eiNoExtensionIcon;
exit;
end;
FLargeIcon.Handle := HandleLarge;
FSmallIcon.Handle := HandleSmall;
end;
Result := eiExtensionIcon;
except
FLargeIcon.Assign (FLargeDefaultIcon);
FSmallIcon.Assign (FSmallDefaultIcon);
Result := eiDefaultIcon;
end;
Reg.Free;
end;
end.
ASKER
Hmmm let me try this
ASKER
Can't compile. I think the error is because of overload function. I'm using Delphi-3. I'm trying to arrange Delphi-5
Bye the way how can I use this control to add icons in the list view control and get the associated file type?
Bye the way how can I use this control to add icons in the list view control and get the associated file type?
-Drop a button and an Image:
procedure TForm1.Button1Click(Sender
var
Index: Word;
begin
Index:= 0;
Image1.Picture.Icon.Handle
ExtractAssociatedIcon(HIns
'c:\autoexec.bat', Index);
end;
Make sure that the file is exists, include ShellApi in uses clause
Motaz