又一次调用win32函数呢…
初始化部分:
<<NetLink`
InstallNET[];
SystemParametersInfoA=DefineDLLFunction["SystemParametersInfoA","user32.dll","int",{"int","int","char*","int"}];
ChangeWallpaper[file_]:=SystemParametersInfoA[20,0,file,1];
RandomWallPaper[]:=Block[{data,file,path="D:/temp.jpg"},
PrintTemporary["Downloading wallpaper..."];
data=URLRead[HTTPRequest["https://api.hanximeng.com/ranimg/api.php",<|"Headers"-><|"referer"->"https://api.hanximeng.com/ranimg/"|>|>],"BodyByteArray"];
file=OpenWrite[path,BinaryFormat->True];
BinaryWrite[file,data];
Close[file];
ChangeWallpaper[path]]
调用方式:RandomWallPaper[]
用完之后记得卸载.NET链接使用:UninstallNET[]
此外,程序使用了api.hanximeng.com
网站的随机图片api