zoukankan      html  css  js  c++  java
  • 一个获取文件的ICON类

    using System;
    using System.Runtime.InteropServices;
    namespace Tools.GUI
    {
    /// <summary>
    /// Description r閟um閑 de System.Drawing.Icon.
    /// </summary>
    public class CIcon
    {
    private const UInt32 SHGFI_ICON = 0x100;
    private const UInt32 SHGFI_LARGEICON = 0x0; // 'Large icon
    private const UInt32 SHGFI_SMALLICON = 0x1; // 'Small icon

    [DllImport("shell32.dll")]
    private static extern IntPtr SHGetFileInfo(string pszPath,
    UInt32 dwFileAttributes, ref SHFILEINFO psfi, UInt32 cbSizeFileInfo,
    UInt32 uFlags);

    [StructLayout(LayoutKind.Sequential)]
    private struct SHFILEINFO
    {
    public IntPtr hIcon;
    public IntPtr iIcon;
    public UInt32 dwAttributes;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
    public string szDisplayName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
    public string szTypeName;
    };

    public static System.Drawing.Icon GetIcon(string filename,bool
    b_large_icon)
    {
    UInt32 icon_size;
    if (b_large_icon)
    icon_size=SHGFI_LARGEICON;
    else
    icon_size=SHGFI_SMALLICON;

    IntPtr hImgSmall;
    SHFILEINFO shinfo = new SHFILEINFO();

    hImgSmall = SHGetFileInfo(filename, 0, ref shinfo,(UInt32)Marshal.SizeOf(shinfo),SHGFI_ICON |icon_size);
    System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);

    return myIcon;
    }

    }
    }

  • 相关阅读:
    SQL数据库——存储过程
    常用命令
    八大排序算法
    Java 反射的理解
    Java 集合的理解(持续更新......)
    JAVA 用数组实现 ArrayList
    JVM 运行时的内存分配
    Java中的增强 for 循环 foreach
    Java 泛型
    《七》随机访问文件流
  • 原文地址:https://www.cnblogs.com/zhucl1006/p/666152.html
Copyright © 2011-2022 走看看