2010-02-19 42 views
4

我正在寻找一种方法来隐藏桌面上的特定图标。我通常在桌面上有很多图标(这使得找到一个文件非常麻烦),所以我想写一个小工具,在我输入时“过滤”它们。我不想“移动”或删除它们,只是隐藏(或加深)它们。我知道如何一次切换显示所有图标的隐藏状态,但不是基于每个图标。有任何想法吗?是否可以用C#隐藏特定的桌面图标?

+1

如果你把这个应用程序,将其发送给我吧:) – anthares 2010-02-19 01:01:01

+0

当然 - 没问题,我会打开源它反正:-) – crono 2010-02-19 01:04:10

回答

3

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

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

+0

我真的很喜欢这个矩形的想法!我也会尝试这个。我想我会留在.NET中,我的Win32 C++经验几乎为零。 – crono 2010-02-20 16:05:15

3

@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(); 
      } 
     } 
    } 
+0

这是一个好主意,但是我认为只有在将“显示隐藏文件”设置为“false”的情况下才能正常工作,而我大部分时间都是这样做的。也许我可以改变它“在飞行中”...我会看看。谢谢 :) – crono 2010-02-20 15:59:24

相关问题