Ejemplo n.º 1
0
        public void GetInfo(bool folder)
        {
            FileIcon.SHFILEINFO shfileinfo;

            if (fileIcon != null)
            {
                fileIcon.Dispose();
            }
            fileIcon    = null;
            typeName    = "";
            displayName = "";
            shfileinfo  = new FileIcon.SHFILEINFO();
            uint ui = (uint)Marshal.SizeOf(shfileinfo.GetType());
            int  i1 = FileIcon.SHGetFileInfo(fileName, folder ? 0x10 : 0, ref shfileinfo, ui, (uint)flags);

            if (i1 != 0)
            {
                if (shfileinfo.hIcon != IntPtr.Zero)
                {
                    fileIcon = Icon.FromHandle(shfileinfo.hIcon);
                }
                typeName    = shfileinfo.szTypeName;
                displayName = shfileinfo.szDisplayName;
            }
            else
            {
                int i2 = FileIcon.GetLastError();
                Console.WriteLine("Error {0}", i2);
                string s  = new String('\0', 0x100);
                int    i3 = FileIcon.FormatMessage(0x1200, IntPtr.Zero, i2, 0, s, 0x100, 0);
                Console.WriteLine("Len {0} text {1}", i3, s);
            }
        }
Ejemplo n.º 2
0
        private void AddIcon(bool folder, string extension)
        {
            FileIcon icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON);

            this.ilIcons.Images.Add(icon.ShellIcon);
            icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_SELECTED | FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON);
            this.ilIcons.Images.Add(icon.ShellIcon);
            icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES);
            this.ilLargeIcons.Images.Add(icon.ShellIcon);
            icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_SELECTED | FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES);
            this.ilLargeIcons.Images.Add(icon.ShellIcon);
        }
Ejemplo n.º 3
0
 private static extern int SHGetFileInfo(string pszPath, int dwFileAttributes, ref FileIcon.SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
Ejemplo n.º 4
0
 public FileIcon(bool folder, string fileName, FileIcon.SHGetFileInfoConstants flags)
 {
     this.fileName = fileName;
     this.flags = flags;
     GetInfo(folder);
 }
Ejemplo n.º 5
0
 private void AddIcon(bool folder, string extension)
 {
     FileIcon icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON);
     this.ilIcons.Images.Add(icon.ShellIcon);
     icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_SELECTED | FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | FileIcon.SHGetFileInfoConstants.SHGFI_SMALLICON);
     this.ilIcons.Images.Add(icon.ShellIcon);
     icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES);
     this.ilLargeIcons.Images.Add(icon.ShellIcon);
     icon = new FileIcon(folder, extension, FileIcon.SHGetFileInfoConstants.SHGFI_SELECTED | FileIcon.SHGetFileInfoConstants.SHGFI_TYPENAME | FileIcon.SHGetFileInfoConstants.SHGFI_ICON | FileIcon.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES);
     this.ilLargeIcons.Images.Add(icon.ShellIcon);
 }