• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

[C#] Desktophintergrund ändern

derwunner

Mitglied
Hallo,
ich wollte mir neulich ein Programm schreiben, dass den Desktop animiert. Dazu hatte ich leider nichts gefunden, also fing ich erstmal nur mit Bildern an. Dazu hatte ich einen interessanten Beitrag vom MSDN Blog gefunden. Nur leider funktioniert das so nicht. Habe ich vill irgendwo eine Pfadangabe vergessen, oder woran liegt es?
Hier der Source-Code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace desktophintergrund
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }

    public class Wallpaper
    {
        const int SPI_SETDESKWALLPAPER = 20;
        const int SPIF_UPDATEINIFILE = 0x01;
        const int SPIF_SENDWININICHANGE = 0x02;

        public Wallpaper()
        {
        }

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int SystemParametersInfo(
            int uAction, int uParam, string lpvParam, int fuWinIni);

        public enum Style : int
        {
            Tiled, Centered, Stretched
        }

        public void SetWallpaper(string path, Style style)
        {
            if (System.IO.File.Exists(@"G:\test2.jpeg"))
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);

                switch (style)
                {
                    case Style.Stretched:
                        key.SetValue(@"WallpaperStyle", "2");
                        key.SetValue(@"TileWallpaper", "0");
                        break;
                    case Style.Centered:
                        key.SetValue(@"WallpaperStyle", "1");
                        key.SetValue(@"TileWallpaper", "0");
                        break;
                    case Style.Tiled:
                        key.SetValue(@"WallpaperStyle", "1");
                        key.SetValue(@"TileWallpaper", "1");
                        break;
                }
                SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
            }
            else
            {
                throw new System.IO.FileNotFoundException();
            }
        }
    }
}


MFG derwunner
 
Werbung:
Müsstest du die extra klasse nicht mit dem Hauptklasse bekannt machen.
Meiner Meinung nach, springt das programm in die Main und die ist halt leer
 
Zurück
Oben