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++)

By , 9 May 2010
 



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


Download mj_wallpaperchanger.zip - 239.65 KB

Introduction

This app changes the desktop wallpaper every three seconds.


00vcexpress.jpg

Background


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.

Components

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

05chngmode.jpg


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



06chngsqnc.jpg


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


 
10timer.jpg



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




07chngfrqncy.jpg

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.



03browse.jpg


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]);
   listBox1->SetSelected(0,true);

}



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]);




08filelist.jpg


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

04preview.jpg

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.

09setbutton.jpg


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



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)

02app.jpg







Download mj_wallpaperchanger.zip - 239.65 KB


License

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

About the Author

Clark Kent SuperCoder
Sweden Sweden
Member
About me:
I attended programming School and I have a degree in three 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've gotten paid to teach coding. I am roughly 20 years old and i have been a teacher's assistant in programming ,
i have held a lecture in Visual basic 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 about a dozen small simple applications and games.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5membermokhi648 Oct '11 - 20:10 
This Was Exactly What I Wanted
GeneralMy vote of 1memberPogoboyMtK14 May '10 - 8:33 
All I can say is Wow! The words I would really like to use would not be appropriate for a public setting like this.
GeneralMy vote of 1memberSledgeHammer018 May '10 - 17:40 
Please stop "coaching" people in programming. This is just really bad code.
Generallook of this tipsmembere_ilite17 Sep '08 - 3:56 
http://bbs.aisnote.com/coms/blogs/aisnote/archive/2008/07/18/set-desktop-wallpaper-using-non-bitmap-in-win32-c.aspx[^]
GeneralRe: look of this tipsmemberDj 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   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 9 May 2010
Article Copyright 2008 by Clark Kent SuperCoder
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid