[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to change wallpaper on desktop using Visual Basic .NET?

Posted on 2008-10-13
3
Medium Priority
?
1,006 Views
Last Modified: 2008-10-14
I found the following code on website:  http://www.dotnetspider.com/resources/19517-Change-Desktop-Wallpaper-using-VB-NET.aspx but its not working....

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
  'constants to be used with the above api

  Private Const SPI_SETDESKWALLPAPER = 20
  Private Const SPIF_UPDATEINIFILE = &H1

Private Sub SetWallpaper()

    Dim imagePath As String = "C:\_Stephens Files\Personal\Pictures\Comic\wolverine.JPG"
    'set the parameters to change the wallpaper to the image you selected  
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)

  End Sub

I know API is the way to go with Visual Basic.NET but what do I need to do in addition to the above to change my desktop wallpaper to something else?

I ALSO NEED CODE TO BE SURE THE PICTURE has the option to be stretched, tile or centered!
0
Comment
Question by:stephenlecomptejr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 2000 total points
ID: 22708909
check the code below.. I assume you are not on network PC.
 

Imports System.Runtime.InteropServices
 
'setting the desktop wallpaper: 
    
    Private Shared SPI_SETDESKWALLPAPER As UInt32 = 20
    
    Private Shared SPIF_UPDATEINIFILE As UInt32 = 1
    
    Private Shared SPIF_SENDWININICHANGE As UInt32 = 2
    
    Private Declare Function SystemParametersInfo Lib "user32.dll" (ByVal action As UInt32, ByVal uParam As UInt32, ByVal vParam As String, ByVal winIni As UInt32) As Int32
    
    Public Sub SetWallpaper(ByVal path As String)
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, (SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE))
    End Sub
 
' detect when wallpaper changes
Imports System.Windows.Forms
Public Class MyApp
    Inherits Form
    
    Private Shared SPI_SETDESKWALLPAPER As UInt32 = 20
    
    Private Shared WM_SETTINGCHANGE As UInt32 = 26
    
    Protected Overrides Sub WndProc(ByRef message As Message)
        If (message.Msg = WM_SETTINGCHANGE) Then
            If (message.WParam.ToInt32 = SPI_SETDESKWALLPAPER) Then
                ' Handle that wallpaper has been changed.
            End If
        End If
        MyBase.WndProc(message)
    End Sub
End Class

Open in new window

0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 22712453
Yes.  I am not on a network PC.

No errors but no change on desktop wallpaper though....

I put all the code that followed the statement  ' detect when wallpaper changes in a separate class module called MyApp.vb.
Was that correct?

0
 
LVL 1

Author Comment

by:stephenlecomptejr
ID: 22713325
This was a big help as well..
http://blogs.msdn.com/coding4fun/archive/2006/10/31/912569.aspx

My problem was that I trying to assign a .jpg file instead of a .bmp file....
Now it works.

Thank you SameerJagdale:
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question