C#隐藏桌面图标

private void ShowDeskIcon(bool b)//控制桌面图标显隐
{             
  IntPtr desk = FindWindow("ProgMan", null);//获取桌面句柄
  IntPtr list_ = FindWindowEx(desk, 0, "SHELLDLL_DefView", null);//获取上级句柄
  IntPtr Idesk = FindWindowEx(list_, 0, "SysListView32", "FolderView"); //获取桌面 
 
  //图标列表句柄,list_为上级父句柄值,用 精易编程助手 查询          
  int value = 0;
  if (b == true)
  {
     value = 5;
   }
  ShowWindow(Idesk, value);  //value=5时显示,value=0时隐藏
} 

 

出处:https://blog.csdn.net/qq_24125575/article/details/73188166

==============================================================

我自己做测试的时候,使用上面的代码在win10上测试不成功,使用Spy++查看句柄如下:

C#隐藏桌面图标

 

 

修改如下:

int b = 0;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
        
            b++;

            // 遍历*窗口
            Win32Func.EnumWindows((hwnd, lParam) =>
            {
                // 找到第一个 WorkerW 窗口,此窗口中有子窗口 SHELLDLL_DefView,所以先找子窗口
                var shellDll = Win32Func.FindWindowEx(hwnd, IntPtr.Zero, "SHELLDLL_DefView", null);
                if (shellDll != IntPtr.Zero)
                {
                    // 找到当前第一个 WorkerW 窗口的,后一个窗口,及第二个 WorkerW 窗口。
                    //IntPtr tempHwnd = Win32Func.FindWindowEx(IntPtr.Zero, hwnd, "WorkerW", null);

                    IntPtr Idesk1 = Win32Func.FindWindowEx(shellDll, IntPtr.Zero, "SysListView32", "FolderView"); //获取桌面 


                    //Win32Func.ShowWindow(Idesk, b % 5);  //value=5时显示,value=0时隐藏
                    Win32Func.ShowWindow(Idesk1, (b % 2 == 0 ? 0 : 5));  //value=5时显示,value=0时隐藏
                }
                return true;
            }, IntPtr.Zero);

        }

 

上一篇:Remote desktop to Ubuntu 12.04 from Windows 7


下一篇:Winform中node.Text重命名时窗口无响应假死的解决方法