[Help] Changing Desktop Background

Posts 14 of 4 · Page 1 of 1
[Help] Changing Desktop Background

Is there any other codes for changing the desktop background?

This code haven't worked at me. It turns into a black background.
Code:
Imports System.IO
Imports System****ntime.InteropServices

Public Class DeskTop
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As String, ByVal fuWinIni As Integer) As Long

Private Const SPI_SETDESKTOPWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = 1
Private Const SPIF_SENDWININICHANGE = 2

Private _WallPaperPath As String

Public Property WallPaperPath()
Get
Return _WallPaperPath
End Get
Set(ByVal Value)
_WallPaperPath = Value
End Set
End Property

Public Sub ChangeWallPaper()
If File.Exists(_WallPaperPath) = True Then
SystemParametersInfo(SPI_SETDESKTOPWALLPAPER, 0, _WallPaperPath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
Else
Throw New FileNotFoundException("Specify a valid image path")
End If
End Sub
End Class
Advanced thanks for the persons who can help me.
Sometime ago i saw 1 line of code 2 do that, Idk where

[highlight=vbnet]Class Wallpaper
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = &H1
Dim pic As New PictureBox
Public Sub New(ImagePath as string)
Dim a As New PictureBox
Dim imagePath1 As String = Application.StartupPath & "\myNewWallpaper.bmp"
a.Image = Image.FromFile(ImagePath)
a.Image.Save(imagePath1, ImageFormat.Bmp)
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath1, SPIF_UPDATEINIFILE)
My.Computer.FileSystem.DeleteFile(imagePath1)
End If
End Sub
End Class[/highlight]

This class is working. Created for simplex. Made few changes so you can easily call New method.

Usage:
[highlight=vbnet]Dim WallClass As New WallPaper("C:\SetThisAsWallPaper.jpg")[/highlight]

Tested. It's Working.
Thanks to you two. I'll be saving this.

Edit : But I wonder why it doesn't work on Windows Vista?
Posts 14 of 4 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?