示例#1
0
        private void searchBox_SuggestionActivated(object sender, SuggestionActivatedEventArgs e)
        {
            ApplicationListViewItem item = e.Item as ApplicationListViewItem;

            filenameBox.Text = item.FileName;
            argsBox.Text     = item.Arguments;
            startInBox.Text  = item.WorkingDirectory;

            UpdateUi();
            startBtn.Focus();
        }
示例#2
0
        private void CreateSuggestions()
        {
            List<ApplicationListViewItem> items = new List<ApplicationListViewItem>();
            ImageList imageLst = new ImageList();
            imageLst.ColorDepth = ColorDepth.Depth32Bit;

            StringBuilder allUsersStartMenu = new StringBuilder(260 + 1);
            WinApi.SHGetSpecialFolderPath(IntPtr.Zero, allUsersStartMenu, WinApi.CSIDL.COMMON_PROGRAMS, false);

            Stack<DirectoryInfo> pendingDirs = new Stack<DirectoryInfo>();
            pendingDirs.Push(new DirectoryInfo(allUsersStartMenu.ToString()));
            pendingDirs.Push(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)));

            IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();

            while (pendingDirs.Count > 0)
            {
                DirectoryInfo dir = pendingDirs.Pop();

                try
                {
                    foreach (FileInfo file in dir.GetFiles("*.lnk"))
                    {
                        var shortcut = shell.CreateShortcut(file.FullName) as IWshRuntimeLibrary.IWshShortcut;
                        if (shortcut != null)
                        {
                            string name = Path.GetFileNameWithoutExtension(shortcut.FullName);
                            string targetName = Path.GetFileNameWithoutExtension(shortcut.TargetPath);
                            string targetExt = Path.GetExtension(shortcut.TargetPath);
                            if (targetExt == ".exe" && name.ToLower().IndexOf("uninst") < 0 && targetName.ToLower().IndexOf("uninst") < 0)
                            {
                                var item = new ApplicationListViewItem(name, shortcut.TargetPath, shortcut.Arguments, shortcut.WorkingDirectory);

                                var icon = System.Drawing.Icon.ExtractAssociatedIcon(item.FileName);
                                imageLst.Images.Add(item.FileName, icon);
                                item.ImageKey = item.FileName;

                                items.Add(item);
                            }
                        }
                    }

                    foreach (DirectoryInfo subdir in dir.GetDirectories())
                        pendingDirs.Push(subdir);
                }
                catch
                {
                }
            }

            items.Sort();

            suggestItems = items.ToArray();
            suggestImages = imageLst;

            searchBox.UpdateSuggestions(suggestItems, suggestImages);
        }
示例#3
0
        private void CreateSuggestions()
        {
            List <ApplicationListViewItem> items = new List <ApplicationListViewItem>();
            ImageList imageLst = new ImageList();

            imageLst.ColorDepth = ColorDepth.Depth32Bit;

            StringBuilder allUsersStartMenu = new StringBuilder(260 + 1);

            WinApi.SHGetSpecialFolderPath(IntPtr.Zero, allUsersStartMenu, WinApi.CSIDL.COMMON_PROGRAMS, false);

            Stack <DirectoryInfo> pendingDirs = new Stack <DirectoryInfo>();

            pendingDirs.Push(new DirectoryInfo(allUsersStartMenu.ToString()));
            pendingDirs.Push(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)));

            IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();

            while (pendingDirs.Count > 0)
            {
                DirectoryInfo dir = pendingDirs.Pop();

                try
                {
                    foreach (FileInfo file in dir.GetFiles("*.lnk"))
                    {
                        var shortcut = shell.CreateShortcut(file.FullName) as IWshRuntimeLibrary.IWshShortcut;
                        if (shortcut != null)
                        {
                            string name       = Path.GetFileNameWithoutExtension(shortcut.FullName);
                            string targetName = Path.GetFileNameWithoutExtension(shortcut.TargetPath);
                            string targetExt  = Path.GetExtension(shortcut.TargetPath);
                            if (targetExt == ".exe" && name.ToLower().IndexOf("uninst") < 0 && targetName.ToLower().IndexOf("uninst") < 0)
                            {
                                var item = new ApplicationListViewItem(name, shortcut.TargetPath, shortcut.Arguments, shortcut.WorkingDirectory);

                                var icon = System.Drawing.Icon.ExtractAssociatedIcon(item.FileName);
                                imageLst.Images.Add(item.FileName, icon);
                                item.ImageKey = item.FileName;

                                items.Add(item);
                            }
                        }
                    }

                    foreach (DirectoryInfo subdir in dir.GetDirectories())
                    {
                        pendingDirs.Push(subdir);
                    }
                }
                catch
                {
                }
            }

            items.Sort();

            suggestItems  = items.ToArray();
            suggestImages = imageLst;

            searchBox.UpdateSuggestions(suggestItems, suggestImages);
        }
示例#4
0
        public int CompareTo(Object obj)
        {
            ApplicationListViewItem other = obj as ApplicationListViewItem;

            return(Text.CompareTo(other.Text));
        }