当前程序只能打开一次且隐藏
当前程序只打开一次
cpp
//当前程序只打开一次
HANDLE hMutex = CreateMutex(NULL, TRUE, "MyMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
MessageBox(NULL, "该程序已经打开!", "提示", MB_OK | MB_ICONINFORMATION);
CloseHandle(hMutex);
return 0;
}
cpp
//当前程序只打开一次(QT程序)
HANDLE hMutex = CreateMutexA(NULL, TRUE, "MyMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
QMessageBox::warning(nullptr, "提示", "该程序已打开", "关闭");
CloseHandle(hMutex);
return 0;
}
隐藏当前窗口
cpp
//隐藏当前窗口
HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, SW_MINIMIZE);