How toset desktop wallpaper in VB.net?

Johnny5

Newcomer
Joined
Aug 23, 2003
Messages
6
Please, if you know how to set the desktop wallpaper by VB.net code so tell me how.
tHIS CODE don't work (I don't know why)::mad:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As String, ByVal fuWinIni As Long) As Long
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1



SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "John5.bmp", SPIF_UPDATEINIFILE)

Thank you. :)
 
you really need to use Integers rather than Longs , eg:
Visual Basic:
    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 As Integer = 20
    Private Const SPIF_UPDATEINIFILE As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim od As New OpenFileDialog()
        With od
            .Filter = "Bitmaps(*.bmp)|*.bmp" '/// only seems to work on bitmaps ( atleast on XP pro here )
            .InitialDirectory = "C:\"
        End With
        If od.ShowDialog = DialogResult.OK Then
            If MessageBox.Show("would you like the changes to remain next time you re-boot", Application.ProductName, MessageBoxButtons.YesNo) = DialogResult.OK Then
                SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, od.FileName, SPIF_UPDATEINIFILE)
            Else '/// dont save changes for after reboot.
                SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, od.FileName, 0)
            End If
        End If
    End Sub
 
Back
Top