当前位置: 首页>>代码示例>>C#>>正文


C# SHFILEINFO类代码示例

本文整理汇总了C#中SHFILEINFO的典型用法代码示例。如果您正苦于以下问题:C# SHFILEINFO类的具体用法?C# SHFILEINFO怎么用?C# SHFILEINFO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SHFILEINFO类属于命名空间,在下文中一共展示了SHFILEINFO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSmallFileIcon

 public static Bitmap GetSmallFileIcon(string filename)
 {
     SHFILEINFO shinfo = new SHFILEINFO();
     Win32.SHGetFileInfo(filename, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
     Icon i = Icon.FromHandle(shinfo.hIcon);
     return i.ToBitmap();
 }
开发者ID:almaddy95,项目名称:MinecraftServerManager,代码行数:7,代码来源:Icons.cs

示例2: GetFileIcon

        /// <summary>
        /// Gets the icon asotiated with the filename.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static Icon GetFileIcon(string fileName)
        {
            System.Drawing.Icon myIcon = null;
            try
            {
                IntPtr hImgSmall;    //the handle to the system image list
                SHFILEINFO shinfo = new SHFILEINFO();

                //Use this to get the small Icon
                hImgSmall = Win32.SHGetFileInfo(fileName, 0, ref shinfo,
                                                (uint)Marshal.SizeOf(shinfo),
                                                Win32.SHGFI_ICON |
                                               (Win32.SHGFI_LARGEICON | Win32.SHGFI_USEFILEATTRIBUTES));

                //The icon is returned in the hIcon member of the shinfo
                //struct
                myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);

            }
            catch
            {
                return null;
            }
            return myIcon;
        }
开发者ID:userof,项目名称:explorernet,代码行数:30,代码来源:IconExtractor.cs

示例3: GetExtensionIcon

        public static Icon GetExtensionIcon(string aFileExtension, bool largeIcon)
        {
            string vFileName = String.Format("*.{0}", aFileExtension);

            SHFILEINFO shinfo = new SHFILEINFO();
            IntPtr hImg;
            if (largeIcon)
            {
                hImg = SHGetFileInfo(vFileName, FILE_ATTRIBUTE_NORMAL, ref shinfo,
                (uint)Marshal.SizeOf(shinfo),
                SHGFI_ICON |
                SHGFI_LARGEICON |
                SHGFI_USEFILEATTRIBUTES);
            }
            else
            {
                hImg = SHGetFileInfo(vFileName, FILE_ATTRIBUTE_NORMAL, ref shinfo,
                (uint)Marshal.SizeOf(shinfo),
                SHGFI_ICON |
                SHGFI_SMALLICON |
                SHGFI_USEFILEATTRIBUTES);
            }
            try
            {
                return Icon.FromHandle(shinfo.hIcon);
            }
            catch
            {
                return null;
            }
        }
开发者ID:heinschulie,项目名称:z2z,代码行数:31,代码来源:DrawingUtils.cs

示例4: SHFILEINFO

        /// <summary>
        /// Returns an icon that should be utilised to represent the specified path
        /// within a directory listing.
        /// </summary>
        /// <param name="path">The path (directory or file name) to fetch an icon for</param>
        /// <returns>The index into the image list for the icon associated with the path</returns>
        public int this[string path]
        {
            get
            {
                // Determine the index of the icon in the system image list
                SHFILEINFO shinfo = new SHFILEINFO();
                IntPtr hImageList = SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

                // If we haven't fetched this icon yet
                if (!shellIndexToOurIndex.ContainsKey(shinfo.iIcon))
                {
                    // Fetch the icon
                    IntPtr hIcon = ImageList_GetIcon(hImageList, shinfo.iIcon, ILD_NORMAL);
                    Icon myIcon = Icon.FromHandle(hIcon);
                    DestroyIcon(hIcon);

                    // And add it to our managed image list
                    shellIndexToOurIndex.Add(shinfo.iIcon, imageList.Images.Count);
                    imageList.Images.Add(myIcon);
                }

                // Return the index of the icon to use for this path.
                return shellIndexToOurIndex[shinfo.iIcon];
            }
        }
开发者ID:jpapayan,项目名称:tuberun_wm,代码行数:31,代码来源:ShellIconCache.cs

示例5: GetIcon

        /// <summary>
        /// Get the associated Icon for a file or application, this method always returns
        /// an icon. If the strPath is invalid or there is no idonc the defaulticon is returned
        /// </summary>
        /// <param name="strPath">full path to the file or directory</param>
        /// <param name="bSmall">if true, the 16x16 icon is returned otherwise the32x32</param>
        /// <param name="bOpen">if true, and strPath is a folder, returns the 'open' icon rather than the 'closed'</param>
        /// <returns></returns>
        public static Icon GetIcon(string strPath, bool bSmall, bool bOpen)
        {
            // Detect Operating System
            // From: http://www.mono-project.com/FAQ:_Technical
            int p = (int)Environment.OSVersion.Platform;
            if ((p == 4) || (p == 6) || (p == 128))
            {
                return GetIconFromResources(strPath);
            }
            else
            {
                try
                {
                    SHFILEINFO info = new SHFILEINFO(true);
                    int cbFileInfo = Marshal.SizeOf(info);
                    SHGFI flags;
                    if (bSmall)
                        flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes;
                    else
                        flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes;
                    if (bOpen) flags = flags | SHGFI.OpenIcon;

                    SHGetFileInfo(strPath, 256, out info, (uint)cbFileInfo, flags);
                    return Icon.FromHandle(info.hIcon);
                }
                catch
                {
                    return GetIconFromResources(strPath);
                }
            }
        }
开发者ID:sunny256,项目名称:nbuexplorer,代码行数:39,代码来源:ExtractIcon.cs

示例6: SHGetFileInfo

 private static extern int SHGetFileInfo(
     string pszPath,
     uint dwFileAttributes,
     out   SHFILEINFO psfi,
     uint cbfileInfo,
     SHGFI uFlags
     );
开发者ID:EdgarEDT,项目名称:myitoppsp,代码行数:7,代码来源:ExtractIcon.cs

示例7: GetDirectoryIcon

        /// <summary>
        /// Get the icon for a directory.
        /// </summary>
        /// <param name="small">true to retrieve a small icon; false otherwise.</param>
        /// <param name="open">true to retrieve an icon depicting an open item; false otherwise.</param>
        /// <returns>The directory icon.</returns>
        public static Icon GetDirectoryIcon(bool small, bool open)
        {
            uint flags = SHGFI_ICON;

            if (small)
            {
                flags |= SHGFI_SMALLICON;
            }
            else
            {
                flags |= SHGFI_LARGEICON;
            }

            if (open)
            {
                flags |= SHGFI_OPENICON;
            }

            SHFILEINFO shellFileInfo = new SHFILEINFO();
            IntPtr success = SHGetFileInfo(null, 0, ref shellFileInfo, (uint)Marshal.SizeOf(shellFileInfo), flags);

            // hack to ensure the icon handle is properly freed
            Icon tempIcon = Icon.FromHandle(shellFileInfo.hIcon);
            Icon icon = (Icon)tempIcon.Clone();
            tempIcon.Dispose();
            NativeMethods.DestroyIcon(shellFileInfo.hIcon);

            return icon;
        }
开发者ID:bullshock29,项目名称:Wix3.6Toolset,代码行数:35,代码来源:NativeMethods.cs

示例8: GetShellFileInfo

 private static SHFILEINFO GetShellFileInfo(string path, uint fileAttributes)
 {
     var info = new SHFILEINFO();
     const uint flags = SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON;
     SHGetFileInfo(path, fileAttributes, ref info, (uint) Marshal.SizeOf(info), flags);
     return info;
 }
开发者ID:nicocrm,项目名称:DotNetSDataClient,代码行数:7,代码来源:ShellUtils.cs

示例9: FormatType

 private static string FormatType(FileInfo fileInfo)
 {
     var info = new SHFILEINFO();
     const uint flags = (uint) SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES;
     SHGetFileInfo(fileInfo.FullName, FILE_ATTRIBUTE_NORMAL, ref info, (uint) Marshal.SizeOf(info), flags);
     return info.szTypeName;
 }
开发者ID:bsimser,项目名称:goldbox,代码行数:7,代码来源:FileDto.cs

示例10: SHGetFileInfo

    public static extern IntPtr SHGetFileInfo(
		string pszPath,
		uint dwFileAttributes,
		ref SHFILEINFO psfi,
		uint cbFileInfo,
		uint uFlags
		);
开发者ID:sdgdsffdsfff,项目名称:WhatEver,代码行数:7,代码来源:Shell32.cs

示例11: GetFolderIcon

        public static Icon GetFolderIcon()
        {
            // Need to add size check, although errors generated at present!
            uint flags = SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON;

            // Get the folder icon
            var shfi = new SHFILEINFO();

            var res = SHGetFileInfo(@"C:\Windows",
                FILE_ATTRIBUTE_DIRECTORY,
                out shfi,
                (uint)Marshal.SizeOf(shfi),
                flags);

            if (res == IntPtr.Zero)
                throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());

            // Load the icon from an HICON handle
            Icon.FromHandle(shfi.hIcon);

            // Now clone the icon, so that it can be successfully stored in an ImageList
            var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();

            DestroyIcon(shfi.hIcon);        // Cleanup

            return icon;
        }
开发者ID:jollywho,项目名称:LFI,代码行数:27,代码来源:NativeMethods.cs

示例12: FileIconIndex

 public static int FileIconIndex(string AFileName)
 {
     SHFILEINFO vFileInfo = new SHFILEINFO();
     SHGetFileInfo(AFileName, 0, ref vFileInfo,
         Marshal.SizeOf(vFileInfo), SHGFI_SYSICONINDEX);
     return vFileInfo.iIcon;
 }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:7,代码来源:SystemICO.cs

示例13: ToImageSource

 public static ImageSource ToImageSource(this string path)
 {
     SHFILEINFO shinfo = new SHFILEINFO();
     Win32.SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
     Icon myIcon = Icon.FromHandle(shinfo.hIcon);
     ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(myIcon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     return imageSource;
 }
开发者ID:z7059652,项目名称:WPFTest,代码行数:8,代码来源:IconToImage.cs

示例14: GetIcon

 /// <summary>
 /// 获取系统图标
 /// </summary>
 /// <param name="path">文件名</param>
 /// <param name="dwAttr">文件信息</param>
 /// <param name="dwFlag">获取信息控制字</param>
 /// <returns></returns>
 private Icon GetIcon( string path, FILE_ATTRIBUTE dwAttr, SHGFI dwFlag)
 {
    SHFILEINFO fi = new SHFILEINFO();
    Icon ic = null;
    int iTotal = (int)SHGetFileInfo(path, dwAttr, ref fi, 0, dwFlag);
    ic = Icon.FromHandle(fi.hIcon);
    return ic;
 }
开发者ID:cheng521yun,项目名称:https---github.com-frontflag-FTMZ_CY,代码行数:15,代码来源:ShellImage.cs

示例15: ListViewSysImages

 public static void ListViewSysImages(ListView AListView)
 {
     SHFILEINFO vFileInfo = new SHFILEINFO();
     IntPtr vImageList = SHGetFileInfo("", 0, ref vFileInfo, Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE | SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
     SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_NORMAL, vImageList);
     vImageList = SHGetFileInfo("", 0, ref vFileInfo, Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
     SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_SMALL, vImageList);
 } 
开发者ID:maanshancss,项目名称:ClassLibrary,代码行数:8,代码来源:SystemIconShell.cs


注:本文中的SHFILEINFO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。