#include <QtGui/QApplication>#include <windows.h>#include "UManager.h"int main(int argc, char *argv[]){ HANDLE mutex; LPCWSTR mtxname = L"Mutex"; if(OpenMutex(MUTEX_ALL_ACCESS, false, mtxname) != 0) { return -1; }else { mutex = CreateMutex(0, false, mtxname); } QApplication a(argc, argv); QPixmap *pixmap = new QPixmap(":/images/splash.png"); QSplashScreen *splash = new QSplashScreen(*pixmap); splash->show(); a.processEvents(); splash->showMessage("initialization...", Qt::AlignRight); UManager *manager = new UManager(); splash->finish(manager); delete pixmap; delete splash; a.setQuitOnLastWindowClosed(false); ReleaseMutex(mutex); return a.exec();}
C++ (Qt) ... if(OpenMutex(MUTEX_ALL_ACCESS, false, mtxname) != 0) { HWND wnd = FindWindow(mtClass, myTitle); if (myWnd) { if (IsIconic(wnd)) ShowWindow(wnd, SW_RESTORE): SetForegroundWindow(wnd); } return -1; } ...
#include "qtsingleapplication/qtsingleapplication.h"#include <QWidget>int main(int argc, char **argv){ QtSingleApplication instance(argc, argv); if(instance.sendMessage("Wake up!")) if(instance.isRunning()) return 0; QWidget w; instance.setActivationWindow(&w); w.show(); QObject::connect(&instance, SIGNAL(messageReceived(const QString&)), &w, SLOT(setWindowTitle(QString&))); return instance.exec();}