C# 隐藏显示桌面图标

 

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
 
namespace HSDesktopIcon
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //定位注册表项
            RegistryKey RKey=Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel");
            if (checkBox1.Checked)
                RKey.SetValue("{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 1);//隐藏我的电脑
            if (checkBox2.Checked)
                RKey.SetValue("{59031a47-3f72-44a7-89c5-5595fe6b30ee}", 1);//隐藏我的文档
            if (checkBox3.Checked)
                RKey.SetValue("{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}", 1);//隐藏网上邻居
            if (checkBox4.Checked)
                RKey.SetValue("{645FF040-5081-101B-9F08-00AA002F954E}", 1);//隐藏回收站
            if (checkBox5.Checked)
                RKey.SetValue("{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", 1);//隐藏控制面板
            MessageBox.Show("修改成功——请刷新桌面!");
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //定位注册表项
            RegistryKey RKey = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\HideDesktopIcons\\NewStartPanel");
            if (checkBox1.Checked)
                RKey.SetValue("{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0);//显示我的电脑
            if (checkBox2.Checked)
                RKey.SetValue("{59031a47-3f72-44a7-89c5-5595fe6b30ee}", 0);//显示我的文档
            if (checkBox3.Checked)
                RKey.SetValue("{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}", 0);//显示网上邻居
            if (checkBox4.Checked)
                RKey.SetValue("{645FF040-5081-101B-9F08-00AA002F954E}", 0);//显示回收站
            if (checkBox5.Checked)
                RKey.SetValue("{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", 0);//显示控制面板
            MessageBox.Show("修改成功——请刷新桌面!");
        }
    }
}

 

 

C# 刷新桌面

public class DesktopRefurbish
{
    [DllImport("shell32.dll")]
    public static extern void SHChangeNotify(HChangeNotifyEventID wEventId, HChangeNotifyFlags uFlags, IntPtr dwItem1, IntPtr dwItem2);
/// <summary> /// 桌面刷新 /// </summary> public static void DeskRefresh() { SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero); } } #region public enum HChangeNotifyFlags [Flags] public enum HChangeNotifyFlags { SHCNF_DWORD = 0x0003, SHCNF_IDLIST = 0x0000, SHCNF_PATHA = 0x0001, SHCNF_PATHW = 0x0005, SHCNF_PRINTERA = 0x0002, SHCNF_PRINTERW = 0x0006, SHCNF_FLUSH = 0x1000, SHCNF_FLUSHNOWAIT = 0x2000 } #endregion//enum HChangeNotifyFlags #region enum HChangeNotifyEventID [Flags] public enum HChangeNotifyEventID { SHCNE_ALLEVENTS = 0x7FFFFFFF, SHCNE_ASSOCCHANGED = 0x08000000, SHCNE_ATTRIBUTES = 0x00000800, SHCNE_CREATE = 0x00000002, SHCNE_DELETE = 0x00000004, SHCNE_DRIVEADD = 0x00000100, SHCNE_DRIVEADDGUI = 0x00010000, SHCNE_DRIVEREMOVED = 0x00000080, SHCNE_EXTENDED_EVENT = 0x04000000, SHCNE_FREESPACE = 0x00040000, SHCNE_MEDIAINSERTED = 0x00000020, SHCNE_MEDIAREMOVED = 0x00000040, SHCNE_MKDIR = 0x00000008, SHCNE_NETSHARE = 0x00000200, SHCNE_NETUNSHARE = 0x00000400, SHCNE_RENAMEFOLDER = 0x00020000, SHCNE_RENAMEITEM = 0x00000001, SHCNE_RMDIR = 0x00000010, SHCNE_SERVERDISCONNECT = 0x00004000, SHCNE_UPDATEDIR = 0x00001000, SHCNE_UPDATEIMAGE = 0x00008000, } #endregion

 

 

引用

C# 隐藏显示桌面图标 实例源码(win7/win8/win10可用)

posted @ 2019-10-11 14:29  quanzhan  阅读(1237)  评论(0编辑  收藏  举报