Okay,
thanks for all replies, finally I got this:
Reuse it if you like it!
#region ExtractAssociat edIcon
[DllImport("shel l32.dll")]
static extern IntPtr ExtractAssociat edIcon(IntPtr hinst, string file,
ref int index);
public static System.Drawing. Icon FindAssocIcon(s tring filename)
{
try
{
string ext = System.IO.Path. GetExtension(fi lename);
RegWin32.Regist ryKey key =
RegWin32.Regist ry.ClassesRoot. OpenSubKey(ext) ;
if(key != null)
{
string val = (string)key.Get Value("");
if(val != null && val != string.Empty)
{
key = RegWin32.Regist ry.ClassesRoot. OpenSubKey(val) ;
if(key != null)
{
key = key.OpenSubKey( "DefaultIco n");
if(key != null)
{
val = (string)key.Get Value("");
if(val != null && val != string.Empty)
{
string name;
int icoIndex = -1;
int index = val.LastIndexOf (',');
if(index > 0)
{
name = val.Substring(0 , index);
if(index < val.Length-1)
{
icoIndex = Convert.ToInt32 ( val.Substring(i ndex+1) );
}
}//index
else
name = val;
System.Reflecti on.Module [] mod =
System.Reflecti on.Assembly.Get CallingAssembly ().GetModules() ;
IntPtr ptr =
ExtractAssociat edIcon(Marshal. GetHINSTANCE(mo d[0]), name, ref icoIndex);
if(ptr != IntPtr.Zero)
{
return System.Drawing. Icon.FromHandle (ptr);
}
}
}
}
}
}
}
catch(Exception ex)
{
MessageBox.Show (ex.Message+"\n "+ex.InnerExcep tion);
}
return null;
}
#endregion
mphanke wrote:
Hi,
how can I retrieve the icon for a registered file extension from the
registry and show it in my ListView?
Any hints appreciated,
Martin