是否可以用 C# 隐藏特定的桌面图标?

发布于 2024-08-21 17:47:37 字数 141 浏览 5 评论 0原文

我正在寻找一种从桌面隐藏特定图标的方法。我的桌面上通常有很多图标(这使得查找文件变得很麻烦),所以我想编写一个小工具,在我键入时“过滤”它们。我不想“移动”或删除它们,只是隐藏(或变暗)它们。我知道如何一次切换显示所有图标的隐藏状态,但不是基于每个图标。有什么想法吗?

I'm searching for a way to hide specific Icons from the Desktop. I usually have way to much icons on my desktop (which makes finding a file a real hassle), so I would like to write a little tool, which "filters" them as I type. I do not want to "move" or delete them, just hide (or darken) them. I know how to toggle show an hide-status of all icons at once, but not on a per icon basis. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的新欢旧爱 2024-08-28 17:47:37

我会尝试以某种方式导航到桌面的 ListView 控件(使用 Win32 API)。然后我要么在我想要隐藏的项目上绘制一些半透明矩形(您可以使用 ListItem_GetItemRect 宏/消息查询项目的矩形),从列表控件中临时删除项目,设置项目的状态为 CUT (淡出),或者我尝试操作列表视图的图像列表以添加透明图像并将项目的图像设置为此。

但我不知道这种方法是否有效......而且我不确定是否会在 C# 中尝试这个(我宁愿使用 C++)。

I'd try to somehow navigate to the desktop's ListView control (using Win32 API). Then I'd either draw some semi-transparent rectangles over the items I want to hide (you can query the rectangles of items using the ListItem_GetItemRect macro/message), remove items temporaryly from the list control, set the status of the items to CUT (which fades the out) or I'd try manipulate the list view's image list to add a transparent image and set the item's images to this.

But I have no idea if this approach would work ... And I'm not sure if I'd try this in C# (I'd rather use C++).

送君千里 2024-08-28 17:47:37

@crono,我认为您最好的选择是添加对 COM 库“Microsoft Shell Control And Automation”的引用并使用 Shell32.Shell 对象。然后枚举快捷方式并设置快捷方式的文件属性(FileAttributes.Hidden)。

检查这些链接以获取更多信息。

看这个简单的例子,并不完整,只是一个草稿。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Shell32; //"Microsoft Shell Control And Automation"

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Shell32.Shell oShell;
                Shell32.Folder oFldr;
                oShell = new Shell32.Shell();
                oFldr = oShell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDESKTOP);//point to the desktop

                foreach ( Shell32.FolderItem oFItm in oFldr.Items()) //get the shotrcuts
                {

                    if (oFItm.IsLink)
                    {
                        Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);

                        bool isArchive = ((File.GetAttributes(oFItm.Path) & FileAttributes.Archive) == FileAttributes.Archive);
                        //bool isHidden = ((File.GetAttributes(oFItm.Path) & FileAttributes.Hidden) == FileAttributes.Hidden);

                        if (isArchive) //Warning, here you must define the condition for hide the shortcut. in this case only check if has set the Archive atribute. 
                        {

                            //Now you can set  FileAttributes.Hidden atribute
                            //File.SetAttributes(oFItm.Path, File.GetAttributes(oFItm.Path) | FileAttributes.Hidden);
                        }

                    }
                    else
                    {
                        Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);
                    }

                }

                Console.ReadKey();
            }
        }
    }

@crono, I think wich your best option is add a reference to the COM library "Microsoft Shell Control And Automation" and use the Shell32.Shell object. and then enumerate the shortcuts and set the file atributes (FileAttributes.Hidden) of the shortcuts.

check these links for more info.

see this simple example, is not complete, is just a draft.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Shell32; //"Microsoft Shell Control And Automation"

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Shell32.Shell oShell;
                Shell32.Folder oFldr;
                oShell = new Shell32.Shell();
                oFldr = oShell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDESKTOP);//point to the desktop

                foreach ( Shell32.FolderItem oFItm in oFldr.Items()) //get the shotrcuts
                {

                    if (oFItm.IsLink)
                    {
                        Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);

                        bool isArchive = ((File.GetAttributes(oFItm.Path) & FileAttributes.Archive) == FileAttributes.Archive);
                        //bool isHidden = ((File.GetAttributes(oFItm.Path) & FileAttributes.Hidden) == FileAttributes.Hidden);

                        if (isArchive) //Warning, here you must define the condition for hide the shortcut. in this case only check if has set the Archive atribute. 
                        {

                            //Now you can set  FileAttributes.Hidden atribute
                            //File.SetAttributes(oFItm.Path, File.GetAttributes(oFItm.Path) | FileAttributes.Hidden);
                        }

                    }
                    else
                    {
                        Console.WriteLine("{0} {1} ", oFItm.Name, oFItm.Path);
                    }

                }

                Console.ReadKey();
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文