Ejemplo n.º 1
0
 /// <summary>
 /// 为列表框的文件设置图标
 /// </summary>
 /// <param name="imageList"></param>
 /// <param name="fileName"></param>
 /// <param name="tf"></param>
 private static void SetIcon(ImageList imageList, string fileName, bool tf)
 {
     NativeApiEx.SHFILEINFO _shFileInfo = new NativeApiEx.SHFILEINFO();
     if (tf.Equals(true))
     {
         int iTotal = (int)NativeApi.SHGetFileInfo(fileName, 0, ref _shFileInfo, 100, 16640);
         if (_shFileInfo.hIcon.Equals(IntPtr.Zero))
         {
             return;
         }
         try
         {
             if (0 < iTotal)
             {
                 Icon icon = Icon.FromHandle(_shFileInfo.hIcon);
                 imageList.Images.Add(icon);
             }
         }
         catch (Exception ex)
         {
             MainForm.main.toolStripStatusLabel_Explorer.Text = "Error: " + ex.Message;
             return;
         }
     }
     else
     {
         int iTotal = (int)NativeApi.SHGetFileInfo(fileName, 0, ref _shFileInfo, 100, 257);
         if (_shFileInfo.hIcon.Equals(IntPtr.Zero))
         {
             return;
         }
         try
         {
             if (0 < iTotal)
             {
                 Icon icon = Icon.FromHandle(_shFileInfo.hIcon);
                 imageList.Images.Add(icon);
             }
         }
         catch (Exception ex)
         {
             MainForm.main.toolStripStatusLabel_Explorer.Text = "Error: " + ex.Message;
             return;
         }
     }
 }
Ejemplo n.º 2
0
 public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref NativeApiEx.SHFILEINFO psfi, uint cbFileInfo, uint uFlags);