最近好多网友说bing.cn的背景找不到地址,还说是“核心机密”,哈哈。
自己就花了点喝茶的时间做了个软件---背景天天换(利用bing.cn的背景)。
下面把核心内容发给大家大家研究研究把(也是我的“核心机密”,哈哈)
主要功能就是搜索背景地址,当然需要一点小调整。有兴趣的自己看看吧,应该不是很难。
有兴趣的可以去我的网站dearcoder.cn下载软件体验一下开机自动更换背景的乐趣吧
private void downbingimage()
{
string webstr;
string locurl = "";
webstr = textBoxWeb.Text;
HttpWebResponse res;
HttpWebRequest req;
StreamReader strm;
bool flag = false;
do
{
try
{
req = (HttpWebRequest)WebRequest.Create(webstr);
res = (HttpWebResponse)req.GetResponse();
if (res != null)
{
flag = true;
strm = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding(54936));//简体中文 Encoding.GetEncoding(54936),Encoding.ASCII
String sLine;
richTextBox1.Text = ""; do //学习笔记do循环C# do while 循环体 loop do until 循环体 loop
{
sLine = strm.ReadLine();
int loc = sLine.IndexOf("g_img={url:");
if (loc != -1)
{//.Remove("'").Remove("/")
sLine = sLine.Substring(loc + 12, 80);
int endlo = sLine.IndexOf(".jpg");
sLine = "http://cn.bing.com/" + sLine.Substring(0, endlo + 4);
//Bitmap mybit = new Bitmap(sLine);
locurl = Path.Combine(Directory.GetCurrentDirectory(), "wall.jpg"); if (SavePhotoFromUrl(locurl, sLine))
{
//mybit.Save(locurl,System.Drawing.Imaging.ImageFormat.Bmp);
pictureBox1.Image = Image.FromFile(locurl);
richTextBox1.Text = sLine; ;
}
else
{
//
}
break;
}
}
while (sLine != null);
setbackground(locurl);
strm.Close();
}
}
catch (WebException e)
{
//MessageBox.Show("出错了", "对不起找不到该网址");
System.Threading.Thread.Sleep(20000);
}
} while (!flag);
}
自己就花了点喝茶的时间做了个软件---背景天天换(利用bing.cn的背景)。
下面把核心内容发给大家大家研究研究把(也是我的“核心机密”,哈哈)
主要功能就是搜索背景地址,当然需要一点小调整。有兴趣的自己看看吧,应该不是很难。
有兴趣的可以去我的网站dearcoder.cn下载软件体验一下开机自动更换背景的乐趣吧
private void downbingimage()
{
string webstr;
string locurl = "";
webstr = textBoxWeb.Text;
HttpWebResponse res;
HttpWebRequest req;
StreamReader strm;
bool flag = false;
do
{
try
{
req = (HttpWebRequest)WebRequest.Create(webstr);
res = (HttpWebResponse)req.GetResponse();
if (res != null)
{
flag = true;
strm = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding(54936));//简体中文 Encoding.GetEncoding(54936),Encoding.ASCII
String sLine;
richTextBox1.Text = ""; do //学习笔记do循环C# do while 循环体 loop do until 循环体 loop
{
sLine = strm.ReadLine();
int loc = sLine.IndexOf("g_img={url:");
if (loc != -1)
{//.Remove("'").Remove("/")
sLine = sLine.Substring(loc + 12, 80);
int endlo = sLine.IndexOf(".jpg");
sLine = "http://cn.bing.com/" + sLine.Substring(0, endlo + 4);
//Bitmap mybit = new Bitmap(sLine);
locurl = Path.Combine(Directory.GetCurrentDirectory(), "wall.jpg"); if (SavePhotoFromUrl(locurl, sLine))
{
//mybit.Save(locurl,System.Drawing.Imaging.ImageFormat.Bmp);
pictureBox1.Image = Image.FromFile(locurl);
richTextBox1.Text = sLine; ;
}
else
{
//
}
break;
}
}
while (sLine != null);
setbackground(locurl);
strm.Close();
}
}
catch (WebException e)
{
//MessageBox.Show("出错了", "对不起找不到该网址");
System.Threading.Thread.Sleep(20000);
}
} while (!flag);
}
setbackground(locurl);
{
//Image myimg;
//myimg.Save(strSavePath);
//设置墙纸显示方式
RegistryKey myRegKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\desktop", true);
//赋值
//注意:在把数值型的数据赋到注册表里面的时候,
//如果不加引号,则该键值会成为“REG_DWORD”型;
//如果加上引号,则该键值会成为“REG_SZ”型。
if (!readxml.ReadXml()) { MessageBox.Show("配置文件被破坏!"); return; }
if (readxml.getmode() == 0)
{
myRegKey.SetValue("TileWallpaper", "0");//0 居中 1 平铺
myRegKey.SetValue("WallpaperStyle", "0");//2 拉伸
this.label1.Text = "当前模式:居中";
this.label2.Text = "更改配置文件config.xml可在下次启动时改变模式";
}
else if (readxml.getmode() == 1)
{
myRegKey.SetValue("TileWallpaper", "1");//0 居中 1 平铺
myRegKey.SetValue("WallpaperStyle", "0");//2 拉伸
this.label1.Text = "当前模式:平铺";
this.label2.Text = "更改配置文件config.xml可在下次启动时改变模式";
}
else if (readxml.getmode() == 2)
{
myRegKey.SetValue("TileWallpaper", "0");//0 居中 1 平铺 默认
myRegKey.SetValue("WallpaperStyle", "2");//2 拉伸
this.label1.Text = "当前模式:拉伸";
this.label2.Text="更改配置文件config.xml可在下次启动时改变模式";
}
else
{
myRegKey.SetValue("TileWallpaper", "0");//0 居中 1 平铺 默认
myRegKey.SetValue("WallpaperStyle", "0");//2 拉伸
this.label1.Text = "当前模式:居中";
this.label2.Text = "更改配置文件config.xml可在下次启动时改变模式";
} //关闭该项,并将改动保存到磁盘
myRegKey.Close(); //设置墙纸
//Bitmap bmpWallpaper = (Bitmap)pictureBox1.Image;
//bmpWallpaper.Save("resource.bmp",ImageFormat.Bmp); //图片保存路径为相对路径,保存在程序的目录下
string strPathBmp = Directory.GetCurrentDirectory() + "wall.bmp";
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(strSavePath);
bm.Save(strPathBmp,System.Drawing.Imaging.ImageFormat.Bmp);//把jpg转成bmp
SystemParametersInfo(20, 1, strPathBmp, 1);//SPI_SETDESKWALLPAPER
// System.Runtime.InteropServices._ParameterInfo=(20,1,strSavePath,1);
}