只要用的是纯Win32 API,没有用到BCB中的专有API,就也可以在QT中使用。
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QWidget>
#ifdef Q_WS_WIN
#include <windows.h>
#endif
int main(int argc, char **argv)
{
QApplication app(argc, argv);
#ifdef Q_WS_WIN
HANDLE hMutex = CreateMutex(NULL, true, QString("['{EFEB2EF6-F8E0-AE44-BABE-1BBEF2C7FD56}']").toStdWString().c_str());
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hMutex);
QMessageBox::information(NULL, "Info", "Has been Run", "OK");
app.exit(1);
return 1;
}
#endif
QWidget form;
form.setWindowTitle("Hello");
form.resize(400, 300);
form.show();
return app.exec();
}
[ 此贴被XChinux在2007-08-14 17:26重新编辑 ]