コード例 #1
0
ファイル: FileIcon.cs プロジェクト: barrett2474/CMS2
        /// <summary>
        ///     This Method is used to return the windows file type icon in rtf form
        /// </summary>
        /// <param name="fileName">
        ///     Out of fileName-extenion the file type icon is extracted
        ///     <br/>
        ///         EXAMPLE:
        ///         fileName = "Hello.doc" ---> Result will be the icon for MS Word document
        /// </param>
        /// <returns>
        ///     A String containing a icon in WMeta8 Icon format (RTF Control string).
        /// </returns>
        public static Image GetFileIcon(string fileName)
        {
            var shinfo = new NativeMethods.ShFileinfo();
            NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
                (uint) Marshal.SizeOf(shinfo),
                (uint) (NativeMethods.ShGetFileInfoConstants.ShgfiIcon |
                        NativeMethods.ShGetFileInfoConstants.ShgfiLargeIcon |
                        NativeMethods.ShGetFileInfoConstants.ShgfiUseFileAttributes));

            var fTypeIcon = Icon.FromHandle(shinfo.hIcon);
            return fTypeIcon.ToBitmap();
        }
コード例 #2
0
ファイル: FileIcon.cs プロジェクト: nnuds/FIT.MsgReader
        /// <summary>
        ///     This Method is used to return the windows file type icon in rtf form
        /// </summary>
        /// <param name="fileName">
        ///     Out of fileName-extenion the file type icon is extracted
        ///     <br/>
        ///         EXAMPLE:
        ///         fileName = "Hello.doc" ---> Result will be the icon for MS Word document
        /// </param>
        /// <returns>
        ///     A String containing a icon in WMeta8 Icon format (RTF Control string).
        /// </returns>
        public static Image GetFileIcon(string fileName)
        {
            var shinfo = new NativeMethods.ShFileinfo();

            NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
                                        (uint)Marshal.SizeOf(shinfo),
                                        (uint)(NativeMethods.ShGetFileInfoConstants.ShgfiIcon |
                                               NativeMethods.ShGetFileInfoConstants.ShgfiLargeIcon |
                                               NativeMethods.ShGetFileInfoConstants.ShgfiUseFileAttributes));


            var fTypeIcon = Icon.FromHandle(shinfo.hIcon);

            return(fTypeIcon.ToBitmap());
        }