This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
131 lines (114 loc) · 3.21 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
mInputPlayProcess = new QProcess(this);
ffplayProgram = qApp->applicationDirPath() + "/ffplay.exe";
wProgman = FindWindowA("Progman", 0);
if(wProgman)
GetWindowRect(wProgman, &wProgmanRect);
// 禁用最大化按钮
// https://www.cnblogs.com/ajanuw/p/13563896.html
Qt::WindowFlags flags = this->windowFlags();
flags &= ~Qt::WindowMaximizeButtonHint;
this->setWindowFlags(flags);
// 托盘图标
QIcon icon = QIcon(":/assets/images/logo.ico");
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(icon);
trayIcon->setToolTip("WinWallpaper");
// 设置托盘右键菜单
quitAction = new QAction("退出", this);
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
MainWindow::~MainWindow()
{
delete ui;
delete mInputPlayProcess;
delete trayIcon;
delete trayIconMenu;
delete quitAction;
}
void MainWindow::on_pushButton_clicked()
{
QString filters = "*";
QString filePath = QFileDialog::getOpenFileName(this, "Open File", NULL, filters);
if(filePath == "") return;
ui->lineEdit->setText( filePath );
}
BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM Lparam)
{
MainWindow* _this = (MainWindow*)Lparam;
HWND SHELLDLL_DefView = FindWindowExA(hwnd, 0, "SHELLDLL_DefView", 0);
if(SHELLDLL_DefView != 0)
{
_this->wWorker = FindWindowExA(0, hwnd, "WorkerW", 0);
ShowWindow(_this->wWorker, 0);
return FALSE;
}
return TRUE;
}
void MainWindow::on_pushButton_2_clicked()
{
QString path = ui->lineEdit->text();
if(path.isEmpty() || !wProgman) return;
mInputPlayProcess->close();
QStringList arguments = {
"-noborder",
"-x", "1920",
"-y", "1080",
"-hide_banner",
"-loglevel", "panic",
};
if(ui->checkBox_3->isChecked())
{
arguments.push_back("-loop");
arguments.push_back("0");
}
if(ui->checkBox->isChecked())
{
arguments.push_back("-an");
}
if(ui->checkBox_2->isChecked())
{
arguments.push_back("-vn");
}
arguments.push_back(path);
mInputPlayProcess->start(ffplayProgram, arguments);
}
void MainWindow::on_pushButton_3_clicked()
{
wFFplay = FindWindowA("SDL_app", 0);
if(wWorker == 0)
{
SendMessageTimeoutA(wProgman, 0x52C, 0, 0, 0, 1000, 0);
EnumWindows(EnumWindowsProc, (LPARAM)this);
}
SetParent(wFFplay, wProgman);
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::DoubleClick)
{
this->showNormal();
trayIcon->hide();
}
}
void MainWindow::hideEvent(QHideEvent *event)
{
Q_UNUSED(event);
trayIcon->show();
if(trayIcon->isVisible())
{
hide();
}
}