コード例 #1
0
        public static Icon GetFolderIcon( string fileName, int index, bool isSmall )
        {
            const uint SHGFI_ICON = 0x000000100;
            const uint SHGFI_SMALLICON = 0x000000001;
            const uint SHGFI_LARGEICON = 0x000000000;
            const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;

            uint flags = SHGFI_ICON + ( isSmall ? SHGFI_SMALLICON : SHGFI_LARGEICON );

            var fileInfo = new SHFILEINFOW();
            uint size = (uint) Marshal.SizeOf( fileInfo );
            uint result = NativeMethods.SHGetFileInfoW( fileName, FILE_ATTRIBUTE_DIRECTORY, ref fileInfo, size, flags );

            if ( result == 0 )
            {
                return null;
            }

            var icon = (Icon) Icon.FromHandle( fileInfo.hIcon ).Clone();
            DestroyIcon( fileInfo.hIcon );
            return icon;
        }
コード例 #2
0
 public static extern uint SHGetFileInfoW( [In] [MarshalAs( UnmanagedType.LPWStr )] string pszPath,
                                           uint dwFileAttributes,
                                           ref SHFILEINFOW psfi,
                                           uint cbFileInfo,
                                           uint uFlags );