well i made this program for my little brother as he didnt want to go to the site every time there was a new wallpaper that came out
so i thought that i would write it up and show it to you so you can create one for yourself
so here is the code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConsoleApplication1
{
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
static void Main(string[] args)
{
bool FileIsThere;
string TheURL = "http://www.foxkeh.com/downloads/wallpapers/";
DateTime dt = DateTime.Now;
int TheYear = dt.Year;
int TheMonth = dt.Month;
string TheDate = TheYear.ToString();
if (TheMonth < 10)
TheDate += "0";
TheDate += TheMonth.ToString();
TheURL += TheDate + "/1280x1024_cal_universal_sun.png";
WebRequest request = WebRequest.Create(new Uri(TheURL));
request.Method = "HEAD";
WebResponse response;
try
{
response = request.GetResponse();
FileIsThere = true;
}
catch (Exception)
{
FileIsThere = false;
}
if (!System.IO.Directory.Exists(@"C:\\foxkeh"))
System.IO.Directory.CreateDirectory(@"C:\\foxkeh");
if (FileIsThere)
{
WebClient Client = new WebClient();
Client.DownloadFile(TheURL, "C:/foxkeh/image.png");
if (File.Exists("C:\\foxkeh\\image.png"))
{
Image Dummy = Image.FromFile("C:\\foxkeh\\image.png");
Dummy.Save("C:\\foxkeh\\image.bmp", ImageFormat.Bmp);
SystemParametersInfo(20, 0, "C:/foxkeh/image.bmp", 0x1 | 0x2);
}
}
}
}
}
now this is mostly self explanatry
first you have to import all the thing that are needed in order to run the program
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
then you have to start the program by writing the following
we will also import the user32.dll at the same time
Code:
namespace ConsoleApplication1
{
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
static void Main(string[] args)
{
then we will declare the variables that are needed and set them
Code:
bool FileIsThere;
string TheURL = "http://www.foxkeh.com/downloads/wallpapers/";
DateTime dt = DateTime.Now;
int TheYear = dt.Year;
int TheMonth = dt.Month;
string TheDate = TheYear.ToString();
if (TheMonth < 10)
TheDate += "0";
TheDate += TheMonth.ToString();
TheURL += TheDate + "/1280x1024_cal_universal_sun.png";
in this you are creating a boolean which is called FileIsThere, we will use this to see if the new updated image is there or not
we then have a string which will then hold the web address, but because we want to add the date in, we havent put the whole address in, so so far is is set to http://www.foxkeh.com/downloads/wallpapers/
then we create a DateTime called dt, this will hold both the date and the time that your computer is currently set to
The Year and The Month are both integers, and as you can probably guess they will hold the year and the month
now we will convert TheYear into a string and store it in the variable called The Date
then it will check if The Month is less than 10, if it is then it will add a 0 to TheDate so that if the month is 3 then it will put 03 into the address instead of 3
after that it will change TheMonth to a string and add it to TheDate
then it will add TheDate to TheURL, which is the address that it should get the image from, so it is now http://www.foxkeh.com/downloads/wallpapers/200908
then it will add the last of the address onto TheURL, so it is now http://www.foxkeh.com/downloads/wall...versal_sun.png
now the next chunk of code
Code:
WebRequest request = WebRequest.Create(new Uri(TheURL));
request.Method = "HEAD";
WebResponse response;
here we create a WebRequest called request and a WebResponse called response
Code:
try
{
response = request.GetResponse();
FileIsThere = true;
}
catch (Exception)
{
FileIsThere = false;
}
firstly it will try to see if there is something at the address that has been provided, and if there is then it will set FileIsThere to true, otherwise it will set it to False
Code:
if (!System.IO.Directory.Exists(@"C:\\foxkeh"))
System.IO.Directory.CreateDirectory(@"C:\\foxkeh");
this will check if the directory "C:/foxkeh" exists, if it doesnt then it will create it
now if FileIsThere is True then it will continue on with the next bit of code
Code:
WebClient Client = new WebClient();
Client.DownloadFile(TheURL, "C:/foxkeh/image.png");
this will create a WebClient so that we can download the file that we want to set to the desktop background, then it will download it to "C:/foxkeh/image.png"
Code:
if (File.Exists("C:\\foxkeh\\image.png"))
{
now we will check if the file we just downloaded is there
Code:
Image Dummy = Image.FromFile("C:\\foxkeh\\image.png");
Dummy.Save("C:\\foxkeh\\image.bmp", ImageFormat.Bmp);
now this will create a Image and load foxkeh.png into it and then save it as image.bmp, because you cannot set a png as the desktop background
Code:
SystemParametersInfo(20, 0, "C:/foxkeh/image.bmp", 0x1 | 0x2);
this line sets image.bmp as the desktop background
these just close off all the open brackets
now as you have probably guessed im not very good at writing tutorials...
~shut