Page 1 of 1

How to make a Wallpaper Changer

Posted: Tue Dec 07, 2010 5:19 pm
by Usman55
Hello everyone,

As I said before while posting my Wallpaper Changer application that I will post a tutorial, I am posting it now. What you will learn in this tutorial is how to change the Desktop's wallpaper by using an application. Its pretty simple and short-length coding. So the tutorial will just as easy to follow. Please don't post any type of negative comments.

---------------------------------------------------------------------------

First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Wallpaper Changer and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.


First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Wallpaper Changer. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False.


Now add the following things to the form:

(1)_ 1 PictureBox. Change it's SizeMode property to StretchImage. Change it's BorderStyle property to FixedSingle.

(2)_ 2 Buttons. Change Button1's Text property to Browse... and Button2's Text property to Set Wallpaper.


Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.

Type the following code before Public Class Form1:
Code: Select all
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Type the following code after Public Class Form1:
Code: Select all
Inherits System.Windows.Forms.Form
    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
Write the following code by double-clicking Button1 whose Text property was Browse...:
Code: Select all
Dim dlg As OpenFileDialog = New OpenFileDialog
        dlg.Filter = "Image Files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png"
        dlg.Title = "Select the image to load."
        dlg.ShowDialog()
        PictureBox1.Image = Image.FromFile(dlg.FileName)
        dlg.Dispose()
Write the following code by double-clicking Button2 whose Text property was Set Wallpaper:
Code: Select all
Dim imagePath As String = Application.StartupPath & "\New Wallpaper.bmp"
        PictureBox1.Image.Save(imagePath, ImageFormat.Bmp)
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)
Well, that's all. It was real easy, wasn't it?

---------------------------------------------------------------------------

Voila! You have just completed making a Wallpaper Changer which sets the wallpaper of your desktop with the image that you choose. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.

And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.

Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making an Icon Extractor project myself so you can download the source file in the attachments.

Thank you.

Image

Re: How to make a Wallpaper Changer

Posted: Sat Dec 18, 2010 9:16 pm
by iLenkaa
Nice tut! :')
I have a little question.
How can I make it change the wallpaper to a wallpaper in :C\ which I chose.
Hope you can help me! :')

Re: How to make a Wallpaper Changer

Posted: Sun Dec 19, 2010 12:16 am
by mandai
Try:
Code: Select all

    Const SPI_SETDESKWALLPAPER As UInteger = &H14
    Const SPIF_UPDATEINIFILE As UInteger = &H1

    <DllImport("user32.dll")> Shared Function SystemParametersInfo(ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByVal pvParam As String, ByVal fWinIni As UInteger) As Boolean
    End Function

    Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click

         ' Where txtWallpaper is a textbox containing something like C:\test.bmp
        SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, txtWallpaper.Text, SPIF_UPDATEINIFILE)

    End Sub

Re: How to make a Wallpaper Changer

Posted: Sun Dec 19, 2010 5:34 am
by Usman55
iLenkaa wrote:
Nice tut! :')
I have a little question.
How can I make it change the wallpaper to a wallpaper in :C\ which I chose.
Hope you can help me! :')
That is not at all difficult. Didn't you saw the Browse button? And yes, you can also do it in mandai's way.

Re: How to make a Wallpaper Changer

Posted: Sun Dec 19, 2010 4:19 pm
by Danny
I've created a wallpaper changer and it chnage a wallpaper on every 10 min =D

Re: How to make a Wallpaper Changer

Posted: Sun Dec 19, 2010 5:34 pm
by Usman55
I have seen it, and it isn't difficult. You just have to put the change wallpaper button code into a timer with some change of code.

Re: How to make a Wallpaper Changer

Posted: Mon Dec 20, 2010 12:12 pm
by Danny
Usman55 wrote:
I have seen it, and it isn't difficult. You just have to put the change wallpaper button code into a timer with some change of code.
true (A)