C#替換桌面的兩種方式

關於C#替換桌面。我一直在網上找。有兩種方式。一種是修改註冊表 一種是調用系統API:


修改註冊表

     using Microsoft.Win32;  //寫入註冊表時要用到       
//設置壁紙
            //導航到Policies項
            RegistryKey hkml = Registry.CurrentUser;
            RegistryKey software = hkml.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Policies\" , true );

            //新建立System項
            RegistryKey aimdir = software.CreateSubKey( "System" );
            aimdir.SetValue( "Wallpaper" , photoURL );//URL是圖片的URL
            reKey.SetValue( "TileWallpaper" , "0" );
            aimdir.SetValue( "WallpaperStyle" , "2" );


            //關閉節點,並保存修改
            hkml.Close();
            software.Close();
            aimdir.Close(); 

調用系統API

using System.Runtime.InteropServices;  //調用WINDOWS API函數時要用到

        [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
        public static extern int SystemParametersInfo(
            int uAction ,
            int uParam ,
            string lpvParam ,
            int fuWinIni
            );
SystemParametersInfo( 20 , 1 , photoURL , 1 );

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章