zoukankan      html  css  js  c++  java
  • 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 { }
            }
  • 相关阅读:
    poj_1236 强连通分支
    【winform程序】自定义webrowser控件调用IE的版本
    【小程序开发】微信小程序开发中遇到的那些坑...
    【C#多线程】C#多线程 Thread 开发基础
    【管理心得】不懂带人,你就自己干到死
    【80端口占用】win7下80端口被(Pid=4)占用的解决方法
    【顽固BUG】Visual Studio 2015 + TestDriven.NET-3.8.2860_Personal_Beta 调用的目标发生了异常。
    【HPP开发】让所有中小企业拥有自己的APP
    【创业积累】如何快速开发出一个高质量的APP
    【架构师之路】依赖注入原理---IoC框架
  • 原文地址:https://www.cnblogs.com/magicdlf/p/1059336.html
Copyright © 2011-2022 走看看