CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2006
    Posts
    1

    Hiding desktop icons

    I am trying to write a small program that will hide the desktop icons. I tried the reg edit thing but you have to restart explorer when you hide/show them. I also tried this. x=0 will show the desktop x!=0 will hide it.

    HWND hw;
    hw = FindWindowEx(0,0,"Progman", NULL);
    ShowWindow(hw, x);

    However this completely disables the desktop (no right click) and i have some trouble with explorer crashing every now and then when i use it. Does anyone know what command is called when you right click on the desktop "Arrange Icons by" --> "Show Desktop Icons"

    Ideally this is the command that i would like to use if it is accessible

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Hiding desktop icons

    Are you attemping to do this in Visual Basic? It looks that way. If so, is it 6 or .Net?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Hiding desktop icons

    It might be best if you use Group Policies to hide desktop icons, drives, or control panel appletts.
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Hiding desktop icons

    Quote Originally Posted by PeejAvery
    Are you attemping to do this in Visual Basic? It looks that way. If so, is it 6 or .Net?
    I'd say it's more Visual C++, because of the ; behind the statements

    All may be well when you eventually hide and show the icons, but isn't it better to allow the user to be able to do this. All system settings IMHO, must be up to the user to decide whether he / she wants to change it.
    Why do you need such a program that does this ¿
    I never could understand why programmers must do this.
    I'm not being funny or anything, but, it's just my opinion.

    Remember also that not every use is an advanced user. Some beginner users might not have a clue of what's going on and why, and of course how to fix it!
    Some users may want their icons to be always displayed, some may not, but it should ultimately be up to the user to decide.

    Just my 2 cents, don't shoot me it's Christmas!
    Last edited by HanneSThEGreaT; December 28th, 2006 at 02:04 AM. Reason: Wrong Code

  5. #5
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Hiding desktop icons

    Could be like I have seen, the client desires a controlled environment (desktop) in a business network. This is where using GPOs is more beneficial then writting any code.

    Ps, looks like C# possibly.
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Hiding desktop icons

    You have to find Progman, then the desktop window and then the listview containing the actual icons. Something like the following in C++:
    Code:
    HWND GetDesktopListViewHWND()
    {
      HWND hDesktopListView = NULL;
      HWND hProgman = FindWindow(_T("Progman"), 0);
      if (hProgman)
      {
        HWND hDesktop = FindWindowEx(hProgman, 0, _T("SHELLDLL_DefView"), 0);
        if (hDesktop)
        {
          hDesktopListView = FindWindowEx(hDesktop, 0, _T("SysListView32"), 0);
        }
      }
    
      return hDesktopListView;
    }
    
    void ShowDesktopIcons(BOOL bShow)
    {
      HWND hWndDesktopListView = GetDesktopListViewHWND();
      ShowWindow(hWndDesktopListView, (bShow?SW_SHOW:SW_HIDE));
    }
    Last edited by Marc G; January 5th, 2012 at 12:19 PM. Reason: Corrected my old code
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Hiding desktop icons

    Quote Originally Posted by Marc G
    You have to find Progman, then the desktop window and then the listview containing the actual icons. Something like the following in C++:
    Code:
    HWND GetDesktopListViewHWND()
    {
      HWND hDesktopListView = NULL;
      HWND hProgman = FindWindow(_T("Progman"), 0);
      if (hProgman)
      {
        HWND hDesktop = FindWindowEx(hProgman, 0, _T("SHELLDLL_DefView"), 0);
        if (hDesktop)
        {
          hDesktopListView = FindWindowEx(hDesktop, 0, _T("SysListView32"), 0);
        }
      }
    
      return hDesktopListView;
    }
    
    void ShowDesktopIcons(BOOL bShow)
    {
      HWND hWndDesktopListView = GetDesktopListViewHWND(&hWndDesktopListView, NULL, NULL);
      ShowWindow(hWndDesktopListView, (bShow?SW_SHOW:SW_HIDE));
    }
    Oh Yes, now I remember....
    The other day, I answered this thread, and when I saw SHELLDLL_DefView and SysListView32 in your post, I remembered it. You are right you have to get the Program, then SHELLDLL_DefView, and then you have access to the icons.

    I also found this on CodeProject :
    http://www.codeproject.com/tips/Tran...35&exp=0&fr=26

    Why am I so forgetful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured