-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix code according to pull request review
- Loading branch information
1 parent
d1e9b77
commit dd0e1b3
Showing
5 changed files
with
46 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,59 @@ | ||
|
||
#include <Windows.h> | ||
|
||
#include <QWidget> | ||
|
||
#include "singleapplication.h" | ||
|
||
void RaiseWidget(QWidget* pWidget); | ||
#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("SHOW_WINDOW"); | ||
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); } ); | ||
widget, [widget] () { raiseWidget(widget); } ); | ||
#else | ||
QObject::connect(&app, &SingleApplication::instanceStarted, | ||
widget, [widget] () { raiseWidget(widget); } ); | ||
#endif | ||
|
||
widget->show(); | ||
|
||
return app.exec(); | ||
} | ||
|
||
void RaiseWidget(QWidget* widget) { | ||
|
||
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 | ||
} |
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