利用 Windows 的 API 获取桌面壁纸的实际路径,使用的是 SystemParametersInfo 这个API,此API的功能非常丰富,壁纸操作只是一斑
。
using System.Runtime.InteropServices;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool SystemParametersInfo(uint uAction, uint uParam, StringBuilder lpvParam, uint init); const uint SPI_GETDESKWALLPAPER = 0x0073;
StringBuilder wallPaperPath = new StringBuilder(200); if (SystemParametersInfo(SPI_GETDESKWALLPAPER, 200, wallPaperPath, 0)) { MessageBox.Show(wallPaperPath.ToString()); }
搞定!
本文介绍了一种通过调用Windows API中的SystemParametersInfo函数来获取当前桌面壁纸实际路径的方法。利用这种方法可以方便地读取用户的桌面背景图片路径。
412

被折叠的 条评论
为什么被折叠?



