views:

809

answers:

1

Im making a simple wallpaper changer. It works when changing the wallpaper but i cant change the pattern of the wallpaper. I tried something like this but it doesnt work :S

SystemParametersInfo(SPI_SETDESKPATTERN, 0, "Center",
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

Can some1 please show me the proper way of setting the wallpaper pattern?

+2  A: 

I assume you mean the centred/ streched / tiled setting that would be the second past value int 1-3

[DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni);
        private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
        private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01;
        private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02;

        private void SetWallpaper(string path)
        {
            if (File.Exists(path))
            {
                Image imgInFile = Image.FromFile(path);
                try
                {
                    imgInFile.Save(SaveFile, ImageFormat.Bmp);
                    SystemParametersInfo(SPI_SETDESKWALLPAPER, 3, SaveFile, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
                }
                catch
                {
                    MessageBox.Show("error in setting the wallpaper");
                }
                finally
                {
                    imgInFile.Dispose();
                }
            }
        }
Crash893
does this convert any image to a bmp? My solution about the tiled etc. thing was to edit the registry. is this way more efficient?
Ozzy
I don't know how your way works so i couldn't say, I do know this works pretty well.I have another method to save files as a temporary bmp.
Crash893
It appears i misspoke i do the transfer in this method with the imgInFile object
Crash893