Пример #1
0
 public static extern IntPtr SHGetFileInfo(string pszPath,
     uint dwFileAttributes,
     ref SHFILEINFO psfi,
     uint cbSizeFileInfo,
     uint uFlags);
Пример #2
0
        void refreshFileList()
        {
            listView1.Items.Clear();
            listView2.Items.Clear();

            if (workingDirectory == null || workingDirectory.Length == 0)
                return;
            this.Cursor = Cursors.WaitCursor;
            try
            {
                string[] files = Directory.GetFiles(workingDirectory);
                int imageIndex = 0;
                imageList1.Images.Clear();
                SHFILEINFO shinfo = new SHFILEINFO();
                listView1.BeginUpdate();
                listView2.BeginUpdate();
                foreach (string s in files)
                {
                    FileInfo fi = new FileInfo(s);
                    if (fi.Extension.ToLower() == ".enc")
                    {
                        ListViewItem lvi = new ListViewItem(fi.Name);
                        lvi.SubItems.Add(fi.Length.ToString());
                        lvi.Tag = fi.FullName;
                        lvi.ImageIndex = 0;
                        listView2.Items.Add(lvi);
                    }
                    else
                    {
                        //extract file icon
                        IntPtr hImgSmall = MyShell.SHGetFileInfo(s, 0, ref shinfo,(uint)Marshal.SizeOf(shinfo),
                            MyShell.SHGFI_ICON |
                            MyShell.SHGFI_SMALLICON);
                        //The icon is returned in the hIcon member of the shinfo
                        //struct
                        System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
                        imageList1.Images.Add(myIcon);

                        ListViewItem lvi = new ListViewItem(fi.Name);
                        lvi.ImageIndex = imageIndex++;
                        lvi.SubItems.Add(fi.Length.ToString());
                        lvi.Tag = fi.FullName;
                        listView1.Items.Add(lvi);
                    }
                }
                listView1.EndUpdate();
                listView2.EndUpdate();
            }
            catch(IOException ex)
            {
                MessageBox.Show("Erro ao atualizar lista de arquivos: "+ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Arrow;
            }
        }