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;
    }

    }
    }

  • 相关阅读:
    RabbitMQ 部署记录
    Linux下安装db2
    CentOS7 安装 Redis 并设置开机启动
    Firewalld 使用指南
    centos7 redis安装教程
    Centos7下杀毒软件clamav的安装和使用
    centos7 zookeeper集群搭建
    centos开机执行JAR Shell脚本
    centos7 防火墙常用设置
    centos7 Systemd 指令详解
  • 原文地址:https://www.cnblogs.com/zhucl1006/p/666152.html
Copyright © 2011-2022 走看看