設定 WIndows 桌面有兩種方式
一種是利用 import user32.dll 的方式
例:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni);
private static UInt32 SPI_SETDESKWALLPAPER = 20;
private static UInt32 SPIF_UPDATEINIFILE = 0x1;
private String imageFileName = "c:\\sample.bmp";

public void SetImage( string filename )
{
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE);
}

另一種是設定 Registry 的方式
例:
RegistryKey k=Registry.CurrentUser.CreateSubKey("Control Panel", RegistryKeyPermissionCheck.ReadWriteSubTree)
                    .CreateSubKey("Desktop", RegistryKeyPermissionCheck.ReadWriteSubTree);
k.SetValue("Wallpaper", "c:\\wallpaperPath.bmp", RegistryValueKind.String);
arrow
arrow
    全站熱搜

    JohnDX 發表在 痞客邦 留言(0) 人氣()