C#用API 获取电脑桌面背景图地址

#region 获取windows桌面背景        

[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]        

public static extern int SystemParametersInfo(int uAction, int uParam, StringBuilder lpvParam, int fuWinIni);

private const int SPI_GETDESKWALLPAPER = 0x0073;        

#endregion

 调用

//定义存储缓冲区大小
StringBuilder s = new StringBuilder(300);
//获取Window 桌面背景图片地址,使用缓冲区
SystemParametersInfo(SPI_GETDESKWALLPAPER, 300, s, 0);
//缓冲区中字符进行转换
string wallpaper_path = s.ToString(); //系统桌面背景图片路径

posted @ 2013-12-19 13:08  bk.lling  阅读(827)  评论(0编辑  收藏  举报