您好,登錄后才能下訂單哦!
微軟Bing壁紙是我非常喜歡的壁紙,怎么說呢它的壁紙非常細膩逼真,總是讓人心動,我就不安利了,反正比三百六X鳥好多了。不幸的是Win10更新到最新版以后微軟bing繽紛桌面不能運行了,失望加無奈。。 難道我就這么的放棄我的壁紙了么,不,黨告訴我,你可以靠自己,你可以創新,然后就自己動手做了一款工具來自動下載Bing壁紙工具。 純。。。純到沒有界面,純到沒有任何提示,純到24小時自動更換壁紙,純。
整體而言,就是用json network slots ,就簡單貼下主要代碼部分,附件有構建好的應用,win10通過。。。
//bing.cpp #include "bing.h" #pragma comment(lib, "user32.lib") Bing::Bing() { connect(&manager,&QNetworkAccessManager::finished,this,&Bing::downloadFinished); } void Bing::execute() { QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(execute())); timer->setInterval(86400000); timer->start(); QUrl url("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"); QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); currentReplys.append(reply); qDebug() << "execute "; } void Bing::doGetJson(QNetworkReply *reply) { QByteArray byteArray = reply->readAll(); QJsonParseError jsonError; QJsonDocument json = QJsonDocument::fromJson(byteArray,&jsonError); if (!json.isNull() && (jsonError.error == QJsonParseError::NoError)) { if(json.isObject()) { QJsonObject obj =json.object(); if(obj.contains("images")) { QJsonValue value = obj.value("images"); if(value.isArray()) { QJsonArray jsonArray = value.toArray(); QJsonValue imageValue = jsonArray.at(0); if(imageValue.isObject()) { QString image = imageValue["url"].toString(); QString baseUrl = "https://www.bing.com"; baseUrl.append(image); QUrl url(baseUrl); QNetworkRequest request(url); QNetworkReply *replyImage = manager.get(request); currentReplys.append(replyImage); } } } } } } void Bing::downloadFinished(QNetworkReply *reply) { if(reply->url() == QUrl("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US")) { doGetJson(reply); } else { saveImages(reply); } currentReplys.removeAll(reply); reply->deleteLater(); } void Bing::saveImages(QNetworkReply *reply) { QDate date = QDate::currentDate(); QString fileName = "d:\\bingWallPaper\\bing"; fileName.append(date.toString("yyyyMMdd")).append(".jpg"); QFile file(fileName); if(!file.open(QIODevice::WriteOnly)) { qDebug() << "open failed"; return; } file.write(reply->readAll()); file.close(); setWallPaper(); } void Bing::setWallPaper() { //const wchar_t *wimFile =reinterpret_cast<const wchar_t *>(pszWimFile.utf16()); QDate date = QDate::currentDate(); QString fileName = "d:\\bingWallPaper\\bing"; fileName.append(date.toString("yyyyMMdd")).append(".jpg"); const wchar_t *image =reinterpret_cast<const wchar_t *>(fileName.utf16()); if( !SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)image, SPIF_UPDATEINIFILE) )//調用windows的API函 return; }
源代碼:https://github.com/piaodonkey/BingWallPaper 我真是越來越懶了。。
附件:鏈接:https://pan.baidu.com/s/1XiL4HhluEbPzEcIVo8xhmA 密碼:dck1
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。