mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-01-15 08:52:08 +08:00
42 lines
757 B
C++
42 lines
757 B
C++
|
|
||
|
#include <Windows.h>
|
||
|
|
||
|
#include <QWidget>
|
||
|
|
||
|
#include "singleapplication.h"
|
||
|
|
||
|
void RaiseWidget(QWidget* pWidget);
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
|
||
|
SingleApplication app(argc, argv, true);
|
||
|
|
||
|
if (app.isSecondary()) {
|
||
|
|
||
|
AllowSetForegroundWindow( DWORD( app.primaryPid() ) );
|
||
|
|
||
|
app.sendMessage("SHOW_WINDOW");
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
QWidget* widget = new QWidget;
|
||
|
|
||
|
QObject::connect(&app, &SingleApplication::receivedMessage,
|
||
|
widget, [widget] () { RaiseWidget(widget); } );
|
||
|
widget->show();
|
||
|
|
||
|
return app.exec();
|
||
|
}
|
||
|
|
||
|
void RaiseWidget(QWidget* widget) {
|
||
|
|
||
|
HWND hwnd = (HWND)widget->winId();
|
||
|
|
||
|
if (::IsIconic(hwnd)) {
|
||
|
::ShowWindow(hwnd, SW_RESTORE);
|
||
|
}
|
||
|
|
||
|
::SetForegroundWindow(hwnd);
|
||
|
}
|