Beispiel #1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
            hSysImgList = NativeMethods.SHGetFileInfo("",
                                                      0,
                                                      ref shfi,
                                                      (uint)Marshal.SizeOf(shfi),
                                                      NativeMethods.SHGFI_SYSICONINDEX
                                                      | NativeMethods.SHGFI_SMALLICON);
            Debug.Assert(hSysImgList != IntPtr.Zero);  // cross our fingers and hope to succeed!

            // Set the ListView control to use that image list.
            IntPtr hOldImgList = NativeMethods.SendMessage(lvMain.Handle,
                                                           NativeMethods.LVM_SETIMAGELIST,
                                                           NativeMethods.LVSIL_SMALL,
                                                           hSysImgList);

            // If the ListView control already had an image list, delete the old one.
            if (hOldImgList != IntPtr.Zero)
            {
                NativeMethods.ImageList_Destroy(hOldImgList);
            }


            // Set up the ListView control's basic properties.
            // Put it in "Details" mode, create a column so that "Details" mode will work,
            // and set its theme so it will look like the one used by Explorer.
            NativeMethods.SetWindowTheme(lvMain.Handle, "Explorer", null);

            // Get the items from the file system, and add each of them to the ListView,
            // complete with their corresponding name and icon indices.

            constructInventory();

            UpdateList();
            UpdateTitle();
        }
Beispiel #2
0
        void UpdateItem(ListViewItem item)
        {
            LVInfo info = (LVInfo)item.Tag;

            item.Text = Path.GetFileNameWithoutExtension(info.FileName);


            {
                NativeMethods.SHFILEINFO shfi = new NativeMethods.SHFILEINFO();
                IntPtr himl = NativeMethods.SHGetFileInfo(info.FullName,
                                                          128, //FileAttribute.Normal,
                                                          ref shfi,
                                                          (uint)Marshal.SizeOf(shfi),
                                                          16 | //SHGFI_USEFILEATTRIBUTES
                                                          NativeMethods.SHGFI_DISPLAYNAME |
                                                          NativeMethods.SHGFI_SYSICONINDEX |
                                                          NativeMethods.SHGFI_SMALLICON |
                                                          0
                                                          );
                Debug.Assert(himl == hSysImgList); // should be the same imagelist as the one we set
                item.ImageIndex = shfi.iIcon;
            }

            LinkData lnk = new LinkData(info.FullName, this);

            foreach (ColumnHeader ch in lvMain.Columns)
            {
                if (ch.Name == COLUMN_NAME)
                {
                    continue;
                }

                ListViewItem.ListViewSubItem sub = item.SubItems[ch.Name];
                if (sub == null)
                {
                    sub      = new ListViewItem.ListViewSubItem();
                    sub.Name = ch.Name;
                    item.SubItems.Add(sub);
                }

                if (ch.Name == COLUMN_PATH)
                {
                    sub.Text = lnk.Path;
                }
                else if (ch.Name == COLUMN_ARGUMENTS)
                {
                    sub.Text = lnk.Arguments;
                }
                else if (ch.Name == COLUMN_WORKINGDIRECTORY)
                {
                    sub.Text = lnk.WorkingDirectory;
                }
                else if (ch.Name == COLUMN_ICONPATH)
                {
                    sub.Text = lnk.IconPath;
                }
                else if (ch.Name == COLUMN_ICONINDEX)
                {
                    sub.Text = lnk.IconIndex.ToString();
                }
                else if (ch.Name == COLUMN_RUNASADMIN)
                {
                    sub.Text = lnk.IsRunAsAdmin.ToString();
                }
                else
                {
                    Debug.Assert(false);
                }
            }

            //if(lvMain.Items.Count!=0)
            //    lvMain.RedrawItems(0, lvMain.Items.Count-1, false);
        }