2009-05-17 9 views

Répondre

3

Il y a aussi un exemple de code en C# et VB here. En plus d'appeler SystemParametersInfo, il définit également les clés reg pour tile et style.

1

trouvé ce (vb) Code sur le 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 

Appelé comme:

SetWallpaper (Me.PictureBox1.Image) 
Questions connexes