Created
April 1, 2021 15:02
-
-
Save heyajulia/58ff35e67384a04583c579ad081d8a43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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