Created
December 30, 2020 14:04
-
-
Save XiaoGeNintendo/899e81f6f2a33de488c001bef45ba861 to your computer and use it in GitHub Desktop.
Animate Wallpaper for Windows
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
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include <set> | |
#include <queue> | |
#include <map> | |
#include <string.h> | |
#include <math.h> | |
#include <stdio.h> | |
#include <deque> | |
#include <bits/stdc++.h> | |
#include <windows.h> | |
//#include "testlib.h" | |
using namespace std; | |
#define ll long long | |
#define pii pair<int,int> | |
#define qi ios::sync_with_stdio(0) | |
bool debug=true; | |
/* ************************************* | |
* Written in New Computer * | |
* The following code belongs to * | |
* XiaoGeNintendo of HellHoleStudios * | |
************************************* | |
*/ | |
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){ | |
os<<ptt.first<<","<<ptt.second; | |
return os; | |
} | |
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){ | |
os<<"{"; | |
for(int i=0;i<vt.size();i++){ | |
os<<vt[i]<<" "; | |
} | |
os<<"}"; | |
return os; | |
} | |
string toString(int num){ | |
bool negative=false; | |
if(num<0) negative=true; | |
if(num==0) return "0"; | |
num=abs(num); | |
string s; | |
while(num!=0){ | |
s+=num%10+'0'; | |
num/=10; | |
} | |
reverse(s.begin(),s.end()); | |
if(negative) s='-'+s; | |
return s; | |
} | |
int findInt(string s){ | |
bool ne=(s[0]=='-'); | |
int num=0; | |
for(int i=0+ne;i<s.size();i++){ | |
num=10*num+s[i]-'0'; | |
} | |
if(ne) num=-num; | |
return num; | |
} | |
void HideConsole() | |
{ | |
::ShowWindow(::GetConsoleWindow(), SW_HIDE); | |
} | |
void ShowConsole() | |
{ | |
::ShowWindow(::GetConsoleWindow(), SW_SHOW); | |
} | |
bool IsConsoleVisible() | |
{ | |
return ::IsWindowVisible(::GetConsoleWindow()) != FALSE; | |
} | |
int interval; | |
string basePath; | |
int size; | |
string mode; | |
int changeBG(string path){ | |
string first=mode.substr(0,1); | |
auto sec=(mode[1]=='S'?SPIF_SENDCHANGE:SPIF_UPDATEINIFILE); | |
// cout<<path<<" "<<mode<<" "<<first<<" "<<sec<<endl; | |
if(first=="N"){ | |
int res=SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)path.c_str(), sec); | |
return res; | |
}else if(first=="A"){ | |
int res=SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (PVOID*)path.c_str(), sec); | |
return res; | |
}else if(first=="W"){ | |
auto wide=wstring(path.begin(),path.end()); | |
auto wider=wide.c_str(); | |
int res=SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)wider, sec); | |
return res; | |
} | |
// cout<<"NS"<<endl; | |
return false; | |
} | |
int main(int argc,char* argv[]){ | |
cout<<"Animate Wallpaper (StopChangeBGV2) By XGN from HHS"<<endl; | |
cout<<"Dev Time: 2020-12"<<endl; | |
if(argc<5){ | |
cout<<"argument: <base path> <interval> <size> <method>"<<endl; | |
cout<<"<base path> should contain a single * to indicate the frame ID"<<endl; | |
cout<<"Frame ID starts from 1 to size"<<endl; | |
cout<<"About <method>: two char"<<endl; | |
cout<<"First char:"<<endl; | |
cout<<"N=SystemParametersInfo"<<endl; | |
cout<<"A=SystemParametersInfoA"<<endl; | |
cout<<"W=SystemParametersInfoW"<<endl; | |
cout<<"Second char:"<<endl; | |
cout<<"S=SPIF_SENDCHANGE"<<endl; | |
cout<<"I=SPIF_UPDATEINIFILE"<<endl; | |
cout<<"Now manual input basePath="<<endl; | |
getline(cin,basePath); | |
cout<<"Interval="; | |
cin>>interval; | |
cout<<"Size="; | |
cin>>size; | |
cout<<"Method(N/A/W+S/I)="; | |
cin>>mode; | |
}else{ | |
interval=findInt(argv[2]); | |
size=findInt(argv[3]); | |
basePath=argv[1]; | |
mode=argv[4]; | |
} | |
cout<<"Confirm Information:"<<endl; | |
cout<<"interval="<<interval<<endl; | |
cout<<"basePath="<<basePath<<endl; | |
cout<<"size="<<size<<endl; | |
cout<<"mode="<<mode<<endl; | |
system("pause"); | |
if(argc<=5){ | |
HideConsole(); | |
} | |
int id=1; | |
while(true){ | |
string path=basePath; | |
path.replace(basePath.find("*"),1,toString(id)); | |
cout<<path<<endl; | |
int clc=clock(); | |
int res=changeBG(path); | |
int timeCon=clock()-clc; | |
cout<<"Time consumed:"<<timeCon<<endl; | |
if(!res){ | |
MessageBox(NULL,"Failed to set wallpaper","Error",MB_OK); | |
return 2; | |
} | |
if(interval-timeCon<=0){ | |
cout<<"[WARNING] Can't keep up"<<endl; | |
}else{ | |
Sleep(interval-timeCon); | |
} | |
id++; | |
if(id==size+1){ | |
id=1; | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment