⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singleinstance.cpp

📁 这是一本学习 window编程的很好的参考教材
💻 CPP
字号:
#include "stdafx.h"
#include "SingleInstance.h"

//***********************************************
CSingleInstance::CSingleInstance() : m_hMutex(NULL)
{
}

//***********************************************
CSingleInstance::~CSingleInstance()
{
	if(m_hMutex != NULL)
	{
		ReleaseMutex(m_hMutex);
		CloseHandle(m_hMutex);
	}
}

//***********************************************
bool CSingleInstance::Create(LPCTSTR szMutexName)
{
	_ASSERTE(szMutexName);
	_ASSERTE(lstrlen(szMutexName));

	bool bSuccess = false;

	try
	{
		// First get the handle to the mutex
		m_hMutex = CreateMutex(NULL, FALSE, szMutexName);
		if(m_hMutex != NULL)
		{
			// Test the state of the mutex
			// If the state is signaled, we successfully opened the mutex
			if(WaitForSingleObject(m_hMutex, 0) == WAIT_OBJECT_0)
				bSuccess = true;
		}
	}
	catch(...) {}

	return bSuccess;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -