using System.Threading;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using Infragistics.Win;
using Icons2;
using Infragistics.Win.UltraWinTree;
using Infragistics.Shared.Serialization;
using FldrSel.draw;
using System.Runtime.InteropServices;
{
/**
* a holder for an icon and its ID
* not required in all cases
*/
public class IconInf
{
public Icon theIcon;
public int id;
}
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
{
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
public const uint SHGFI_SMALLICON = 0x1; // 'Small icon
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
}
public class Othr
{
private struct SHFILEINFO
{
public IntPtr hIcon; // : icon
public int iIcon; // : icondex
public int dwAttributes; // : SFGAO_ flags
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}
private static extern IntPtr SHGetFileInfo(string pszPath, int dwFileAttributes, ref SHFILEINFO psfi, int cbFileInfo, int uFlags);
private const int SHGFI_SMALLICON = 0X1;
private const int SHGFI_LARGEICON = 0X0; // Large icon
public const string FOLDER_STR = "[folder]";
public const string DRIVE_STR = "[folder]";
Dictionary<string, IconInf> icons = new Dictionary<string, IconInf>();
{
}
public void init(){
string sExtn = "txt";
if (!icons.ContainsKey(sExtn))
{
IconInf oIconInf = new IconInf();
oIconInf.theIcon = di.GetIcon(sExtn);
oIconInf.id = icons.Count;
icons.Add(sExtn, oIconInf);
}
}
public IconInf getIcon(string sFileName)
{
return getIcon2(sFileName);
}
private IconInf getIcon2(string FileName)
{
lock (icons)
{
if (icons.Count > 1100)
{
System.Collections.ArrayList keys = new System.Collections.ArrayList(icons.Keys);
for (int i = 700; i < 800; i++)//remove from the middle, hopefully they are less used
{
icons.Remove(keys[i].ToString());
}
init();//reinit
}
System.Drawing.Icon myIcon = null;
IntPtr hImgSmall = default(IntPtr); //The handle to the system image list.
IntPtr hImgLarge = default(IntPtr);
string sExtn = null;
sExtn = "txt";
{
//FileName = "d:\Dev"
if (!System.IO.Directory.Exists(FileName))
{
sExtn = FileName.Substring((FileName.LastIndexOf(".") + 1));
}
else
{
sExtn = FileName;
}
if (icons.ContainsKey(FileName))
{
sExtn = FileName;
}
else if (icons.ContainsKey(sExtn))
{
//do nothing
}
else
{
DefaultIcon di = new DefaultIcon();
IconInf oIconInf = new IconInf();
oIconInf.theIcon = di.GetIcon(sExtn);
oIconInf.id = icons.Count;
icons.Add(sExtn, oIconInf);
catch (Exception ex)
{
{
SHFILEINFO shinfo = new SHFILEINFO();
shinfo = new SHFILEINFO();
hImgSmall = SHGetFileInfo(FileName, 0, ref shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
//icons[sExtn] = myIcon;
IconInf oIconInf = new IconInf();
oIconInf.theIcon = myIcon;
oIconInf.id = icons.Count;
icons.Add(sExtn, oIconInf);
}
catch (Exception ex2)
{
//default
sExtn = "txt";
}
}
return oIconInf2;
}
}