Skip to content

Instantly share code, notes, and snippets.

@heyajulia
Created April 1, 2021 15:02
Show Gist options
  • Save heyajulia/58ff35e67384a04583c579ad081d8a43 to your computer and use it in GitHub Desktop.
Save heyajulia/58ff35e67384a04583c579ad081d8a43 to your computer and use it in GitHub Desktop.
mod bindings {
::windows::include_bindings!();
}
use std::ffi::c_void;
use bindings::Windows::Win32::WindowsAndMessaging::{
SystemParametersInfoW, SystemParametersInfo_fWinIni, SYSTEM_PARAMETERS_INFO_ACTION,
};
fn main() {
let wallpaper_change_succeeded;
let mut path = r#"C:\image.png"#.encode_utf16().collect::<Vec<_>>();
path.push(0);
unsafe {
wallpaper_change_succeeded = SystemParametersInfoW(
SYSTEM_PARAMETERS_INFO_ACTION::SPI_SETDESKWALLPAPER,
0,
path.as_mut_ptr() as *mut c_void,
SystemParametersInfo_fWinIni::SPIF_UPDATEINIFILE,
);
}
if !wallpaper_change_succeeded.as_bool() {
eprintln!("Failed to change the wallpaper");
} else {
println!("Wallpaper changed!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment