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

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.

Comments and Discussions

 
GeneralMy vote of 5 Pinmembermokhi648-Oct-11 20:10 
This Was Exactly What I Wanted
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 

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.140721.1 | Last Updated 9 May 2010
Article Copyright 2008 by Software_Developer
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid