吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3066|回复: 12
收起左侧

[其他转载] 非常简单的小程序:win10定时切换壁纸,不喜欢的删除到回收站

[复制链接]
longforus 发表于 2020-4-21 18:36
本帖最后由 longforus 于 2020-5-4 11:36 编辑

最近在网上爬了一些漂亮小姐姐做壁纸,虽然大多都是喜欢的,难免也有不喜欢的,都过一遍工作量也太大了,我就想有没有方法,在用文件夹幻灯片自动切换壁纸的时候,遇到不喜欢的可以删掉呢?这样用上一段时间,剩下的就都是我的喜欢的了,可是除了学C的时候,后来基本都没有写过exe程序了,也没有做过windows的相关开发,api调用也是完全懵逼的.后来经过一番百度和cv大法,终于用c#实现了.目的勉强达到,还是有点意思的.哈哈😄.

代码

        using System;
        using System.Runtime.InteropServices;
        using System.Text;
        using Microsoft.Win32;
        using System.Timers;
        using System.IO;
        using Microsoft.VisualBasic.FileIO;
        // 编译 csc .\AutoChangeWallpaper.cs /r:Microsoft.VisualBasic.dll
        namespace AutoChangeWallpaperApplication
        {
    class AutoChangeWallpaper
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool SystemParametersInfo(uint uAction, uint uParam, StringBuilder lpvParam, uint init);

        const uint SPI_GETDESKWALLPAPER = 0x0073;

        static String DIR_PATH = "F:/senluoAll";

        static Random rd = new Random(Guid.NewGuid().GetHashCode());

        static FileInfo[] files = new DirectoryInfo(DIR_PATH).GetFiles();

        static String currentPath;

        static void Main(string[] args)
        {
            if (args != null&&args.Length>0) {
                DIR_PATH = args[0];
                files = new DirectoryInfo(DIR_PATH).GetFiles();
                Console.WriteLine("set dir to " + DIR_PATH );
            }
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Enabled = true;
            timer.Interval = 60000; //执行间隔时间,单位为毫秒; 这里实际间隔为1分钟  
            timer.Start();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(changeWallPaper);
            while (true)
            {
                String inputNumber = Console.ReadLine();
                if (inputNumber.Equals("d"))
                {
                    // File.Delete(currentPath);
                    FileSystem.DeleteFile(currentPath,UIOption.OnlyErrorDialogs,RecycleOption.SendToRecycleBin);
                    files = new DirectoryInfo(DIR_PATH).GetFiles();
                    realChangeWallPaper();
                    timer.Stop();
                    timer.Start();
                }
            }

        }

        private static void changeWallPaper(object source, ElapsedEventArgs e)
        {
            realChangeWallPaper();
        }

        private static void realChangeWallPaper(){
            Wallpaper wallpaper = new Wallpaper();
            int i = rd.Next(0, files.Length);
            String path = files[i].FullName;
            wallpaper.SetWallPaper(path, Wallpaper.Style.Fill);
            Console.WriteLine("set WallPaper to " + path + " at: " + DateTime.Now.ToString());
            currentPath = path;
        }

    }

    public class Wallpaper
    {
        const int SPI_SETDESKWALLPAPER = 20;
        const int SPIF_UPDATEINIFILE = 0x01;
        const int SPIF_SENDWININICHANGE = 0x02;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

        public enum Style : int
        {
            Fill,
            Fit,
            Span,
            Stretch,
            Tile,
            Center
        }

        public void SetWallPaper(string wpaper, Style style)
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true))
            {
                if (style == Style.Fill)
                {
                    key.SetValue(@"WallpaperStyle", 10.ToString());
                    key.SetValue(@"TileWallpaper", 0.ToString());
                }
                if (style == Style.Fit)
                {
                    key.SetValue(@"WallpaperStyle", 6.ToString());
                    key.SetValue(@"TileWallpaper", 0.ToString());
                }
                if (style == Style.Span) // Windows 8 or newer only!
                {
                    key.SetValue(@"WallpaperStyle", 22.ToString());
                    key.SetValue(@"TileWallpaper", 0.ToString());
                }
                if (style == Style.Stretch)
                {
                    key.SetValue(@"WallpaperStyle", 2.ToString());
                    key.SetValue(@"TileWallpaper", 0.ToString());
                }
                if (style == Style.Tile)
                {
                    key.SetValue(@"WallpaperStyle", 0.ToString());
                    key.SetValue(@"TileWallpaper", 1.ToString());
                }
                if (style == Style.Center)
                {
                    key.SetValue(@"WallpaperStyle", 0.ToString());
                    key.SetValue(@"TileWallpaper", 0.ToString());
                }
            }

            SystemParametersInfo(SPI_SETDESKWALLPAPER,
                    0,
                    wpaper,
                    SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
        }
    }

}

编译用csc .\AutoChangeWallpaper.cs /r:Microsoft.VisualBasic.dll就可以编译出exe执行了.

运行

在这里插入图片描述
输入 d 回车就可以删除当前图片了.

很简单的小玩意儿,能拼出来还是有点意外的. 嗯嗯,就是这样,该吃饭了.😄



抱歉抱歉,差点都忘记传exe了,今天补上
https://lanzouj.com/ic8qwdg

创建一个快捷方式,右键->属性->在目标后面加上图片文件夹路径,就可以使用自己的图片了  就像:

D:\cProject\deleteWallpaper\AutoChangeWallpaper.exe F:\Selected
注意空格


AutoChangeWallpaper.7z (2.79 KB, 下载次数: 31)

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| longforus 发表于 2020-4-21 18:38
等下回家,传一下exe

点评

传了成品后回我  详情 回复 发表于 2020-4-22 15:05
风之暇想 发表于 2020-4-22 15:05
MPFENG 发表于 2020-4-22 15:22
gamekeep 发表于 2020-4-27 11:48
exe呢?等着呢
 楼主| longforus 发表于 2020-5-4 11:37

抱歉抱歉,差点都忘记了.已传
 楼主| longforus 发表于 2020-5-4 11:38
MPFENG 发表于 2020-4-22 15:22
希望可以自定义壁纸文件夹。

支持的哦,按照帖子你们操作就行
 楼主| longforus 发表于 2020-5-4 11:39

抱歉抱歉,差点都忘记了.已传
erui 发表于 2020-5-4 18:49
请问楼主,这个软件可以设置更换壁纸时间吗?
这个软件常驻任务栏吗?
cocorange 发表于 2020-5-14 09:50
感谢无私分享  
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 22:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表