再好也是别人做的,再烂也是自己写的,存在专栏,作为留念。
vs2022+opencv4.8.0+w11(需要opencv环境)
动态壁纸.cpp
#include"目录.h"
#include"动态壁纸运行.h"
int main()
{
vector suo_you_di_zhi = jia_zai_di_zhi();
int xuan_ze_1;
while (1)
{
mu_lu_1(suo_you_di_zhi);
cin >> xuan_ze_1;
switch (xuan_ze_1)
{
case (0):
chu_chun_di_zhi(suo_you_di_zhi);
return 0;
case (1):
{
yun_xing_dong_tai_bi_zhi(suo_you_di_zhi[0].dizhi);
system("pause");
break;
}
case (2):
{
xian_shi_di_zhi(suo_you_di_zhi);
system("pause");
break;
}
case (3):
{
xian_shi_di_zhi(suo_you_di_zhi);
she_zhi_bi_zhi(suo_you_di_zhi);
system("pause");
break;
}
case (4):
{
tian_jia_di_zhi(suo_you_di_zhi);
system("pause");
break;
}
case (5):
{
xian_shi_di_zhi(suo_you_di_zhi);
shan_chu_di_zhi(suo_you_di_zhi);
system("pause");
break;
}
default:
{
cout << "无关选项,请重新选择:" << endl;
system("pause");
break;
}
}
system("cls");
}
}
目录.h
#pragma once
#include"地址储存.h"
#include
using namespace std;
void mu_lu_1(vector dizhi)
{
cout << "--------------------------" << endl;
cout << "1.运行动态壁纸 " << endl;
cout << "" << endl;
cout << "2.查看视频目录 " << endl;
cout << "" << endl;
cout << "3.设置当前壁纸 " << endl;
cout << "" << endl;
cout << "4.插入视频地址 " << endl;
cout << "" << endl;
cout << "5.删除视频地址 " << endl;
cout << "" << endl;
cout << "当前动态视频:" << endl;
if (dizhi.size() == 0)
cout << "暂无" << endl;
else
cout << dizhi[0].name << endl;
cout << "" << endl;
cout << "(所有页面0为退出) " << endl;
cout << "--------------------------" << endl;
}
动态壁纸运行.h
#pragma once
#include
#include
#include"opencv2/highgui/highgui_c.h"
#include
using namespace cv;
HWND bi_zhi = NULL;
void fen_lie_bi_zhi()
{
HWND dang_qian_bi_zhi = FindWindow(L"Progman", L"Program Manager");
SendMessage(dang_qian_bi_zhi, 0x52c, 0, 0);
}
BOOL CALLBACK EnumWinProc(HWND mei_ju, LPARAM lParam)
{
HWND tu_biao = FindWindowEx(mei_ju, 0, L"SHELLDLL_DefView", 0);
if (tu_biao != 0)
{
bi_zhi = FindWindowEx(0, mei_ju, L"WorkerW", 0);
return 0;
}
return 1;
}
void cha_xun_bi_zhi()
{
fen_lie_bi_zhi();
EnumWindows(EnumWinProc, 0);
}
void yun_xing_dong_tai_bi_zhi(string & SPDZ)
{
cout << "按ESC退出。" << endl;
cv::utils::logging::setLogLevel(utils::logging::LOG_LEVEL_SILENT);//取消日志
cha_xun_bi_zhi();
const String spdz = SPDZ;
VideoCapture shi_pin(spdz);
int const zhen = shi_pin.get(5);
namedWindow("dong_tai", 0);
setWindowProperty("dong_tai", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
HWND show_chuangkou = FindWindow(L"Main HighGUI class", L"dong_tai");
HWND const bizhi_jb = (HWND)cvGetWindowHandle("dong_tai");
SetParent(show_chuangkou, bi_zhi);
resizeWindow("dong_tai", 2560, 1600);
Mat tu_pian;
int dang_qian_zhen = 0, pan_duan = 1;
while (pan_duan)
{
dang_qian_zhen++;
if (dang_qian_zhen == shi_pin.get(CAP_PROP_FRAME_COUNT))
{
dang_qian_zhen = 0;
shi_pin.set(CAP_PROP_POS_FRAMES, 0);
}
shi_pin.read(tu_pian);
imshow("dong_tai", tu_pian);
cvWaitKey(33);
if (GetAsyncKeyState(VK_ESCAPE))
{
break;
}
}
shi_pin.release();
destroyWindow("dong_tai");
destroyAllWindows();
}
地址储存.h
#pragma once
#include
#include
#include
#include
using namespace std;
class DZ
{
public:
int id;
string dizhi;
string name;
};
void xian_shi_di_zhi(vector dizhi)
{
for (int i = 0; i < dizhi.size(); i++)
{
if (i == 0)
{
cout << "当前播放视频名字:" << dizhi[i].name << endl;
cout << "视频所属地址:" << dizhi[i].dizhi << endl << endl;
}
else
{
cout << "编号:" << dizhi[i].id << " 名字:" << dizhi[i].name << endl;
cout << "地址:" << dizhi[i].dizhi << endl;
}
}
}
void chu_chun_di_zhi(vector dizhi)
{
ofstream shu_chu;
shu_chu.open("di_zhi.txt", ios::out | ios::trunc);
int i = dizhi.size();
for (int i = 0; i < dizhi.size(); i++)
{
shu_chu << dizhi[i].id << " " << dizhi[i].name << " " << dizhi[i].dizhi << endl;
}
shu_chu.close();
}
vector jia_zai_di_zhi()
{
vector dizhi;
dizhi.clear();
ifstream shu_ru;
shu_ru.open("di_zhi.txt", ios::in);
DZ temp;
while (shu_ru>>temp.id&&shu_ru>>temp.name&&shu_ru>>temp.dizhi)
{
dizhi.push_back(temp);
}
shu_ru.close();
return dizhi;
}
void she_zhi_bi_zhi(vector &dizhi)
{
cout << endl << endl;
int id;
cout << "视频编号:" << endl;
cin >> id;
if (id == 0)
{ }
else if (id < 0 && id >= dizhi.size())
{
cout << "不存在该编号。" << endl;
}
else
{
dizhi[0].dizhi = dizhi[id].dizhi;
dizhi[0].name = dizhi[0].name;
}
}
void tian_jia_di_zhi(vector & dizhi)
{
DZ di_zhi;
cout << "视频名字:" << endl;
cin >> di_zhi.name;
cout << "视频地址:" << endl;
cout << "(地址的所有“\\”请改成“\\\\”或者“/”。)" << endl << "(还有,两边别给我加引号。)" << endl<<"地址不要有空格!!!"<> di_zhi.dizhi;
int id = dizhi.size();
di_zhi.id = id;
if(dizhi.size()==0)
{
dizhi.push_back(di_zhi);
di_zhi.id++;
dizhi.push_back(di_zhi);
}
else
{
dizhi.push_back(di_zhi);
}
}
void shan_chu_di_zhi(vector & dizhi)
{
cout << endl << endl;
int id;
cout << "视频编号:" << endl;
cin >> id;
if(id==0)
{ }
else if (id < 0 && id >= dizhi.size())
{
cout << "不存在该编号。" << endl;
}
else
{
dizhi.erase(dizhi.begin() + id);
for (int i = 1; i < dizhi.size(); i++)
{
if (dizhi[i].id - 1 != dizhi[i - 1].id)
{
dizhi[i].id -= 1;
}
}
}
}
标签: