这是一本学习 window编程的很好的参考教材

源代码在线查看: singleinstance.cpp

软件大小: 5535 K
上传用户: ok34090512
关键词: window 编程 教材
下载地址: 免注册下载 普通下载 VIP

相关代码

				#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;
				}
							

相关资源