C # Use The Sohu Weibo api to remotely change the wallpaper

Source: Internet
Author: User

Through Sohu Weibo's api, http basic authentication is used, and Sina's oauth must also pass browser authentication, which is too troublesome. The entire program is divided into several small parts, not difficult.

Implement the following functions:

1. Start the instance. If the program runs, the C: gimg folder is created, and the program itself is copied to the folder. The program in this folder will be used when it is started. The downloaded wallpaper is also in this folder.

2. automatically update the wallpaper.

3. Get the image link from Sohu Weibo and download the image.

4. md5 verification, used to compare whether the current wallpaper is the same as the downloaded wallpaper.

5. Hide the window and run it in the background without dropping the window.

6. Convert the image format. In the XP system, call SystemParametersInfo to change the wallpaper. Only the bmp format is supported. Note that the uploaded image is also in bmp format.

The C #. net class encapsulated by Sohu Weibo is used in the code, which is easy to use. This class Library:

Http://www.iiidown.com/source_link.php? Type = 1 & key = 71510353 & url = http % 3A % 2F % 2Fdlwt.csdn.net % 2Ffd. php % 3Fi % 3D751826827284012% 26 s % 3d025045b263981a9e0000d83067b6b9d3c

Paste the code below:

Using System; using System. collections. generic; using System. drawing; using System. text; using System. windows. forms; using System. runtime. interopServices; using System. net. sockets; using System. IO; using System. threading; using System. net; using System. drawing. imaging; using web. apiService; // Sohu api class library. Namespace client_souhu {public partial class main: Form {[DllImport ("user32.dll", EntryPoint = "SystemParametersInfo")] public static extern int SystemParametersInfo1 (int uAction, int uParam, string lpvParam, int fuWinIni); [DllImport ("user32.dll", CharSet = CharSet. auto, SetLastError = true)] static extern bool SystemParametersInfo (uint uAction, uint uParam, StringBuilder lpvParam, uint init ); Const uint spi_get1_wallpaper = 0x0073; string localPath = @ "c: gimg"; // create a folder path. String localFilename = "1.bmp"; // the file name of the downloaded image. String mainName = "wallpaper.exe"; // name of the main program. String lastThemesPaperMd5 = ""; // Save the md5 of the last image. There is a problem with implementation here, so you don't have to worry about it first. String lastBgimgPaperMd5 = ""; // The md5. string tmpFileName = "1.jpg"; bool downloadingImg = false; // if the value is true, the image is being downloaded, pause switching wallpaper. String weiboCreateTime; // The Creation Time of the Weibo image. It is used to determine whether the Weibo image is updated and whether the image is to be downloaded. // Sohu Weibo account information. // When uploading images on Weibo, the content of Weibo is imgBz. The program downloads the images based on the logo. For Windows XP users, the uploaded image is in. BMP format. // You can change the wallpaper string username = "Your Weibo account" as long as you have Weibo images with the imgBz logo in the last 20 Weibo posts "; string passwd = "Your Weibo password"; string imgBz = "wp_public"; // different people use different logos to download different images. The custom public main () {InitializeComponent () ;}private void form=load (object sender, EventArgs e) {updateSelf (); autoRun (); // separate thread. Thread updateImgThread = new Thread (new ThreadStart (updateImg); updateImgThread. start (); Thread downloadImgThread = new Thread (new ThreadStart (downloadImg); downloadImgThread. start () ;}// update the image private void updateImg () {Thread. currentThread. isBackground = true; StringBuilder wallPaperPath = new StringBuilder (200); SystemParametersInfo (spi_get1_wallpaper, 200, wallPaperPath, 0); while (true ){ If (File. Exists (localPath + localFilename )&&! DownloadingImg) {string x = getMD5Hash (wallPaperPath. ToString (); string y = getMD5Hash (localPath + localFilename); if (x! = LastThemesPaperMd5 | y! = LastBgimgPaperMd5) {SystemParametersInfo1 (20, 0, localPath + localFilename, 1); lastThemesPaperMd5 = x; lastBgimgPaperMd5 = y; // MessageBox. show ("change Paper: Themes") ;}} Thread. sleep (5000) ;}/// download images from Weibo. Private void downloadImg () {Thread. CurrentThread. IsBackground = true; WebClient wc = new WebClient (); while (true) & nbs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.