Click here to Skip to main content
Click here to Skip to main content

How to create an automatic Wallpaper Changer with Windows Forms (C++)

, 9 May 2010
Rate this:
Please Sign up or sign in to vote.
How to create an automatic Wallpaper Changer with Windows Forms (C++)

How to create an automatic Wallpaper Changer with Windows Forms (C++)

Download - 239.65 KB


This app changes the desktop wallpaper every three seconds.



Designing apps in Microsoft Visual C++ 2005 Express Edition is pretty straight forward.
Click on the desired component (control) , located at the left toolbar of 
Visual C++ 2005 Express Edition , and draw it at an appropiate locaton on the form.
Components on the form align to rectangular grids,  giving  your apps a symmetric look.


This app uses the following components:

   - command buttons
  - radio buttons
  - horizontal scroll bar
  - groupbox
  - picturebox
  - list box
  - timer
  - labels

Using the code

Altering the wallpaper change mode


Selection of how the app will change desktop wallpapers is
done here. One can either let the app automatically change
wallpapers or one can manually do so by clicking the
'set as wallpaper' button.

Setting the wallpaper change sequence


The sequence of the wallpapers can be randomily done or
sequenced in a foward non-random direction.
The app generates a series of random numbers, stores them
in an array. This is done to assure that numbers arent
repeated as often occurs when using the random function.

Adjusting the wallpaper change time


The default time and max time is set to 30 seconds but can be
reduced down to 2 seconds using the scrollbar.


timer1->Interval=hScrollBar1->Value * 1000;


The program's loop

The core of this app has been placed in Timer1
to make things as simple as can be.

Browsing for wallpapers and   selecting wallpaper folders.


Obviously this app would be useless without this feature. Browsing for
folders containing wallpapers is pretty straightforward. Select the
folder containing the 'bmp files and click the ' ok ' button.

if ( folderBrowserDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
   TargetDirectory = folderBrowserDialog1->SelectedPath;
    MichaelJanssonProcessDirectory(TargetDirectory );
   pictureBox1->Image = Image::FromFile(fileList[ 0]);


The app will list all bmp files found in the directory, in the list box
located to the lower left section of the form.

  maxmichaeljanssonWallpaperChangerFileIndex = listBox1->SelectedIndex ;
  filename= (char*)(void*)Marshal::StringToHGlobalAnsi( fileList[ maxmichaeljanssonWallpaperChangerFileIndex] );
  pictureBox1->Image = Image::FromFile(fileList[ maxmichaeljanssonWallpaperChangerFileIndex]);


Selecting the files is done by clicking the file in question,
a preview of the .bmp file will be rendered in the wapaper preview.


Clicking the ' set as wallpaper ' will set it as wallpaper or
one can click the ' automatic ' radio button to have the app
automatically set the wallpapers.


   if (michaeljanssonWallpaperChangerFileCount>0)
	 filename= (char*)(void*)Marshal::StringToHGlobalAnsi( fileList[ maxmichaeljanssonWallpaperChangerFileIndex] );

Setting the wallpaper

 [DllImport("USER32.DLL",EntryPoint="SystemParametersInfo", CharSet = CharSet::Ansi, SetLastError = true)]
static int SystemParametersInfo(int uAction, int uParam,  wchar_t*  lpvParam,   int fuWinIni);
static void setWallpaper(char *   path)

	  result =  SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (wchar_t*) path , SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );


when all said and done
(when the code is built)


Download - 239.65 KB


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .
I hold lectures in programming. I have also coached students in C++, Java and Visual basic.
In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

Comments and Discussions

GeneralMy vote of 5 Pinmembermokhi648-Oct-11 20:10 
GeneralMy vote of 1 PinmemberPogoboyMtK14-May-10 8:33 
GeneralMy vote of 1 PinmemberSledgeHammer018-May-10 17:40 
Generallook of this tips Pinmembere_ilite17-Sep-08 3:56 
GeneralRe: look of this tips PinmemberDj Rush30-Mar-09 21:49 
Thanks for the tip.
Yes, Iam in the process of updating it so that it does JPG, GIF or whatever and not just BMP files. or i could have it convert to BMP internally before it sets the wallpaper

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 9 May 2010
Article Copyright 2008 by Software_Developer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid