当前程序只能打开一次且隐藏

当前程序只能打开一次且隐藏

  • 当前程序只打开一次
  • 隐藏当前窗口

当前程序只打开一次

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

隐藏当前窗口

	//隐藏当前窗口
	HWND hwnd = GetConsoleWindow();
	ShowWindow(hwnd, SW_MINIMIZE);

你可能感兴趣的:(windows,c++)