zoukankan      html  css  js  c++  java
  • 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();
    }
    }

    }
  • 相关阅读:
    intent-filter的用法
    关于三星手机刷机,以GTN8000为例
    seamless video loop with videoview
    hashmap,list,vector,Linkedlist的优缺点
    vlc+mfc,搭建简单的播放器
    OA项目9:部门管理的上下级部门的功能实现
    OA项目8:表映射关系及跟对象之间的关系处理
    OA项目7:系统管理之部门管理
    OA项目6:项目优化
    OA项目5:系统管理之岗位管理
  • 原文地址:https://www.cnblogs.com/longle/p/2072908.html
Copyright © 2011-2022 走看看