change desktop wallpaper c# -
this question has answer here:
i want create program saves bmp image file on driver , sets image wallpaper. code managed write saves image in correct place image doesn't appear wallpaper. please help...
class program { [dllimport("user32.dll", charset = charset.auto)] private static extern int32 systemparametersinfo(uint32 uiaction, uint32 uiparam,string pvparam, uint32 fwinini); private static uint32 spi_setdeskwallpaper = 20; private static uint32 spif_updateinifile = 0x1; private string imagefilename = "d:\\wall.bmp"; static void main(string[] args) { bitmap bmp = new bitmap(properties.resources.wall); bmp.save("d:\\wall.bmp"); systemparametersinfo(spi_setdeskwallpaper, 0, "d:\\wall.bmp", spif_updateinifile); } }
you can try class written here :
public sealed class wallpaper { wallpaper() { } const int spi_setdeskwallpaper = 20; const int spif_updateinifile = 0x01; const int spif_sendwininichange = 0x02; [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 static void set(uri uri, style style) { system.io.stream s = new system.net.webclient().openread(uri.tostring()); system.drawing.image img = system.drawing.image.fromstream(s); string temppath = path.combine(path.gettemppath(), "wallpaper.bmp"); img.save(temppath, system.drawing.imaging.imageformat.bmp); registrykey key = registry.currentuser.opensubkey(@"control panel\desktop", true); if (style == style.stretched) { key.setvalue(@"wallpaperstyle", 2.tostring()); key.setvalue(@"tilewallpaper", 0.tostring()); } if (style == style.centered) { key.setvalue(@"wallpaperstyle", 1.tostring()); key.setvalue(@"tilewallpaper", 0.tostring()); } if (style == style.tiled) { key.setvalue(@"wallpaperstyle", 1.tostring()); key.setvalue(@"tilewallpaper", 1.tostring()); } systemparametersinfo(spi_setdeskwallpaper, 0, temppath, spif_updateinifile | spif_sendwininichange); } }
good luck!
Comments
Post a Comment