views:

439

answers:

2

Hi,

I would like to write a small Windows application which changes the desktop wallpaper based on photographs retrieved from a web service ? How should I go about this ? Which language / technology would this be the quickest to code in ?

A: 

Found this (vb) code on the net:

Private Const SPI_SETDESKWALLPAPER As Integer = &H14
Private Const SPIF_UPDATEINIFILE As Integer = &H1
Private Const SPIF_SENDWININICHANGE As Integer = &H2
Private Declare Auto Function SystemParametersInfo Lib "user32.dll" (ByVal uAction As Integer,_
 ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer


' change this to whatever filename you want to use'
Const WallpaperFile As String = "MovieCollectionImage.bmp"

''' <summary>
''' Sets the background of your Windows desktop. The image will be saved in MyPictures_
 and the background wallpaper updated.
''' </summary>
''' <param name="img">The image to be set as the background.</param>
''' <remarks></remarks>
Friend Sub SetWallpaper(ByVal img As Image)
     Dim imageLocation As String
     imageLocation = My.Computer.FileSystem.CombinePath_
(My.Computer.FileSystem.SpecialDirectories.MyPictures, WallpaperFile)
     Try
          img.Save(imageLocation, System.Drawing.Imaging.ImageFormat.Bmp)
          SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imageLocation,_
 SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
     Catch Ex As Exception
          MsgBox("There was an error setting the wallpaper: " & Ex.Message)
     End Try
End Sub

Called like:

SetWallpaper (Me.PictureBox1.Image)
hypoxide
+1  A: 

There is also sample code in C# and VB here. In addition to calling SystemParametersInfo, it also sets the reg keys for tile and style.

ratchetr