• How to change windows wallpaper in C#


    http://www.csharphelp.com/archives3/archive578.html
    http://www.codeproject.com/KB/dotnet/SettingWallpaperDotNet.aspx

    核心部分代码:
    using System.Runtime.InteropServices;

            public class WinAPI
            {
                [DllImport("user32.dll", CharSet = CharSet.Auto)]
                public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
                public const int SPI_SETDESKWALLPAPER = 20;
                public const int SPIF_SENDCHANGE = 0x2;
                public const int SPIF_UPDATEINIFILE = 0x01;

            }

             public void changeWallpaper(string path)
            {
                Microsoft.Win32.RegistryKey rkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop",true);
                try
                {

                    if (rkey != null)
                    {
                        string currentWallpaper = rkey.GetValue(@"Wallpaper") as string;
                        if (currentWallpaper != null)
                        {
                            //key exists;
                            //rkey.SetValue(@"Wallpaper", textBox1.Text);
                            rkey.SetValue(@"WallpaperStyle", 1.ToString());
                            rkey.SetValue(@"TileWallpaper", 0.ToString());
                            string fileName = path;
                            if (fileName.ToLower().EndsWith(@".jpg"))
                            {
                                fileName = jepg2bmp(fileName);
                            }
                            //check file exists;
                            int nResult = WinAPI.SystemParametersInfo(WinAPI.SPI_SETDESKWALLPAPER, 0, fileName, WinAPI.SPIF_SENDCHANGE | WinAPI.SPIF_UPDATEINIFILE);
                            Console.WriteLine(nResult);
                        }
                    }
                }
                catch { }
            }
  • 相关阅读:
    UI组件库Kendo UI for Vue原生组件中文教程 如何开始制作动画
    高性能HTML5/JavaScript开发框架DevExtreme v22.1.3正式发布
    界面组件Telerik UI for WPF入门指南 如何使用主题切换自定义样式
    如何在MVVM场景中使用WinUI数据网格?这个工具可以搞定
    Spring Boot设置上传文件大小
    SpringBoot SpringBoot 定时器的三种方式定时器的三种方式
    SpringBoot文件上传
    vscode快速生成vue模板
    Failed to execute goal org.apache.maven.plugins:mavensurefireplugin:2.12.4
    There are no resources that can be added or removed from the server
  • 原文地址:https://www.cnblogs.com/magicdlf/p/1059336.html
Copyright © 2020-2023  润新知