AdvancedBackgroundJimmy.Program.cs
using AdvancedBackground; using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.ServiceProcess; using System.Threading.Tasks; using System.Timers; namespace AdvancedBackgroundJimmy { [System.Runtime.Remoting.Contexts.Synchronization] static class Program { const int SPI_GETDESKWALLPAPER = 0x73; const int MAX_PATH = 260; const int SPI_SETDESKWALLPAPER = 0x14; const int SPIF_UPDATEINIFILE = 0x01; const int SPIF_SENDININICHANGE = 0x02; static string photoFileDirPath = @"g:/Photos/Camera/"; static DirectoryInfo photoDir = new DirectoryInfo(photoFileDirPath); static FileInfo[] photoFileArr = photoDir.GetFiles(); static int PHOTO_PER_WAIT = 3000; static string log_path = @"g:/TestLog/AdvancedBackgroundJimmy/log.txt"; static FileInfo logFileInfo = new FileInfo(log_path); static string log = null; /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { //ServiceBase[] servicesToRun = new ServiceBase[] //{ // new AdvancedBackgroundServiceJimmy() //}; //ServiceBase.Run(servicesToRun); AutoPhoto(); } public static void AutoPhoto() { try { log = "进入AutoPhoto方法!" + System.Environment.NewLine; File.AppendAllText(log_path, log); FileInfo[] fileArr = photoFileArr; for (int i = 0; i < fileArr.Length; i++) { FileInfo photoFile = fileArr[i]; log = "当前图片路径:" + photoFile.FullName + System.Environment.NewLine; File.AppendAllText(log_path, log); SetWallpaper2(photoFile.FullName, WallpaperStyle.Centered); //SHChangeNotify(HChangeNotifyEventID.SHCNE_ASSOCCHANGED, HChangeNotifyFlags.SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero); if (i == fileArr.Length - 1) { i = -1; } System.Threading.Thread.Sleep(PHOTO_PER_WAIT); } } catch(Exception e) { log = e.Message + System.Environment.NewLine; File.AppendAllText(log_path, log); } } const int WM_SETTINGCHANGE = 0x001A; const int HWND_BROADCAST = 0xffff; static IntPtr result1; public enum SendMessageTimeoutFlags : uint { SMTO_NORMAL = 0x0000, SMTO_BLOCK = 0x0001, SMTO_ABORTIFHUNG = 0x0002, SMTO_NOTIMEOUTIFNOTHUNG = 0x0008 } [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] static extern int GetLastError(); public enum WallpaperStyle : int { Tiled, Centered, Stretched, Fill, Fit } /// <summary> /// 返回当前的系统壁纸路径 /// </summary> /// <returns></returns> public static string GetDesktopWallpaper() { string wallpaper = new string('