1、准备
- windows操作系统(7,8,10,11)
- autohotkey2.x_x64 版本
- 连接互联网
2、使用方式
- 直接运行代码,就会立即下载并更换bing壁纸、
- 你可以把代码加入开机启动下,即可实现每日更换bing壁纸、
- 只会修改桌面壁纸,并不会修改锁屏壁纸
3、演示
4、代码
setTimer ()=>init.changeBingWallpaper(),ak.onStartPc()?-5000:-1 ;开机后更换桌面为bing壁纸,无水印
class init
{
static configLogPath:= A_ScriptDir
;异步更换bing壁纸
static changeBingWallpaper()
{
try{
bingSite:="http://www.bing.com"
if not ak.ConnectedToInternet()
return
if not FileExist(bingPng:=Format("{1}\wallpaper\{2}-{3}-{4}.png",this.configLogPath,A_YYYY,A_MM,A_DD)){
if not FileExist(bingDir:=Format("{1}\wallpaper",this.configLogPath))
DirCreate(bingDir)
bingURL:=bingSite . ak.getElemetAttr(ak.getHtmlContent(bingSite),"preloadBg","href")
Download bingURL, bingPng ;下载图片
}
ak.changeWallPaper(bingPng) ;更换壁纸
}catch as e{
msgbox "更换壁纸异常:" . e.Message
}
}
}
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ak工具类class
class ak
{
;判断是否连接互联网
static ConnectedToInternet(flag:=0x40) {
Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
}
;Func 通过id获取htmlcontent中指定标签的的指定属性attr
static getElemetAttr(htmlcontent,id ,attr)
{
js:= ComObject("htmlfile")
js.write(htmlcontent)
document :=js.parentWindow.document
element:=document.getElementByID(id)
return element.getAttribute(attr)
}
;Func 判断是否是刚开机,传入时间 n 秒
static onStartPc(n:=60)
{
return (A_TickCount/1000)<n
}
;Func 异步获取网页内容,返回完整的html,传入完整的url 例:http://www.baidu.com
static getHtmlContent(url)
{
static req := comObject("WinHttp.WinHttpRequest.5.1")
req.Open("get",url,true) ;异步
req.setRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36")
req.send()
req.WaitForResponse()
return req.ResponseText
}
;Func 修改壁纸
static changeWallpaper(path)
{
DllCall("SystemParametersInfo", "UInt", 0x14, "UInt", 0, "Str", path, "UInt", 2)
}
}
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ak工具类class
5、总结
bing的壁纸是全球统一的, 该方法直接爬取网页获取地址来更换,当然也可以微软也有专门的壁纸接口,但是接口返回的图片就很离谱不太推荐.
感谢大佬分享
感谢大佬😂😂😂
感谢大佬分享