-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
main.cpp
59 lines (42 loc) · 1.15 KB
/
main.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
#include <QWidget>
#include "singleapplication.h"
#ifdef Q_OS_WINDOWS
#include <Windows.h>
#endif
void raiseWidget(QWidget* widget);
int main(int argc, char *argv[]) {
#ifdef Q_OS_WINDOWS
SingleApplication app(argc, argv, true);
if (app.isSecondary()) {
AllowSetForegroundWindow( DWORD( app.primaryPid() ) );
app.sendMessage("RAISE_WIDGET");
return 0;
}
#else
SingleApplication app(argc, argv);
#endif
QWidget* widget = new QWidget;
#ifdef Q_OS_WINDOWS
QObject::connect(&app, &SingleApplication::receivedMessage,
widget, [widget] () { raiseWidget(widget); } );
#else
QObject::connect(&app, &SingleApplication::instanceStarted,
widget, [widget] () { raiseWidget(widget); } );
#endif
widget->show();
return app.exec();
}
void raiseWidget(QWidget* widget) {
#ifdef Q_OS_WINDOWS
HWND hwnd = (HWND)widget->winId();
// check if widget is minimized to Windows task bar
if (::IsIconic(hwnd)) {
::ShowWindow(hwnd, SW_RESTORE);
}
::SetForegroundWindow(hwnd);
#else
widget->show();
widget->raise();
widget->activateWindow();
#endif
}