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 { }
            }
  • 相关阅读:
    大前端完整学习路线(详解)
    浅谈攻击Web应用常见的技术手段
    浅谈XSS跨站脚本攻击
    利用SQL注入漏洞登录后台
    1、MyBatis框架底层初涉
    1、用静态工厂方法代替构造器
    日志管理-log4j与slf4j的使用
    Java的值类型和引用类型
    自动任务调度
    2、Hibernate持久化编写
  • 原文地址:https://www.cnblogs.com/magicdlf/p/1059336.html
Copyright © 2011-2022 走看看