zoukankan      html  css  js  c++  java
  • 一个工具类,让你用C#换桌面墙纸

    参考了这篇文章:

    http://blog.csdn.net/sonyicn/archive/2006/05/20/746280.aspx

    现实代码如下:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using Microsoft.Win32;
    using System.IO;

    namespace RockLib
    {
        
    public class Utils
        
    {
            
    /// <summary>
            
    /// Change user's desktop wallpaper
            
    /// </summary>
            
    /// <param name="picturePath"></param>
            
    /// <param name="style"></param>
            
    /// <returns></returns>

            public static bool ChangeWallPaper(string picturePath, WallPaperStyle style)
            
    {
                RegistryKey myRegKey 
    = Registry.CurrentUser.OpenSubKey("Control Panel\\desktop"true);
                
    switch (style)
                
    {
                    
    case WallPaperStyle.Center:
                        myRegKey.SetValue(
    "TileWallpaper""0");
                        myRegKey.SetValue(
    "WallpaperStyle""0");
                        
    break;
                    
    case WallPaperStyle.Tile:
                        myRegKey.SetValue(
    "TileWallpaper""1");
                        myRegKey.SetValue(
    "WallpaperStyle""0");
                        
    break;
                    
    case WallPaperStyle.Stretch:
                        myRegKey.SetValue(
    "TileWallpaper""0");
                        myRegKey.SetValue(
    "WallpaperStyle""2");
                        
    break;
                    
    default:
                        
    throw new NotSupportedException("style");                    
                }


              
                myRegKey.Close();

                
    int intResult;
                
                
    if (!File.Exists(picturePath))
                
    {
                    
    throw new ArgumentException(string.Format("Picture {0} cannot be found.", picturePath));
                }


                intResult 
    = SystemParametersInfo(203, picturePath, 0x1 | 0x2);

                
    return intResult > 0;

            }


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


        
    public enum WallPaperStyle
        
    {
            Center,
            Tile,
            Stretch
        }

    }

    测试代码:

    Code
  • 相关阅读:
    tomcat 增加压缩设置
    ffmpeg centos6.5上安装(测试 amr 转换为 mp3)
    wkhtmltopdf 安装使用笔记(CentOS6)
    tomcat配置SSL证书(使用startSSL申请到的证书)
    lipo 合并target为Simulator和Device编译的静态库
    aliyun的yum源(国内速度极快)
    OS X 下iso刻录U盘(系统安装启动盘)
    Django学习笔记之数据库-模型的操作
    Django学习笔记之数据库-QuerySet_API
    Django学习笔记之数据库-数据库与模型
  • 原文地址:https://www.cnblogs.com/rockniu/p/1263134.html
Copyright © 2011-2022 走看看