• C#获取软件图标


    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.IO;
    namespace ShowIcon
    {
    [StructLayout( LayoutKind.Sequential)]
    public struct FileInfomation
    {
    public IntPtr hIcon;
    public int iIcon;
    public int dwAttributes;

    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst
    = 260 )]
    public string szDisplayName;

    [ MarshalAs( UnmanagedType.ByValTStr, SizeConst
    = 80 )]
    public string szTypeName;
    }

    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm
    {
    [STAThread]
    public static void Main(string[] args)
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(
    false);
    Application.Run(
    new MainForm());
    }


    [DllImport(
    "shell32.dll", EntryPoint="SHGetFileInfo")]
    public static extern int GetFileInfo(string pszPath, int dwFileAttributes, ref FileInfomation psfi, int cbFileInfo,int uFlags);
    public MainForm()
    {
    //
    // The InitializeComponent() call is required for Windows Forms designer support.
    //
    InitializeComponent();

    //
    // TODO: Add constructor code after the InitializeComponent() call.
    //
    }
    public static Icon GetSmallIcon(string path)
    {
    FileInfomation _info
    = new FileInfomation();

    GetFileInfo(path,
    0, ref _info, Marshal.SizeOf(_info), (int)(0x000000100| 0x000000001));
    try
    {
    return Icon.FromHandle(_info.hIcon);
    }
    catch
    {
    return null;
    }
    }
    void Button1Click(object sender, System.EventArgs e)
    {
    this.openFileDialog1.ShowDialog();
    }

    void OpenFileDialog1FileOk(object sender, System.ComponentModel.CancelEventArgs e)
    {
    this.textBox1.Text=this.openFileDialog1.FileName;
    this.pictureBox1.Image=GetSmallIcon(this.openFileDialog1.FileName).ToBitmap();
    }
    }

    }
  • 相关阅读:
    利用JBoss漏洞拿webshell方法
    jboss漏洞导致服务器中毒
    dubbo bug之 Please check registry access list (whitelist/blacklist)的分析与解决
    将list转为json字符串
    MySQL语句给字段值加1
    java int怎么转换为string
    HttpURLConnection如何添加请求头?
    eclipse下载egit插件,实现代码git同步问题
    eclipse编译项目用maven编译问题
    fastjson将java list转为json字符串
  • 原文地址:https://www.cnblogs.com/longle/p/2072908.html
Copyright © 2020-2023  润新知