該項功能需要使用WINAPI SystemParametersInfo ,該函數用于設置和取得windows系統參數,詳細信息可查閱MSDN,這里就不展開討論了,實現主要部分如下
C# 中引用WINAPI定義如下:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SystemParametersInfo(int uAction, int uParam, StringBuilder lpvParam, int fuWinIni);
PRivate const int SPI_GETDESKWALLPAPER = 0x0073;
實現主要代碼:
//定義存儲緩沖區大小
StringBuilder s = new StringBuilder(200);
//獲取Window 桌面背景圖片地址,使用緩沖區
SystemParametersInfo(SPI_GETDESKWALLPAPER, 200, s, 0);
//緩沖區中字符進行轉換
string wallpaper_path = s.ToString(); //系統桌面背景圖片路徑
新聞熱點
疑難解答