c gets the windows desktop background code sample
- 2020-05-27 06:56:40
- OfStack
#region To obtain windows Desktop background
[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
void WindowsBtn_Click(object sender, RoutedEventArgs e)
{
// Define the size of the storage buffer
StringBuilder s = new StringBuilder(300);
// To obtain Window Desktop background image address, using buffer
SystemParametersInfo(SPI_GETDESKWALLPAPER, 300, s, 0);
// Characters in the buffer are converted
string wallpaper_path = s.ToString(); // System desktop background image path
}
Call windows api get
Note that the size of StringBuilder should not be less than 255, because the windows path supports a maximum of 255. If the definition is too small...
Returns empty if the current system desktop has no background or is a solid color.