高分,跪着爬着求代码,C#改变桌面背景图片.各位哥哥,请给详细的代码,详细的.

解决方案 »

  1.   

    1、SystemParametersInfo   设定背景的API
    2、System.Drawing.Bitmap bm=new System.Drawing.Bitmap(strPathJpg);
                        bm.Save(strPathBmp,System.Drawing.Imaging.ImageFormat.Bmp);,把jpg转成bmpusing System; 
    using System.IO; 
    using System.Runtime.InteropServices; 
    using System.Text;
    using System.Windows;
    using System.Windows.Forms;
    namespace Desktop
    {
        /// <summary>
        /// ClassDesktop 的摘要说明。
        /// </summary>
        public class ClassDesktop
        {
            public string strPath="";        [DllImport("user32.dll",   EntryPoint="SystemParametersInfo")]   
            public   static   extern   int   SystemParametersInfo   (   
                int   uAction,   
                int   uParam,   
                string   lpvParam,   
                int   fuWinIni   
                );        public ClassDesktop()
            {
                //
                // TODO: 在此处添加构造函数逻辑
                //
            }        public ClassDesktop(string strpath)
            {
                strPath=strpath;
                //
                // TODO: 在此处添加构造函数逻辑
                //
            }
            /// <summary>
            /// 设置桌面背景
            /// </summary>
            /// <param name="Path"></param>
            public void Desktop(string Path)
            {
                if (File.Exists(Path))
                SystemParametersInfo(20, 0, Path,   0x2); // 0x1 | 0x2 
            }
            public void Font()
            {
            //    System.IntPtr p=GetDC(0);
                //System.Drawing.Graphics g=System.Drawing.Graphics.FromHdc(p);
                
            }
            public void setDesktop()
            {
                //取得每天需要显示的图片
                string strPathJpg="";
                string strPathBmp="";
                strPathJpg=Application.StartupPath+"\\"+DateTime.Today.Day.ToString()+".jpg ";
                strPathBmp=Application.StartupPath+"\\"+DateTime.Today.Day.ToString()+".bmp";
                if (File.Exists(strPathBmp))
                {
                    this.Desktop(strPathBmp);
                }
                else
                {
                    if (File.Exists(strPathJpg))
                    {
                        //
                                        }
                    else
                    {
                        MessageBox.Show(strPathJpg);
                        return;
                    }
                }            //MessageBox.Show(strPathJpg);        }
        }
    }引自:http://hi.baidu.com/cocoxili/blog/item/ed79e219cc5d104043a9ada8.html