impsfiletype.cs

来自「破解的飞信源代码」· CS 代码 · 共 40 行

CS
40
字号
namespace Imps.Client.Resource
{
    using System;
    using System.Drawing;
    using System.Runtime.InteropServices;

    public class ImpsFileType
    {
        private const int SHGFI_ICON = 0x100;
        private const int SHGFI_LARGEICON = 0;
        private const int SHGFI_SMALLICON = 1;
        private const int SHGFI_TYPENAME = 0x400;

        public static Icon GetIcon(string sFileName)
        {
            SHFILEINFO structure = new SHFILEINFO();
            int cbFileInfo = Marshal.SizeOf(structure);
            int uFlags = 0x100;
            SHGetFileInfo(sFileName, 0, ref structure, cbFileInfo, uFlags);
            return Icon.FromHandle(structure.hIcon);
        }

        [DllImport("shell32.dll", CharSet=CharSet.Auto)]
        public static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO info, int cbFileInfo, int uFlags);

        [StructLayout(LayoutKind.Sequential)]
        public struct SHFILEINFO
        {
            public IntPtr hIcon;
            public uint iIcon;
            public uint dwAttributes;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=260)]
            public char[] szDisplayName;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst=80)]
            public char[] szTypeName;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?