Introduction
This code sets the background at the specified folder.
Background
Earlier, the user did not have any user interactive/friendly interface. The user could interact with the OS through DOS or any type of command prompt that then became interfaces for interacting with the OS and other applications. Then the user wanted to set different backgrounds at the desktop but user may have also wanted to set the background at many other places, for example at the background of any folder. Now, the user can fulfill his/her desire through different software.
Using the Code
Before going to the code, I want to explain the manual procedure which the code performs during execution.
Select the folder you want to use for your background wallpaper. You MUST convert the folder you want to use to a SYSTEM folder. At the command prompt screen (Start/Run/CMD) which looks something like this: c:\>, type this command: attrib +s c:\myfolder
and then hit the return key.
Copy and paste the script below into Notepad and change the line that says IconArea_Image
to point to the directory and the file that you want to use for the background image.
[ExtShellFolderViews]
{BE098140-A513-11D0-A3A4-00C04FD706EC}={BE098140-A513-11D0-A3A4-00C04FD706EC}
[{BE098140-A513-11D0-A3A4-00C04FD706EC}]
Attributes=1
IconArea_Image=C:\YOUR LOCATION\OF\ANY\IMAGE.JPG
IconArea_Text=0x00000000
The last line in the script tells Windows what color the font will be when you read the files in that folder. For instance:
0x00000000 = black
0x00FF0000 = blue
0x0000FF00 = green
0x000000FF = red
0x00C000C0 = purple
Save the file you just created as desktop.ini and place it into the directory you just converted into a system folder.
Now close that folder and then reopen.
Let's see how the code performs the above procedure automatically:
private void folderpbtn_Click(object sender, EventArgs e)
{
FolderBrowserDialog openFolder = new FolderBrowserDialog();
if (openFolder.ShowDialog() == DialogResult.OK)
{
if ((folderpath = openFolder.SelectedPath) != null)
this.folderptxt.Text = folderpath;
}
}
private void bgibtn_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Jpg files (*.jpg)|*.jpg|Bitmap files (*.bmp)|*.bmp|" +
"Icon files (*.ico)|*.ico|Jpeg files (*.jpeg)|*.jpeg|" +
"Exif files (*.bmp)|*.exif|TIFF files (*.tiff)|*.tiff";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((imagepath = openFileDialog1.FileName) != null)
{
this.bgitxt.Text = imagepath;
this.imagepicbox.SizeMode = PictureBoxSizeMode.StretchImage;
this.imagepicbox.Image = System.Drawing.Image.FromFile(imagepath);
}
}
}
void run()
{
try
{
path = String.Concat("\"", path);
path = String.Concat(path, "\"");
FileStream aFile = new FileStream("test.bat", FileMode.Create);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine(String.Concat("attrib +s ", path));
sw.Close();
}
catch (IOException e)
{
Console.WriteLine("An IO exception have been thrown !");
Console.WriteLine(e.ToString());
Console.ReadLine();
return;
}
}
public void OpenApplication()
{
Process.Start(".\\test.bat");
}
class background
{
string imagepath,folderpath;
public background(string imageaddress,string folderaddress)
{
imagepath = imageaddress;
folderpath = folderaddress;
}
public void setbackground()
{
set();
}
void set()
{
string file=String.Concat(folderpath, "\\desktop.ini");
if (File.Exists(file))
{
if (MessageBox.Show("It may be change your Operating system setting?",
"User Database Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
File.Delete(file);
makefile(file);
}
}
else
makefile(file);
}
void makefile(string filepath)
{
try
{
FileStream aFile = new FileStream
(filepath, FileMode.CreateNew, FileAccess.Write);
File.SetAttributes(filepath, FileAttributes.Hidden);
StreamWriter sw = new StreamWriter(aFile);
sw.WriteLine("[ExtShellFolderViews]");
sw.WriteLine("{BE098140-A513-11D0-A3A4-00C04FD706EC}=
{BE098140-A513-11D0-A3A4-00C04FD706EC}");
sw.WriteLine("[{BE098140-A513-11D0-A3A4-00C04FD706EC}] ");
sw.WriteLine("Attributes=1");
sw.WriteLine(String.Concat("IconArea_Image = ", imagepath));
sw.WriteLine("IconArea_Text=0x00000000");
sw.Close();
}
catch (IOException e)
{
MessageBox.Show("Background can not be set on the specified folder");
}
catch (Exception ex)
{
MessageBox.Show("Background can not be set on the specified folder");
}
}
}
Now the background has been set at the specified folder.
Tip: If a folder uses the wrong background picture and you can't change it: Start/Run/Regedit and remove this key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Bags.
Points of Interest
In this code, I run the command prompt and execute a specified command (attrib: +s "folder path"
) which converts the folder into the system folder and also does some file handling which changes file attributes and removes the background from the specified folder by deleting the desktop.ini file from the specified folder.
History
- 29th May, 2008: Initial post