Exemplo n.º 1
0
        public static Icon GetFolderIcon(IconSize size, FolderType folderType)
        {
            uint flags = Shell32Wrapper.SHGFI_ICON | Shell32Wrapper.SHGFI_USEFILEATTRIBUTES;

            if (FolderType.Open == folderType)
            {
                flags += Shell32Wrapper.SHGFI_OPENICON;
            }

            if (IconSize.Small == size)
            {
                flags += Shell32Wrapper.SHGFI_SMALLICON;
            }
            else
            {
                flags += Shell32Wrapper.SHGFI_LARGEICON;
            }

            Shell32Wrapper.SHFILEINFO shfi = new Shell32Wrapper.SHFILEINFO();
            Shell32Wrapper.SHGetFileInfo(null, Shell32Wrapper.FILE_ATTRIBUTE_DIRECTORY, ref shfi, (uint)Marshal.SizeOf(shfi), flags);

            Icon.FromHandle(shfi.hIcon);

            Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();

            DestroyIcon(shfi.hIcon);

            return(icon);
        }
Exemplo n.º 2
0
        public static string GetFileType(string ext)
        {
            Shell32Wrapper.SHFILEINFO shfi = new Shell32Wrapper.SHFILEINFO();
            uint flags = Shell32Wrapper.SHGFI_TYPENAME | Shell32Wrapper.SHGFI_USEFILEATTRIBUTES;

            Shell32Wrapper.SHGetFileInfo(ext, (uint)0, ref shfi, (uint)Marshal.SizeOf(shfi), flags);

            return(shfi.szTypeName.Trim());
        }
Exemplo n.º 3
0
        public static Icon GetFileIcon(string name, IconSize size)
        {
            Shell32Wrapper.SHFILEINFO shfi = new Shell32Wrapper.SHFILEINFO();
            uint flags = Shell32Wrapper.SHGFI_ICON | Shell32Wrapper.SHGFI_USEFILEATTRIBUTES;

            if (IconSize.Small == size)
            {
                flags += Shell32Wrapper.SHGFI_SMALLICON;
            }
            else
            {
                flags += Shell32Wrapper.SHGFI_LARGEICON;
            }

            Shell32Wrapper.SHGetFileInfo(name, Shell32Wrapper.FILE_ATTRIBUTE_NORMAL, ref shfi, (uint)Marshal.SizeOf(shfi), flags);

            Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();

            DestroyIcon(shfi.hIcon);

            return(icon);
        }