Saturday, July 24, 2010

Fun App: Take a Screenshot of the Desktop as Wallpaper and Delete all Items - Reverse

So, here the code to reverse the effects done by the program of the last post:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll")]
        private static extern int FindWindow(string className, string windowText);

        [DllImport("user32.dll")]
        private static extern int ShowWindow(int hwnd, int command);

        private void Form1_Load(object sender, EventArgs e)
        {
            // show taskbar
            int hwnd = FindWindow("Shell_TrayWnd""");
            ShowWindow(hwnd, 1);
       
            string BackupDirectory = @"C:\backupdesktopfun\";

            DirectoryInfo ds = new DirectoryInfo(BackupDirectory);

            string DesktopDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";

            // recover all files and folders again

            foreach (FileInfo f in ds.GetFiles())
            {
                if (!File.Exists(DesktopDirectory + f.Name))
                    f.MoveTo(DesktopDirectory + f.Name);
            }

            foreach (DirectoryInfo d in ds.GetDirectories())
            {
                if (!Directory.Exists(DesktopDirectory + d.Name))
                    d.MoveTo(DesktopDirectory + d.Name);
            }

            Application.Exit();
        }
    }

No comments:

Post a Comment