views:

285

answers:

2

Hi,

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?

+3  A: 

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++).

MartinStettner
I really like the rectangle idea! I will try this as well. I think I will stay in .Net, my Win32 C++ experience is almost zero.
crono
+3  A: 

@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();
            }
        }
    }
RRUZ
This is a good idea, but I think it would only work, if I set "display hidden files" to "false" - which I have "on" most of the time. Maybe I could change it "on the fly"... I will hav a look. Thanks :)
crono