|
//代码名称: 单一运行实例
//类别: 系统控制
//关健字: 程序启动 单一程序实例
//作者: EasySL
//编译器: VC
//操作系统: windows
class COnceApprun
{
public:
// 启动程序运行 唯一标识
static bool Start( const char *szName );
// 停止程序运行 唯一标识
static void Stop();
protected:
static HANDLE m_hOnce;
};
/// 放在 CPP 文件里
HANDLE COnceApprun::m_hOnce = NULL;
bool COnceApprun::Start( const char *szName )
{
m_hOnce = CreateMutex( NULL, FALSE, szName );
if( m_hOnce==NULL || ERROR_ALREADY_EXISTS==::GetLastError() )
{
return false;
}
return true;
}
void COnceApprun::Stop()
{
ReleaseMutex( m_hOnce );
}
|
|